implement cache
This commit is contained in:
parent
e118561a37
commit
6879291030
27
src/_mix
27
src/_mix
|
|
@ -393,10 +393,23 @@ _mix() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_mix_tasks() {
|
_mix_tasks() {
|
||||||
|
local ret=1
|
||||||
local -a mix_tasks=()
|
local -a mix_tasks=()
|
||||||
if (( $+commands[perl] )); then
|
if (( $+commands[perl] )); then
|
||||||
mix_tasks=(${(f)"$(mix help | perl -lne 'm{^mix (\S+)\s+#\s+(.+)} and print qq($1:$2)')"})
|
local cache_policy
|
||||||
else
|
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
|
||||||
|
zstyle ":completion:${curcontext}:" cache-policy ${cache_policy:-_mix_tasks_caching_policy}
|
||||||
|
|
||||||
|
if _cache_invalid mix_cached_tasks || ! _retrieve_cache mix_cached_tasks; then
|
||||||
|
mix_tasks=(${(f)"$(mix help | perl -lne 'm{^mix (\S+)\s+#\s+(.+)} and print qq($1:$2)')"})
|
||||||
|
if (( $? == 0 )); then
|
||||||
|
_store_cache mix_cached_tasks mix_tasks
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# fallback
|
||||||
|
if (( $#mix_tasks == 0 )); then
|
||||||
local -a builtin_tasks=(
|
local -a builtin_tasks=(
|
||||||
"app.config:Configures all registered apps"
|
"app.config:Configures all registered apps"
|
||||||
"app.start:Starts all registered apps"
|
"app.start:Starts all registered apps"
|
||||||
|
|
@ -467,7 +480,8 @@ _mix_tasks() {
|
||||||
mix_tasks=($builtin_tasks[@] $hex_tasks[@])
|
mix_tasks=($builtin_tasks[@] $hex_tasks[@])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_describe -t tasks 'task' mix_tasks
|
_describe -t tasks 'task' mix_tasks && ret=0
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
_mix_profile_tasks() {
|
_mix_profile_tasks() {
|
||||||
|
|
@ -811,6 +825,13 @@ _mix_escript_install_from() {
|
||||||
'where:repo:(git github hex)'
|
'where:repo:(git github hex)'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_mix_tasks_caching_policy() {
|
||||||
|
# rebuild if cache is more than an hour
|
||||||
|
local -a oldp
|
||||||
|
oldp=( "$1"(mh+1) )
|
||||||
|
(( $#oldp ))
|
||||||
|
}
|
||||||
|
|
||||||
_mix "$@"
|
_mix "$@"
|
||||||
|
|
||||||
# Local Variables:
|
# Local Variables:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue