Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: completion examples
- X-seq: zsh-workers 6657
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: completion examples
- Date: Wed, 16 Jun 1999 10:24:48 +0200 (MET DST)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Here is a bit of cleanup for the completion functions. Most of the
patch just replaces uses of `compgen -[sk]' with calls to compadd
(which is almost always possible and often faster).
It also tries to improve `_make' and it adds `_gdb' (so remember to
use `-p0') -- which isn't perfect yet.
I've also added two configuration keys `ps_args' and `ps_listargs'
that are used by `_{wait,kill,gdb}' and give to `ps'. This is not in
the manual yet because I didn't know where to put it (we would need
a section for misc. configuaration keys, I think).
Bye
Sven
diff -u -r oc/Base/_subscript Completion/Base/_subscript
--- oc/Base/_subscript Wed Jun 16 08:22:10 1999
+++ Completion/Base/_subscript Wed Jun 16 08:42:44 1999
@@ -1,7 +1,7 @@
#compdef -subscript-
if [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
- compgen -S ']' -k "( ${(kP)${compstate[parameter]}} )"
+ compadd -S ']' - "${(@kP)${compstate[parameter]}}"
else
_compalso -math-
fi
diff -u -r oc/Builtins/_autoload Completion/Builtins/_autoload
--- oc/Builtins/_autoload Wed Jun 16 08:22:12 1999
+++ Completion/Builtins/_autoload Wed Jun 16 08:42:44 1999
@@ -1,3 +1,3 @@
#compdef autoload
-compgen -s '${^fpath}/*(N:t)'
+compadd - ${^fpath}/*(N:t)
diff -u -r oc/Builtins/_bindkey Completion/Builtins/_bindkey
--- oc/Builtins/_bindkey Wed Jun 16 08:22:12 1999
+++ Completion/Builtins/_bindkey Wed Jun 16 08:42:44 1999
@@ -8,7 +8,7 @@
# Where appropriate, will complete keymaps instead of widgets.
if [[ "$words[2]" = -*[DAN]* || "$words[CURRENT-1]" = -*M ]]; then
- compgen -s '$(bindkey -l)'
+ compadd - $(bindkey -l)
else
compgen -b -M 'r:|-=* r:|=*'
fi
diff -u -r oc/Builtins/_echotc Completion/Builtins/_echotc
--- oc/Builtins/_echotc Wed Jun 16 08:22:12 1999
+++ Completion/Builtins/_echotc Wed Jun 16 08:42:45 1999
@@ -1,3 +1,3 @@
#compdef echotc
-compgen -k '(al dc dl do le up al bl cd ce cl cr dc dl do ho is le ma nd nl se so up)'
+compadd al dc dl do le up al bl cd ce cl cr dc dl do ho is le ma nd nl se so up
diff -u -r oc/Builtins/_kill Completion/Builtins/_kill
--- oc/Builtins/_kill Wed Jun 16 08:22:13 1999
+++ Completion/Builtins/_kill Wed Jun 16 09:07:20 1999
@@ -3,13 +3,13 @@
local list
if compset -P 1 -; then
- compgen -k "($signals[1,-3])"
+ compadd $signals[1,-3]
else
local ret=1
compgen -P '%' -j && ret=0
- list=("$(ps 2>/dev/null)")
- compgen -y '$list' -s '${${${(f)"$(ps 2>/dev/null)"}[2,-1]## #}%% *}' &&
+ list=("${(@Mr:COLUMNS-1:)${(f)$(ps ${compconfig[ps_listargs]:-$compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ ]#${PREFIX}[0-9]#${SUFFIX}[ ]*}")
+ compgen -y '$list' -s '${${${(f)"$(ps $compconfig[ps_args] 2>/dev/null)"}[2,-1]## #}%% *}' &&
ret=0
return ret
diff -u -r oc/Builtins/_limits Completion/Builtins/_limits
--- oc/Builtins/_limits Wed Jun 16 08:22:13 1999
+++ Completion/Builtins/_limits Wed Jun 16 08:42:45 1999
@@ -1,3 +1,3 @@
#compdef limit unlimit
-compgen -s '${${(f)"$(limit)"}%% *}'
+compadd ${${(f)"$(limit)"}%% *}
diff -u -r oc/Builtins/_wait Completion/Builtins/_wait
--- oc/Builtins/_wait Wed Jun 16 08:22:13 1999
+++ Completion/Builtins/_wait Wed Jun 16 09:07:27 1999
@@ -1,9 +1,20 @@
#compdef wait
+# This uses two configuration keys:
+#
+# ps_args
+# This can be set to options of the ps(1) command that should be
+# used when invoking it to get the pids to complete.
+#
+# ps_listargs
+# This defaults to the value of the `ps_args' key and defines
+# options for the ps command that are to be used when creating
+# the list to display during completion.
+
local list ret=1
compgen -P '%' -j && ret=0
-list=("$(ps 2>/dev/null)")
-compgen -y '$list' -s '${${${(f)"$(ps 2>/dev/null)"}[2,-1]## #}%% *}' && ret=0
+list=("${(@Mr:COLUMNS-1:)${(f)$(ps ${compconfig[ps_listargs]:-$compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ ]#${PREFIX}[0-9]#${SUFFIX}[ ]*}")
+compgen -y '$list' -s '${${${(f)"$(ps $compconfig[ps_args] 2>/dev/null)"}[2,-1]## #}%% *}' && ret=0
return ret
diff -u -r oc/Builtins/_zmodload Completion/Builtins/_zmodload
--- oc/Builtins/_zmodload Wed Jun 16 08:22:13 1999
+++ Completion/Builtins/_zmodload Wed Jun 16 08:42:45 1999
@@ -5,7 +5,7 @@
if [[ "$fl" = -*(a*u|u*a)* || "$fl" = -*a* && CURRENT -ge 4 ]]; then
compgen -B
elif [[ "$fl" = -*u* ]]; then
- compgen -s '$(zmodload)'
+ compadd - $(zmodload)
else
- compgen -s '${^module_path}/*(N:t:r)'
+ compadd - ${^module_path}/*(N:t:r)
fi
diff -u -r oc/User/_dd Completion/User/_dd
--- oc/User/_dd Wed Jun 16 08:22:17 1999
+++ Completion/User/_dd Wed Jun 16 08:42:45 1999
@@ -4,10 +4,9 @@
# If there's a comma present, ignore up to the last one. The
# test alone will have that effect.
compset -p '*,'
- compgen -S, -q \
- -k '(ascii ebcdic ibm block unblock lcase ucase swab noerror sync)'
+ compadd -qS, -q ascii ebcdic ibm block unblock lcase ucase swab noerror sync
elif compset -P 1 '[io]f\='; then
_files
else
- compgen -S '=' -k '(if of ibs obs bs cbs skip files seek count conv)'
+ compadd -S '=' if of ibs obs bs cbs skip files seek count conv
fi
diff -u -r oc/User/_find Completion/User/_find
--- oc/User/_find Wed Jun 16 08:22:17 1999
+++ Completion/User/_find Wed Jun 16 08:42:45 1999
@@ -5,10 +5,10 @@
if compset -N '-(ok|exec)' '\;'; then
_normal
elif compset -P 1 -; then
- compgen -s 'daystart {max,min,}depth follow noleaf version xdev \
+ compadd daystart {max,min,}depth follow noleaf version xdev \
{a,c,}newer {a,c,m}{min,time} empty false {fs,x,}type gid inum links \
{i,}{l,}name {no,}{user,group} path perm regex size true uid used \
- exec {f,}print{f,0,} ok prune ls'
+ exec {f,}print{f,0,} ok prune ls
elif [[ CURRENT -eq 2 ]]; then
local ret=1
@@ -19,7 +19,7 @@
elif [[ "$prev" = -((a|c|)newer|fprint(|0|f)) ]]; then
_files
elif [[ "$prev" = -fstype ]]; then
- compgen -k '(ufs 4.2 4.3 nfs tmp mfs S51K S52K)'
+ compadd ufs 4.2 4.3 nfs tmp mfs S51K S52K
elif [[ "$prev" = -group ]]; then
compgen -k groups
elif [[ "$prev" = -user ]]; then
diff -u -r oc/User/_gdb Completion/User/_gdb
--- oc/User/_gdb Wed Jun 16 09:29:56 1999
+++ Completion/User/_gdb Wed Jun 16 09:29:29 1999
@@ -0,0 +1,49 @@
+#compdef gdb
+
+# This uses the configuration keys `ps_args' and `ps_listargs'
+# described in the `_wait' function.
+
+local cur="$words[CURRENT]" prev w list ret=1
+
+_long_options -t '*=(CORE|SYM)FILE' '_files' \
+ '*=EXECFILE' '_files *(*)' \
+ '*=TTY' 'compadd /dev/tty*' && return 0
+
+if compset -P '-(cd|directory)='; then
+ _files -/
+elif compset -P '-tty='; then
+ compadd - /dev/tty*
+elif compset -P '-(exec|se)='; then
+ _files -/g '*(*)'
+elif compset -P '-(symbols|core|command)='; then
+ _files
+elif compset -P -; then
+ compadd -QS '' - symbols\= exec\= se\= core\= command\= directory\= \
+ cd\= tty\=
+ compadd - help h s e c x d nx n quiet q batch fullname f b
+else
+ prev="$words[CURRENT-1]"
+
+ case "$prev" in
+ (-d) _files -/ && return 0 ;;
+ (-e) _files -/g '*(*)' && return 0 ;;
+ (-[csx]) _files && return 0 ;;
+ (-b) compadd -V baud 0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 \
+ 9600 19200 38400 57600 115200 230400 && return 0 ;;
+ esac
+ w=( "${(@)words[2,-1]}" )
+ while [[ "$w[1]" = -* ]]; do
+ [[ "$w[1]" = -[decsxb] ]] && shift 1 w
+ shift 1 w
+ done
+
+ if [[ $#w -gt 1 ]]; then
+ _files && ret=0
+ list=("${(F)${(@Mr:COLUMNS-1:)${(f)$(ps ${compconfig[ps_listargs]:-$compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ ]#${PREFIX}[0-9]#${SUFFIX}[ ]*${w[1]}}}")
+ compgen -y '$list' -s "\${\${\${(M)\${(f)\"\$(ps $compconfig[ps_args] 2>/dev/null)\"}:#*${w[1]:t}*}## #}%% *}" && ret=0
+
+ return ret
+ else
+ _files -/g '*(*)'
+ fi
+fi
diff -u -r oc/User/_make Completion/User/_make
--- oc/User/_make Wed Jun 16 08:22:17 1999
+++ Completion/User/_make Wed Jun 16 08:42:46 1999
@@ -1,4 +1,24 @@
#compdef make gmake pmake
-compgen -s "\$(awk '/^[a-zA-Z0-9][^\/ ]+:/ {print \$1}' FS=: [mM]akefile /dev/null)" ||
-_files
+local prev="$words[CURRENT-1]" file ret=1
+
+if [[ "$prev" = -[CI] ]]; then
+ _files -/
+elif [[ "$prev" = -[foW] ]]; then
+ _files
+else
+ file="$words[(I)-f]"
+ if (( file )); then
+ file="$words[file+1]"
+ elif [[ -e Makefile ]]; then
+ file=Makefile
+ elif [[ -e makefile ]]; then
+ file=makefile
+ else
+ file=''
+ fi
+
+ [[ -n "$file" ]] &&
+ compadd - $(awk '/^[a-zA-Z0-9][^/ ]+:/ {print $1}' FS=: $file) && ret=0
+ (( ret )) && _files
+fi
diff -u -r oc/User/_mh Completion/User/_mh
--- oc/User/_mh Wed Jun 16 08:22:17 1999
+++ Completion/User/_mh Wed Jun 16 08:42:46 1999
@@ -39,7 +39,7 @@
elif [[ "$prev" = -(editor|(whatnow|rmm|show|more)proc) ]]; then
compgen -c
elif [[ "$prev" = -file ]]; then
- compgen -f
+ _files
elif [[ "$prev" = -(form|audit|filter) ]]; then
# Need some MH template file, which may be in our own MH directory
# or with the standard library.
@@ -69,7 +69,7 @@
# leaving foldnam empty works here
fi
- compgen -s '$(mark $foldnam 2>/dev/null | awk -F: '\''{ print $1 }'\'')' &&
+ compadd $(mark $foldnam 2>/dev/null | awk -F: '{ print $1 }') &&
ret=0
compadd reply next cur prev first last all unseen && ret=0
compgen -W folddir -g '<->' && ret=0
diff -u -r oc/User/_rlogin Completion/User/_rlogin
--- oc/User/_rlogin Wed Jun 16 08:22:18 1999
+++ Completion/User/_rlogin Wed Jun 16 08:42:46 1999
@@ -3,7 +3,7 @@
if [[ CURRENT -eq 2 ]]; then
compgen -k hosts
elif [[ CURRENT -eq 3 ]]; then
- compgen -k '(-l)'
+ compadd - -l
else
compgen -u
fi
diff -u -r oc/User/_x_options Completion/User/_x_options
--- oc/User/_x_options Wed Jun 16 08:22:17 1999
+++ Completion/User/_x_options Wed Jun 16 08:42:46 1999
@@ -2,4 +2,4 @@
# A simple pattern completion, just as an example.
-compgen -J options -k '(-display -name -xrm)'
+compadd -J options - -display -name -xrm
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author