Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: Re: Completion/User functions again
- X-seq: zsh-workers 7140
- From: Tanaka Akira <akr@xxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: PATCH: Re: Completion/User functions again
- Date: 14 Jul 1999 22:12:41 +0900
- In-reply-to: Sven Wischnowsky's message of "Wed, 14 Jul 1999 14:46:28 +0200 (MET DST)"
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <199907141246.OAA11798@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
In article <199907141246.OAA11798@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx> writes:
> While we are at it: we still don't have completion functions for some
> commands for which we have compctl examples, e.g. cvs and rpm. I don't
> use either of these often enough to be able to write good functions
> for them -- any volunteers for that?
I wrote _cvs.
But it's ugly, not self-contained and it doesn't deal with CVS/Entries.
And I don't have a time to implove it in this week.
So, if another implementation exists, it may better.
---------- _cvs ----------
#compdef cvs
typeset -A short_opts
local com="${words[(i)(add|ad|new|admin|adm|rcs|annotate|ann|checkout|co|get|commit|ci|com|diff|di|dif|edit|editors|export|exp|ex|history|hi|his|import|im|imp|init|log|lo|rlog|login|logon|lgn|logout|rdiff|patch|release|re|rel|remove|rm|delete|status|st|stat|rtag|rt|rfreeze|tag|ta|freeze|unedit|update|up|upd|watch|watchers)]}"
local complete_D="compgen -k '(yesterday week\\ ago month\\ ago)'"
local complete_k="compgen -k '(kv kvl k o b v)'"
local complete_r="compgen -k '(tag)'"
#_view_completion_parameters "com=$com"
if (( $com < $CURRENT )); then
case "$words[$com]" in
add|ad|new) # "+k:m:"
short_opts=(k: "$complete_k" m: "compgen -k '(MESSAGE)'")
_complete_opts || compgen -f
;;
admin|adm|rcs) # "+ib::c:a:A:e:l::u::LUn:N:m:o:s:t::IqxV:k:"
short_opts=(i '' b:: '' c: '' a: '' A: '' e: '' l:: '' u:: '' L '' U '' n: '' N: '' m: '' o: '' s: '' t:: '' I '' q '' x '' V: '' k: '')
_complete_opts || compgen -f
;;
annotate|ann) # "+lr:D:fR"
short_opts=(l '' r: '' D: '' f '' R '')
_complete_opts || compgen -f
;;
checkout|co|get) # "+ANnk:d:flRpQqcsr:D:j:P"
short_opts=(A '' N '' n '' k: "$complete_k" d: '' f '' l '' R '' p '' Q '' q '' c '' s '' r: "$complete_r" D: "$complete_D" j: '' P '')
_complete_opts || compgen -k '(MODULE)'
;;
commit|ci|com) # "+nlRm:fF:r:"
short_opts=(n '' l '' R '' m: '' f '' F: '' r: "$complete_r")
_complete_opts || compgen -f
;;
diff|di|dif) # "+abcdefhilnpstuw0123456789BHNRC:D:F:I:L:U:V:W:k:r:"
short_opts=(a '' b '' c '' d '' e '' f '' h '' i '' l '' n '' p '' s '' t '' u '' w ''
0 '' 1 '' 2 '' 3 '' 4 '' 5 '' 6 '' 7 '' 8 '' 9 '' B '' H '' N '' R ''
C: '' D: "$complete_D" F: '' I: '' L: '' U: '' V: '' W: '' k: "$complete_k" r: "$complete_r")
_complete_opts || compgen -f
;;
edit) # "+lRa:"
short_opts=(l '' R '' a: '')
_complete_opts || compgen -f
;;
editors) # "+lR"
short_opts=(l '' R '')
_complete_opts || compgen -f
;;
export|exp|ex) # "+ANnk:d:flRpQqcsr:D:j:P"
short_opts=(A '' N '' n '' k: "$complete_k" d: '' f '' l '' R '' p '' Q '' q '' c '' s '' r: "$complete_r" D: "$complete_D" j: '' P '')
_complete_opts || compgen -k '(MODULE)'
;;
history|hi|his) # "+Tacelow?D:b:f:m:n:p:r:t:u:x:X:z:"
short_opts=(T '' a '' c '' e '' l '' o '' w '' \? '' D: "$complete_D" b: '' f: '' m: '' n: '' p: '' r: '' t: '' u: '' x: '' X: '' z: '')
_complete_opts || compgen -f
;;
import|im|imp) # "+Qqdb:m:I:k:W:"
short_opts=(Q '' q '' d '' b: '' m: '' I: '' k: '' W: '')
_complete_opts || compgen -k '(REPOSITORY-VENDORTAG-RELEASETAG)'
;;
init)
short_opts=()
_complete_opts || compgen -f
;;
login|logon|lgn)
short_opts=()
_complete_opts || compgen -f
;;
logout)
short_opts=()
_complete_opts || compgen -f
;;
rdiff|patch|pa) # "+V:k:cuftsQqlRD:r:"
short_opts=(V: '' k: "$complete_k" c '' u '' f '' t '' s '' Q '' q '' l '' R '' D: "$complete_D" r: "$complete_r")
_complete_opts || compgen -f
;;
release|re|rel) # "+Qdq"
short_opts=(Q '' d '' q '')
_complete_opts || compgen -f
;;
remove|rm|delete) # "+flR"
short_opts=(f '' l '' R '')
_complete_opts || compgen -f
;;
status|st|stat) # "+vlR"
short_opts=(v '' l '' R '')
_complete_opts || compgen -f
;;
tag|ta|freeze) # "+FQqlRcdr:D:bf"
short_opts=(F '' Q '' q '' l '' R '' c '' d '' r: "$complete_r" D: "$complete_D" b '' f '')
_complete_opts || compgen -f
;;
unedit) # "+lR"
short_opts=(l '' R '')
_complete_opts || compgen -f
;;
update|up|upd) # "+ApPflRQqduk:r:D:j:I:W:"
short_opts=(A '' p '' P '' f '' l '' R '' Q '' q '' d '' u '' k: "$complete_k" r: "$complete_r" D: "$complete_D" j: '' I: '' W: '')
_complete_opts || compgen -f
;;
watch)
if [[ $CURRENT = $(($com + 1)) ]]; then
compgen -k '(on off add remove)'
else
case "$words[$com+1]" in
on|off) # "+lR"
short_opts=(l '' R '')
_complete_opts || compgen -f
;;
add|remove) # "+lRa:"
short_opts=(l '' R '' a: '')
_complete_opts || compgen -f
;;
esac
fi
;;
watchers) # "+lR"
short_opts=(l '' R '')
_complete_opts || compgen -f
;;
*) compgen -f;;
esac
return
fi
case ${+cvs_roots} in
0)
cvs_roots=()
if [[ -f ~/.cvspass ]]; then
cvs_roots=(
$(cut -d ' ' -f 1 ~/.cvspass)
)
fi
;;
esac
short_opts=(
H '' Q '' q '' r '' w '' l '' n '' t '' v '' f '' a ''
b: "compgen -k '(/usr/local/bin)'"
T: "compgen -k '(/tmp)'"
e: "compgen -k '(vi)'"
d: "compgen -k cvs_roots || compgen -/"
z: "compgen -k '(9)'"
s: "_cvs_user_variable"
)
_complete_opts ||
compgen -k '(add admin annotate checkout commit
diff edit editors export history
import init log login logout
rdiff release remove status rtag
tag unedit update watch watchers)' ||
compgen -k '(add ad new admin adm rcs annotate ann
checkout co get commit ci com diff di dif
edit editors export exp ex
history hi his import im imp init
log lo rlog login logon lgn logout
rdiff patch release re rel remove rm delete
status st stat rtag rt rfreeze tag ta freeze
unedit update up upd watch
watchers)'
------------------------------
---------- _complete_opts ----------
#autoload
# Usage:
# typeset -A short_opts
# short_opts=(
# H ''
# f 'compgen -f'
# )
# _complete_opts
typeset -a no_arg with_arg
no_arg=($short_opts[(I)?])
with_arg=($short_opts[(I)?:]:s/://)
case "${#no_arg}-${#with_arg}" in
0-0)
if [[ x$PREFIX = x-* ]]; then
compgen -k '()'
else
false
fi
;;
0-*)
if [[ x$PREFIX = x- ]]; then
IPREFIX="$IPREFIX$PREFIX"
PREFIX=
compgen -k with_arg
elif [[ x$PREFIX = x-[${(j::)with_arg}] ]]; then
IPREFIX="$IPREFIX$PREFIX"
PREFIX=
eval $short_opts[$IPREFIX[-1]:]
elif [[ x$PREFIX = x-[${(j::)with_arg}]* ]]; then
local p="$PREFIX[1,(r)[${(j::)with_arg}]]"
IPREFIX="$IPREFIX$p"
PREFIX="$PREFIX[$#p + 1,-1]"
eval $short_opts[$IPREFIX[-1]:]
elif [[ x$words[$CURRENT-1] = x-[${(j::)with_arg}] ]]; then
local p="$words[$CURRENT - 1]"
eval $short_opts[$p[-1]:]
else
false
fi
;;
*-0)
if [[ x$PREFIX = x-[${(j::)no_arg}]# ]]; then
IPREFIX="$IPREFIX$PREFIX"
PREFIX=
compgen -k no_arg
else
false
fi
;;
*-*)
if [[ x$PREFIX = x-[${(j::)no_arg}]# ]]; then
IPREFIX="$IPREFIX$PREFIX"
PREFIX=
compgen -k no_arg
compgen -k with_arg
elif [[ x$PREFIX = x-[${(j::)no_arg}]#[${(j::)with_arg}] ]]; then
IPREFIX="$IPREFIX$PREFIX"
PREFIX=
eval $short_opts[$IPREFIX[-1]:]
elif [[ x$PREFIX = x-[${(j::)no_arg}]#[${(j::)with_arg}]* ]]; then
local p="$PREFIX[1,(r)[${(j::)with_arg}]]"
IPREFIX="$IPREFIX$p"
PREFIX="$PREFIX[$#p + 1,-1]"
eval $short_opts[$IPREFIX[-1]:]
elif [[ x$words[$CURRENT-1] = x-[${(j::)no_arg}]#[${(j::)with_arg}] ]]; then
local p="$words[$CURRENT - 1]"
eval $short_opts[$p[-1]:]
else
false
fi
;;
esac
------------------------------
Also, I wrote _wget, _lynx, etc. If you interest them, See
http://www.ldl.jaist.ac.jp/~akr/zsh/dot-zsh/funcs/.
I want standard way to specify user's completion preferences such as
host-port relation for _telnet and _socket, URLs for _wget and _lynx,
user-host relation for _finger, and so on.
--
Tanaka Akira
Messages sorted by:
Reverse Date,
Date,
Thread,
Author