From 6879291030828322cef1f0151e63b87cc19e1d2c Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Wed, 25 Mar 2026 15:10:11 +0900 Subject: [PATCH] implement cache --- src/_mix | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/_mix b/src/_mix index 9ee8904..aa5a4f5 100644 --- a/src/_mix +++ b/src/_mix @@ -393,10 +393,23 @@ _mix() { } _mix_tasks() { + local ret=1 local -a mix_tasks=() if (( $+commands[perl] )); then - mix_tasks=(${(f)"$(mix help | perl -lne 'm{^mix (\S+)\s+#\s+(.+)} and print qq($1:$2)')"}) - else + 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)')"}) + 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: