diff options
Diffstat (limited to 'Completion/Zsh')
-rw-r--r-- | Completion/Zsh/Command/_compadd | 52 | ||||
-rw-r--r-- | Completion/Zsh/Command/_fc | 48 | ||||
-rw-r--r-- | Completion/Zsh/Command/_print | 17 | ||||
-rw-r--r-- | Completion/Zsh/Command/_setopt | 5 | ||||
-rw-r--r-- | Completion/Zsh/Command/_strftime | 12 | ||||
-rw-r--r-- | Completion/Zsh/Command/_zmodload | 2 | ||||
-rw-r--r-- | Completion/Zsh/Command/_zpty | 7 | ||||
-rw-r--r-- | Completion/Zsh/Context/_brace_parameter | 4 | ||||
-rw-r--r-- | Completion/Zsh/Function/_zargs | 64 | ||||
-rw-r--r-- | Completion/Zsh/Type/_command_names | 4 | ||||
-rw-r--r-- | Completion/Zsh/Type/_directory_stack | 6 | ||||
-rw-r--r-- | Completion/Zsh/Type/_file_descriptors | 70 | ||||
-rw-r--r-- | Completion/Zsh/Type/_globquals | 11 | ||||
-rw-r--r-- | Completion/Zsh/Type/_ps1234 | 170 |
14 files changed, 382 insertions, 90 deletions
diff --git a/Completion/Zsh/Command/_compadd b/Completion/Zsh/Command/_compadd new file mode 100644 index 000000000..03fed1854 --- /dev/null +++ b/Completion/Zsh/Command/_compadd @@ -0,0 +1,52 @@ +#compdef compadd + +local curcontext="$curcontext" state line ret=1 +typeset -A opt_args + +_arguments -C -s -S -A "-*" \ + '-P+[specify prefix]:prefix' \ + '-S+[specify suffix]:suffix' \ + '-p+[specify hidden prefix]:hidden prefix' \ + '-s+[specify hidden suffix]:hidden suffix' \ + '-i+[specify ignored prefix]:ignored prefix' \ + '-I+[specify ignored suffix]:ignored suffix' \ + '(-k)-a[matches are elements of specified arrays]' \ + '(-a)-k[matches are keys of specified associative arrays]' \ + '-d+[specify display strings]:array:_parameters -g "*array*"' \ + '-l[list display strings one per line, not in columns]' \ + '-o[order matches by display string not by match string]' \ + '(-1 -E)-J+[specify match group]:group' \ + '-V+[specify unsorted match group]:group' \ + '(-J -E)-1[remove only consecutive duplicates from group]' \ + '-2[preserve all duplicates]' \ + '(-x)-X[specify explanation]:explanation' \ + '(-X)-x[specify unconditional explanation]:explanation' \ + '-q[make suffix autoremovable]' \ + '-r+[specify character class for suffix autoremoval]:character class' \ + '-R+[specify function for suffix autoremoval]:function:_functions' \ + '-f[mark matches as being files]' \ + '-e[mark matches as being parameters]' \ + '-W[specify location for matches marked as files]' \ + '-F+[specify array of ignore patterns]:array:_parameters -g "*array*"' \ + '-Q[disable quoting of matchines]' \ + '*-M[specify matching specifications]' \ + '-n[hide matches in completion listing]' \ + '-U[disable internal matching of completion candidates]' \ + '-O+[populate array with matches instead of adding them]:array:_parameters -g "*array*"' \ + '-A+[populate array with expanded matches instead of adding them]:array:_parameters -g "*array*"' \ + '-D+[delete elements from array corresponding to non-matching candidates]:array:_parameters -g "*array*"' \ + '-C[add special match that expands to all other matches]' \ + '(-1 -J)-E+[add specified number of display only matches]:number' \ + '*:candidate:->candidates' && ret=0 + +if [[ -n $state ]]; then + if (( $+opt_args[-a] )); then + _parameters -g "*array*" && ret=0 + elif (( $+opt_args[-k] )); then + _parameters -g "*assoc*" && ret=0 + else + _message -e candidate candidates + fi +fi + +return ret diff --git a/Completion/Zsh/Command/_fc b/Completion/Zsh/Command/_fc index c2987211e..68456cc3d 100644 --- a/Completion/Zsh/Command/_fc +++ b/Completion/Zsh/Command/_fc @@ -1,7 +1,7 @@ #compdef fc history r local curcontext="$curcontext" state state_descr line ret=1 -local list events num cmd +local events num cmd sep typeset -A opt_args local fc_common fc_hist fc_r @@ -12,8 +12,10 @@ words=( "${(@)words[1,CURRENT-1]:#*=*}" "${(@)words[CURRENT,-1]}" ) fc_common=( -s -S - '(-A -R -W -I -p -P)-r[reverse order of the commands]' - '(-A -R -W -I -e -p -P)-n[suppress line numbers]' + '(-A -R -W -p -P)-I[include internal (new) events only]' + '(-A -R -W -p -P)-L[include local events only]' + '(-A -R -W -p -P)-r[reverse order of the events]' + '(-A -R -W -e -p -P)-n[suppress line numbers]' ) if [[ -n ${words[(r)-[pa](|[ap])]} ]]; then @@ -32,20 +34,20 @@ else fi fc_hist=( - '(-A -R -W -I -a -p -P 2)-m[treat argument as a pattern]' - '(-A -R -W -I -e -f -E -i -t -a -p -P)-d[print time-stamps]' - '(-A -R -W -I -e -d -E -i -t -a -p -P)-f[mm/dd/yyyy format time-stamps]' - '(-A -R -W -I -e -d -f -i -t -a -p -P)-E[dd.mm.yyyy format time-stamps]' - '(-A -R -W -I -e -d -f -E -t -a -p -P)-i[yyyy-mm-dd format time-stamps]' - '(-A -R -W -I -e -d -f -E -i -a -p -P)-t[print time-stamps in specified format]:date format' - '(-A -R -W -I -e -a -p -P)-D[print elapsed times]' + '(-A -R -W -a -p -P 2)-m[treat argument as a pattern]' + '(-A -R -W -e -f -E -i -t -a -p -P)-d[print time-stamps]' + '(-A -R -W -e -d -E -i -t -a -p -P)-f[mm/dd/yyyy format time-stamps]' + '(-A -R -W -e -d -f -i -t -a -p -P)-E[dd.mm.yyyy format time-stamps]' + '(-A -R -W -e -d -f -E -t -a -p -P)-i[yyyy-mm-dd format time-stamps]' + '(-A -R -W -e -d -f -E -i -a -p -P)-t[print time-stamps in specified format]:date format' + '(-A -R -W -e -a -p -P)-D[print elapsed times]' '(-A -R -W -I -e -d -f -i -l -m -n -r -D -E -t -P)-a[with -p, automatically pop history on function return]' '(-A -R -W -I -e -d -f -i -l -m -n -r -D -E -t -P)-p[push current history to stack]' '(- *)-P[pop history from stack]' ) -fc_r='(-A -R -W -I -e)-l[list resulting commands on stdout]' +fc_r='(-A -R -W -e)-l[list resulting commands on stdout]' case $service in history) @@ -56,31 +58,29 @@ case $service in ;; *) _arguments "$fc_common[@]" "$fc_hist[@]" "$fc_r" \ - '(-A -R -W -I -a -l -n -d -f -E -i -r -t -D -p -P)-e+[specify editor to invoke]:editor to invoke:_command_names -e' \ - '(-a -l -m -e -r -n -d -f -t -E -i -R -D -A -W -p -P *)-'{\ + '(-A -R -W -a -l -n -d -f -E -i -r -t -D -p -P)-e+[specify editor to invoke]:editor to invoke:_command_names -e' \ + '(-a -l -L -m -e -r -n -d -f -t -E -i -R -D -A -W -p -P *)-'{\ 'R[read history from file]',\ 'A[append history to file]',\ -'W[write history to file]',\ -'I[read/write new events only]'} && ret=0 +'W[write history to file]'} && ret=0 ;; esac if [[ -n $state ]]; then + zstyle -s ":completion:${curcontext}:" list-separator sep || sep=-- if [[ -z ${line:#*=*} ]] && compset -P '*='; then _message -e replacements 'replacement' elif [[ -prefix [0-9] ]]; then - events=( ${(ps.\0.)"$(printf '%s:%s\0' ${(kv)history})"} ) - zformat -a list " -- " "$events[@]" - _wanted -2V events expl "$state_descr" compadd -M "B:0=" -ld list - \ - "${events[@]%%:*}" + events=( ${(0)"$(printf "%-${#HISTNO}.${#HISTNO}s $sep %s\0" "${(kv)history[@]}")"} ) + _wanted -2V events expl "$state_descr" compadd -M "B:0=" -ld events - \ + "${events[@]%% *}" elif [[ -prefix - ]]; then - for num cmd in ${(kv)history}; do + for num cmd in "${(kv@)history}"; do (( num=num - HISTNO )) - events+=( $num:$cmd ) + events+=( "${(r.1+$#HISTNO.)num} $sep $cmd" ) done - zformat -a list " -- " "$events[@]" - _wanted -2V events expl "$state_descr" compadd -ld list - \ - "${events[@]%%:*}" + _wanted -2V events expl "$state_descr" compadd -ld events - \ + "${events[@]%% *}" else _wanted events expl "$state_descr" compadd -S '' - \ ${${history%%[=[:IFS:]]*}:#[0-9-]*} || _guard "[0-9]#" event diff --git a/Completion/Zsh/Command/_print b/Completion/Zsh/Command/_print index 405393355..1eba13e88 100644 --- a/Completion/Zsh/Command/_print +++ b/Completion/Zsh/Command/_print @@ -11,7 +11,7 @@ if [[ $service = print ]]; then pflag='(-s -u -z)-p[print arguments to input of coprocess]' if [[ -n ${words[1,CURRENT][(r)-*P*]} ]]; then - rest='*: :_ps1234' + rest='*: :->prompt' else rest='*: :_default' fi @@ -48,16 +48,17 @@ if [[ $state = printf ]]; then fi if [[ $state = printfformat ]]; then - if [[ ${(Q)PREFIX} = *%((-|)<->|[-#0 +*.])# ]]; then + if [[ ${(Q)PREFIX} = *%[0-9\$#\ +*.\'-]# ]]; then local -a specs specs=( '#:alternate form' - '0:zeropad to length n' + '0:zero pad to length' '-:left adjust result' ' :leave one space in front of positive number from signed conversion' '+:always place sign before a number from signed conversion' '*:field width in next argument' '.:precision' + "':thousand separators" 'c:print the first character of the argument' 's:print the argument as a string' {d,i}':signed decimal number or with leading " numeric value of following character' @@ -73,12 +74,16 @@ if [[ $state = printfformat ]]; then 'q:as %s but shell quote result' ) compset -P "*" - _describe -t print-format-specifier 'print format specifier' specs -S '' - _message -e print-format-specifier 'number' + _describe -t print-format-specifiers 'print format specifier' specs -S '' + _message -e print-format-specifiers 'number' else - _describe -t print-format-specifier 'print format specifier' '(%)' -S '' + _wanted print-format-specifiers expl 'print format specifier' compadd -S '' % fi ret=0 +elif [[ $state = prompt ]]; then + _default && ret=0 + # complete prompt specifiers without interfering too much with default completion + (( $#compstate[unambiguous] <= $#PREFIX || ! $#PREFIX )) && _ps1234 && ret=0 fi return ret diff --git a/Completion/Zsh/Command/_setopt b/Completion/Zsh/Command/_setopt index fb38d1da6..86c0965f9 100644 --- a/Completion/Zsh/Command/_setopt +++ b/Completion/Zsh/Command/_setopt @@ -2,8 +2,9 @@ local expl ret=1 local -a onopts offopts -onopts=( ${(k)_comp_caller_options[(R)on]} ) -offopts=( ${(k)_comp_caller_options[(R)off]} ) +onopts=( ${(k)_comp_caller_options[(R)on]} printexitvalue ) +offopts=( ${(k)_comp_caller_options[(R)off]} printexitvalue ) +typeset -U onopts offopts case $service in setopt) onopts=(no$onopts) ;; unsetopt) offopts=(no$offopts) ;; diff --git a/Completion/Zsh/Command/_strftime b/Completion/Zsh/Command/_strftime new file mode 100644 index 000000000..0be7b078d --- /dev/null +++ b/Completion/Zsh/Command/_strftime @@ -0,0 +1,12 @@ +#compdef strftime + +local ret=1 expl + +_arguments -S -A '-*' -s \ + '-q[run quietly]' \ + '-r[reverse lookup using strptime]' \ + '-s+[assign result to parameter]:param:_parameters' \ + '1:format: _date_formats' \ + '2:epoch time (or date string with -r)' && ret=0 + +return ret diff --git a/Completion/Zsh/Command/_zmodload b/Completion/Zsh/Command/_zmodload index e144b981e..57fb990e9 100644 --- a/Completion/Zsh/Command/_zmodload +++ b/Completion/Zsh/Command/_zmodload @@ -68,7 +68,7 @@ else _requested loadedmodules expl 'loaded modules' \ compadd -k 'modules[(R)loaded]' && ret=0 _requested files expl 'module file' \ - _files -W module_path -/g '*.(dll|s[ol]|bundle)(:r)' && ret=0 + _files -W module_path -g '*.(dll|s[ol]|bundle)(:r)' && ret=0 _requested aliases expl 'module alias' \ compadd "$suf[@]" -k 'modules[(R)alias*]' && ret=0 done diff --git a/Completion/Zsh/Command/_zpty b/Completion/Zsh/Command/_zpty index ef4ac4bb1..99251aa0a 100644 --- a/Completion/Zsh/Command/_zpty +++ b/Completion/Zsh/Command/_zpty @@ -1,6 +1,6 @@ #compdef zpty -local state line list names expl curcontext="$curcontext" +local state line list names expl sep curcontext="$curcontext" typeset -A opt_args _arguments -C -s -S \ @@ -50,8 +50,9 @@ if [[ $state = name ]]; then fi list=( ${${(f)"$(zpty)"}#*\) } ) names=( ${list%%:*} ) - if zstyle -T ":completion:${curcontext}" verbose; then - zformat -a list ' --' ${${(f)"$(zpty)"}#*\) } + if zstyle -T ":completion:${curcontext}:" verbose; then + zstyle -s ":completion:${curcontext}:" list-separator sep || sep=-- + zformat -a list " $sep" ${${(f)"$(zpty)"}#*\) } _wanted names expl 'zpty command name' compadd -d list -a names else _wanted names expl 'zpty command name' compadd -a names diff --git a/Completion/Zsh/Context/_brace_parameter b/Completion/Zsh/Context/_brace_parameter index 3955cb7a4..9eb3465ae 100644 --- a/Completion/Zsh/Context/_brace_parameter +++ b/Completion/Zsh/Context/_brace_parameter @@ -152,7 +152,7 @@ if [[ $PREFIX = *'${('[^\)]# ]]; then "F:join arrays with newlines" "g:process echo array sequences (needs options)" "i:sort case-insensitively" - "k:subsitute keys of associative arrays" + "k:substitute keys of associative arrays" "L:lower case all letters" "n:sort decimal integers numerically" "o:sort in ascending order (lexically if no other sort option)" @@ -192,7 +192,7 @@ elif compset -P '*:([\|\*\^]|\^\^)'; then elif compset -P '*:'; then flags=( '-:substitute alternate value if parameter is null' - '+:susbtitute alternate value if parameter is non-null' + '+:substitute alternate value if parameter is non-null' '=:substitute and assign alternate value if parameter is null' '\:=:unconditionally assign value to parameter' '?:print error if parameter is set and non-null' diff --git a/Completion/Zsh/Function/_zargs b/Completion/Zsh/Function/_zargs index f1f87b447..c24b276f2 100644 --- a/Completion/Zsh/Function/_zargs +++ b/Completion/Zsh/Function/_zargs @@ -1,24 +1,48 @@ #compdef zargs -value-,-default-,-command- -# atom smasher - jan 2011 -local arguments +local arguments eofstr pos=$((CURRENT)) numeofs=0 ret=1 cmdpos=1 -arguments=( $arguments[@] - '(--eof -e)'{--eof=,-e+}'[change the end-of-input-args string from "--" to eof-str]' - '(--exit, -x)'{--exit,-x}'[exit if the size (see --max-chars) is exceeded]' - '--help[print summary and exit]' - '(--interactive, -p)'{--interactive,-p}'[prompt before executing each command line]' - '(--max-args, -n)'{--max-args=,-n+}'[use at most max-args arguments per command line]' - '(--max-chars, -s)'{--max-chars=,-s+}'[use at most max-chars characters per command line]' - '(--max-lines, -l)'{--max-lines=,-l+}'[use at most max-lines of the input-args per command line]' - '(--max-procs, -P)'{--max-procs=,-P+}'[run up to max-procs command lines in the background at once]' - '(--no-run-if-empty, -r)'{--no-run-if-empty,-r}'[do nothing if there are no input arguments before the eof-str]' - '(--null, -0)'{--null,-0}'[split each input-arg at null bytes, for xargs compatibility]' - '(--replace, -i)'{--replace=,-i}'[substitute replace-str in the initial-args by each initial-arg]' - '(--verbose, -t)'{--verbose,-t}'[print each command line to stderr before executing it]' - '--version[print the version number of zargs and exit]' -) +#this doesn't handle '--' on the command line, only -- +#it also by extension doesn't handle eofstr being the empty string +#it also also doesn't handle eofstr being -e or --eof, and everything will +# probably also be confused if the command at the end takes a -e, --eof= or -- +eofstr=${${${${words[(r)(--eof=*|-e*)]}#--eof=}#-e}:---} +while { + pos=$(( words[(b:pos-1:I)$eofstr] )) + (( numeofs == 0 )) && (( cmdpos = pos )) + (( pos )) && (( numeofs++ )) + (( pos )) +} {} +case $numeofs in + 0) + #zargs arguments + arguments=( + '(--eof -e)'{--eof=,-e+}'[change the end-of-input-args string from "--" to eof-str]' + '(--exit, -x)'{--exit,-x}'[exit if the size (see --max-chars) is exceeded]' + '--help[print summary and exit]' + '(--interactive, -p)'{--interactive,-p}'[prompt before executing each command line]' + '(--max-args, -n)'{--max-args=,-n+}'[use at most max-args arguments per command line]' + '(--max-chars, -s)'{--max-chars=,-s+}'[use at most max-chars characters per command line]' + '(--max-lines, -l)'{--max-lines=,-l+}'[use at most max-lines of the input-args per command line]' + '(--max-procs, -P)'{--max-procs=,-P+}'[run up to max-procs command lines in the background at once]' + '(--no-run-if-empty, -r)'{--no-run-if-empty,-r}'[do nothing if there are no input arguments before the eof-str]' + '(--null, -0)'{--null,-0}'[split each input-arg at null bytes, for xargs compatibility]' + '(--replace, -i)'{--replace=,-i}'[substitute replace-str in the initial-args by each initial-arg]' + '(--verbose, -t)'{--verbose,-t}'[print each command line to stderr before executing it]' + '--version[print the version number of zargs and exit]' + ) + _arguments -S -s $arguments[@] && ret=0 + ;; + 1) + #argument list for command + _files && ret=0 + ;; + *) + #command and command arguments + shift cmdpos words + (( CURRENT -= cmdpos )) + _normal + ;; +esac -_arguments -S -s $arguments[@] - -_command_names -e +return ret diff --git a/Completion/Zsh/Type/_command_names b/Completion/Zsh/Type/_command_names index d9fc62dfe..940f341cb 100644 --- a/Completion/Zsh/Type/_command_names +++ b/Completion/Zsh/Type/_command_names @@ -17,9 +17,7 @@ defs=( ) [[ -n "$path[(r).]" || $PREFIX = */* ]] && - defs=( "$defs[@]" - 'executables:executable file or directory:_path_files -/g \*\(-\*\)' - ) + defs+=( 'executables:executable file:_files -g \*\(-\*\)' ) if [[ "$1" = -e ]]; then shift diff --git a/Completion/Zsh/Type/_directory_stack b/Completion/Zsh/Type/_directory_stack index 8a4cf675a..e84115a64 100644 --- a/Completion/Zsh/Type/_directory_stack +++ b/Completion/Zsh/Type/_directory_stack @@ -12,14 +12,14 @@ local expl list lines revlines disp sep ### we decided against this, for now... #! zstyle -T ":completion:${curcontext}:directory-stack" prefix-needed || -zstyle -s ":completion:${curcontext}:directory-stack" list-separator sep || sep=-- - [[ $PREFIX = [-+]* ]] || return 1 +zstyle -s ":completion:${curcontext}:directory-stack" list-separator sep || sep=-- + if zstyle -T ":completion:${curcontext}:directory-stack" verbose; then # get the list of directories with their canonical number # and turn the lines into an array, removing the current directory - lines=("${dirstack[@]}") + lines=("${(D)dirstack[@]}") if [[ ( $PREFIX[1] = - && ! -o pushdminus ) || ( $PREFIX[1] = + && -o pushdminus ) ]]; then diff --git a/Completion/Zsh/Type/_file_descriptors b/Completion/Zsh/Type/_file_descriptors index 3e251b733..3e9f4968b 100644 --- a/Completion/Zsh/Type/_file_descriptors +++ b/Completion/Zsh/Type/_file_descriptors @@ -1,31 +1,59 @@ #autoload -local i fds expl list link sep +local i fds expl disp link sep +local -a list proc -fds=( /dev/fd/<0-9>(N:t) ) +fds=( /dev/fd/<3->(N:t) ) +fds=( ${(n)fds} ) -if zstyle -T ":completion:${curcontext}:" verbose && [[ -h /proc/$$/fd/$fds[1] ]]; then - zstyle -s ":completion:${curcontext}:" list-separator sep || sep=-- +if zstyle -T ":completion:${curcontext}:file-descriptors" verbose; then + zstyle -s ":completion:${curcontext}:file-descriptors" list-separator sep || sep=-- - if zmodload -F zsh/stat b:zstat; then - for i in "${fds[@]}"; do - zstat +link -A link /proc/$$/fd/$i - list+=( "$i $sep ${link[1]}" ) - done - elif (( $+commands[readlink] )); then - for i in "${fds[@]}"; do - list+=( "$i $sep $(readlink /proc/$$/fd/$i)" ) - done - else - for i in "${fds[@]}"; do - list+=( "$i $sep $(ls -l /proc/$$/fd/$i|sed 's/.*-> //' )" ) - done + if [[ $OSTYPE = freebsd* ]]; then + fds=( ${(f)"$(procstat -f $$|awk -v OFS=: '$3>2 && $3~/[0-9]/ {print $3,$10}')"} ) + zformat -a list " $sep " $fds + fds=( ${fds%%:*} ) + elif + proc=( /proc/$$/(fd|path)/<->(@N[-1]:h) ) + [[ -n $proc ]] + then + if zmodload -F zsh/stat b:zstat; then + for i in "${fds[@]}"; do + if zstat +link -A link $proc/$i; then + list+=( "${(r.$#fds[-1].)i} $sep ${(D)link[1]}" ) + else + fds[(i)$i]=() + fi + done + elif (( $+commands[readlink] )); then + for i in "${fds[@]}"; do + if link=$(readlink $proc/$i); then + list+=( "${(r.$#fds[-1].)i} $sep ${(D)link}" ) + else + fds[(i)$i]=() + fi + done + else + for i in "${fds[@]}"; do + if link=$(ls -l $proc/$i); then + list+=( "${(r.$#fds[-1].)i} $sep ${(D)link#* -> }" ) + else + fds[(i)$i]=() + fi + done + fi 2>/dev/null fi - if (( $list[(I)* $sep ?*] )); then - _wanted file-descriptors expl 'file descriptor' compadd "$@" -d list -a - fds - return + if (( list[(I)* $sep ?*] )); then + list=( + "${(r.$#fds[-1].):-0} $sep standard input" + "${(r.$#fds[-1].):-1} $sep standard output" + "${(r.$#fds[-1].):-2} $sep standard error" $list + ) + disp=( -d list ) fi fi +fds=( 0 1 2 $fds ) -_wanted file-descriptors expl 'file descriptor' compadd -a "$@" - fds +_description -V file-descriptors expl 'file descriptor' +compadd $disp "${@/-J/-V}" "$expl[@]" -a fds diff --git a/Completion/Zsh/Type/_globquals b/Completion/Zsh/Type/_globquals index 042b27400..5cdb8f7c4 100644 --- a/Completion/Zsh/Type/_globquals +++ b/Completion/Zsh/Type/_globquals @@ -1,7 +1,7 @@ #autoload local state=qual expl char delim timespec -local -a alts +local -a alts tdisp sdisp local -A specmap while [[ -n $PREFIX ]]; do @@ -117,14 +117,15 @@ while [[ -n $PREFIX ]]; do alts=() timespec=$PREFIX[1] if ! compset -P '[Mwhmsd]' && [[ -z $PREFIX ]]; then - alts+=("time-specifiers:time specifier:\ -((M\:months w\:weeks h\:hours m:\minutes s\:seconds d\:days))") + tdisp=( seconds minutes hours days weeks Months ) + alts+=( "time-specifiers:time specifier:compadd -E 0 -d tdisp -S '' - s m h d w M" ) fi if ! compset -P '[-+]' && [[ -z $PREFIX ]]; then - alts+=("senses:sense:((-\:less\ than +\:more\ than))") + sdisp=( before exactly since ) + alts+=("senses:sense:compadd -E 0 -d sdisp -S '' - + '' -") fi specmap=( M months w weeks h hours m minutes s seconds '(|+|-|d)' days) - alts+=('digits:digit ('${${specmap[(K)$timespec]}:-invalid time specifier}'):' ) + alts+=('digits:digit ('${${specmap[(K)$timespec]}:-invalid time specifier}'):_dates -f ${${timespec/[-+]/d}:-d} -S ""' ) _alternative $alts return fi diff --git a/Completion/Zsh/Type/_ps1234 b/Completion/Zsh/Type/_ps1234 new file mode 100644 index 000000000..8edf0d0cb --- /dev/null +++ b/Completion/Zsh/Type/_ps1234 @@ -0,0 +1,170 @@ +#compdef -value-,PROMPT,-default- -value-,PROMPT2,-default- -value-,PROMPT3,-default- -value-,PROMPT4,-default- -value-,RPROMPT,-default- -value-,RPROMPT2,-default- -value-,PS1,-default- -value-,PS2,-default- -value-,PS3,-default- -value-,PS4,-default- -value-,RPS1,-default- -value-,RPS2,-default- -value-,SPROMPT,-default- + +local -a specs +local expl grp cols bs suf pre changed=1 ret=1 +local -A ansi + +[[ -z $compstate[quote] ]] && bs='\' + +# first strip off any complete prompt specifications leaving only the +# current, incomplete, one +while (( changed )); do + changed=0 + compset -P '%[DFK](\\|){[^}]#}' && changed=1 # formats with arg: %x{...} + compset -P '%[0-9-\\]#[^DFK(0-9-<>\\\[]' && changed=1 # normal formats + compset -P '%[0-9-\\]#(<[^<]#<|>[^>]#>|\[[^\]]#\])' && changed=1 # truncations + compset -P '%[0-9-\\]#(\\|)\([0-9-]#[^0-9]?|[^%]' && changed=1 # start of ternary + compset -P '[^%]##' && changed=1 # sundry other characters + # %D/%F/%K without a following { ... } + [[ $PREFIX = %(-|)<->#[DFK](\\[^{]|[^{\\])* ]] && + compset -P '%[0-9\\-]#[DFK]' && changed=1 +done +[[ $PREFIX = %(-|)<->[FK](#e) ]] && compset -P '*' # F/K with number + +if compset -P '%[FK]'; then + # this should use -P but that somehow causes single quotes to be stripped + compset -P '(\\|){' || pre=( -p '{' ) + compset -S '(\\|)}*' || suf=( -S "$bs}" ) + ansi=( + black 30 + red 31 + green 32 + yellow 33 + blue 34 + magenta 35 + cyan 36 + white 37 + default 39 + ) + + _description -V ansi-colors expl 'ansi color' + grp="$expl[expl[(i)-V]+1]" + _comp_colors+=( ${(ps.\0.)"$(printf "($grp)=%s=%s\0" ${(kv)ansi})"} ) + compadd "$expl[@]" $suf $pre -k ansi && ret=0 + if (( $#suf )) && compset -P "(<->|%v)"; then + _wanted ansi-colors expl 'closing brace' compadd -S '' \} && ret=0 + elif (( $+terminfo[colors] )); then + (( cols = $terminfo[colors] - 1 )) + (( cols = cols > 255 ? 255 : cols )) + _description -V terminal-colors expl 'terminal color' + grp="$expl[expl[(i)-V]+1]" + compadd "$expl[@]" $suf $pre {0..$cols} + for c in {0..$cols}; do + _comp_colors+=( "($grp)=${c}=${${$(print -P "%F{$c}")#?\[}%m}" ) + done + else + _message -e terminal-colors "number" + fi +fi + +if compset -P '%[0-9-\\]#(\\|)\([0-9-]#[^0-9]'; then + compset -S '*' + _delimiters && ret=0 +elif compset -P '%[0-9-\\]#[<>\]]'; then + _message -e replacements 'replacement string' +elif compset -P '%[0-9-\\]#(\\|)\([0-9-]#'; then + compset -S '[.:+/-%]*' || suf=( -S . ) + compset -S '*' + specs=( + '!:running with privileges' + '#:effective uid' + '?:exit status' + '_:at least n shell constructs started' + 'C:at least n path elements' + '/:at least n path elements' + '.:at least n path elements' + 'c:at least n path elements' + '~:at least n path elements' + 'D:month' + 'd:day of month' + 'g:effective gid' + 'j:number of jobs' + 'L:SHLVL' + 'l:number of characters already printed' + 'S:SECONDS parameter at least n' + 'T:current hour' + 't:current minute' + 'v:psvar has at least n elements' + 'V:element n of psvar is set and non-empty' + 'w:day of week (Sunday = 0)' + ) + [[ $IPREFIX != *- ]] && _describe -t ternary-prompt-expressions \ + 'ternary prompt format test character' specs $suf && ret=0 + _message -e numbers number +elif compset -P '%D(\\|){'; then + compset -S '(\\|)}*' + _date_formats zsh && ret=0 +elif [[ -prefix '%' ]] || + ! zstyle -t ":completion:${curcontext}:prompt-format-specifiers" prefix-needed +then + specs=( + 'm:hostname up to first .' + '_:status of parser' + '^:reversed status of parser' + 'd:current working directory' + '/:current working directory' + '~:current working directory, with ~ replacement' + 'N:name of current script or shell function' + 'x:name of file containing code being executed' + 'c:deprecated' + '.:deprecated' + 'C:deprecated' + 'F:start using fg color' + 'K:start using bg color' + 'G:counts as extra character inside %{...%}' + '(:ternary expression %(x.true-string.false-string)' + ) + compset -P '%' || pre=( -p '%' ) + if ! compset -P '(-|)<->'; then + if [[ $service == -value-,SPROMPT,* ]]; then + specs+=( + 'r:suggested correction' + 'R:corrected string' + ) + fi + specs+=( + '%:A %' + '):A )' + 'l:current line (tty) with /dev/tty stripped' + 'M:full hostname' + 'n:username' + 'y:current line (tty)' + '#:a # when root, % otherwise' + '?:return status of last command' + 'h:current history event number' + '!:current history event number' + 'i:current line number' + 'I:current source line number' + 'j:number of jobs' + 'L:$SHLVL' + 'D:date in yy-mm-dd format' + 'T:current time of day, 24-hour format' + 't:current time of day, 12-hour am/pm format' + '@:current time of day, 12-hour am/pm format' + '*:current time of day, 24-hour format with seconds' + 'w:the date in day-dd format' + 'W:the date in mm/dd/yy format' + 'D{:format string like strftime' + 'B:start bold' + 'b:stop bold' + 'E:clear to end of line' + 'U:start underline' + 'u:stop underline' + 'S:start standout' + 's:stop standout' + 'f:reset fg color' + 'k:reset bg color' + '{:start literal escape sequence' + '}:stop literal escape sequence' + 'v:value from $psvar array' + '<:truncation from left %len<string<' + '>:truncation from right %len>string>' + '[:truncation from who knows where' + ) + fi + _describe -t prompt-format-specifiers 'prompt format specifier' \ + specs -S '' $pre && ret=0 + (( ! $#pre )) && _message -e prompt-format-specifiers number +fi + +return ret |