Mercurial > hg > mercurial-crew-with-dirclash
comparison contrib/zsh_completion @ 3600:932dadd2e614
zsh: add optional remote directory cache
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Tue, 31 Oct 2006 15:44:16 -0800 |
parents | 27121416f9a8 |
children | cedf056bb723 |
comparison
equal
deleted
inserted
replaced
3599:e00920b4f1cb | 3600:932dadd2e614 |
---|---|
74 then | 74 then |
75 cmd=$_hg_alias_list[$cmd] | 75 cmd=$_hg_alias_list[$cmd] |
76 fi | 76 fi |
77 fi | 77 fi |
78 | 78 |
79 curcontext="${curcontext%:*:*}:hg-${cmd}:" | |
80 | |
81 zstyle -s ":completion:$curcontext:" cache-policy update_policy | |
82 | |
83 if [[ -z "$update_policy" ]] | |
84 then | |
85 zstyle ":completion:$curcontext:" cache-policy _hg_cache_policy | |
86 fi | |
87 | |
79 if (( $+functions[_hg_cmd_${cmd}] )) | 88 if (( $+functions[_hg_cmd_${cmd}] )) |
80 then | 89 then |
81 curcontext="${curcontext%:*:*}:hg-${cmd}:" | |
82 _hg_cmd_${cmd} | 90 _hg_cmd_${cmd} |
83 else | 91 else |
84 # complete unknown commands normally | 92 # complete unknown commands normally |
85 _arguments -s -w : $_hg_global_opts \ | 93 _arguments -s -w : $_hg_global_opts \ |
86 '*:files:_files -W $(_hg_cmd root)' | 94 '*:files:_files -W $(_hg_cmd root)' |
87 fi | 95 fi |
96 } | |
97 | |
98 _hg_cache_policy() { | |
99 typeset -a old | |
100 | |
101 # cache for a minute | |
102 old=( "$1"(mm+10) ) | |
103 (( $#old )) && return 0 | |
104 | |
105 return 1 | |
88 } | 106 } |
89 | 107 |
90 _hg_get_commands() { | 108 _hg_get_commands() { |
91 typeset -ga _hg_cmd_list | 109 typeset -ga _hg_cmd_list |
92 typeset -gA _hg_alias_list | 110 typeset -gA _hg_alias_list |
170 then | 188 then |
171 local host=${PREFIX%%/*} | 189 local host=${PREFIX%%/*} |
172 typeset -a remdirs | 190 typeset -a remdirs |
173 compset -p $(( $#host + 1 )) | 191 compset -p $(( $#host + 1 )) |
174 local rempath=${(M)PREFIX##*/} | 192 local rempath=${(M)PREFIX##*/} |
193 local cacheid="hg_${host}_${rempath//\//_}" | |
175 compset -P '*/' | 194 compset -P '*/' |
176 remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}" 2> /dev/null)"}##*/}%/}) | 195 if _cache_invalid "$cacheid" || ! _retrieve_cache "$cacheid" |
196 then | |
197 remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}" 2> /dev/null)"}##*/}%/}) | |
198 _store_cache "$cacheid" remdirs | |
199 fi | |
177 _describe -t directories 'remote directory' remdirs -S/ | 200 _describe -t directories 'remote directory' remdirs -S/ |
178 else | 201 else |
179 _message 'remote directory' | 202 _message 'remote directory' |
180 fi | 203 fi |
181 else | 204 else |