implement cache
This commit is contained in:
parent
e118561a37
commit
6879291030
25
src/_mix
25
src/_mix
|
|
@ -393,10 +393,23 @@ _mix() {
|
|||
}
|
||||
|
||||
_mix_tasks() {
|
||||
local ret=1
|
||||
local -a mix_tasks=()
|
||||
if (( $+commands[perl] )); then
|
||||
local cache_policy
|
||||
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)')"})
|
||||
else
|
||||
if (( $? == 0 )); then
|
||||
_store_cache mix_cached_tasks mix_tasks
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# fallback
|
||||
if (( $#mix_tasks == 0 )); then
|
||||
local -a builtin_tasks=(
|
||||
"app.config:Configures all registered apps"
|
||||
"app.start:Starts all registered apps"
|
||||
|
|
@ -467,7 +480,8 @@ _mix_tasks() {
|
|||
mix_tasks=($builtin_tasks[@] $hex_tasks[@])
|
||||
fi
|
||||
|
||||
_describe -t tasks 'task' mix_tasks
|
||||
_describe -t tasks 'task' mix_tasks && ret=0
|
||||
return ret
|
||||
}
|
||||
|
||||
_mix_profile_tasks() {
|
||||
|
|
@ -811,6 +825,13 @@ _mix_escript_install_from() {
|
|||
'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 "$@"
|
||||
|
||||
# Local Variables:
|
||||
|
|
|
|||
Loading…
Reference in New Issue