Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: _rpm fixes
- X-seq: zsh-workers 7718
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: _rpm fixes
- Date: Wed, 8 Sep 1999 13:25:47 +0200 (MET DST)
- In-reply-to: Adam Spiers's message of Tue, 7 Sep 1999 17:48:34 +0100
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Adam Spiers wrote:
> Adam Spiers, on thelonious (adam@xxxxxxxxxxxxxxxxxxxxxxx) wrote:
> > Sven Wischnowsky (wischnow@xxxxxxxxxxxxxxxxxxxxxxx) wrote:
> > > I don't know `rpm' very well and the documentation I have is very
> > > imprecise, that's why I was asking for help when I first sent the
> > > `Rpm/*' functions.
> > >
> > > Is the rest of the function ok?
> >
> > I haven't played with it much yet (still discovering the joys of all
> > the bells and whistles with the new completion system,
> > e.g. description_format with group_matches, which is GREAT!) but I use
> > rpm a fair bit so of course I'll fix any more problems I find.
>
> Well, at least, I would if I knew how to...
>
> Next problem: rpm allows single letter switches to be grouped, but
> _rpm doesn't recognise this, e.g.
>
> % rpm -ihv <TAB>
>
> doesn't complete .rpm files.
>
> Presumably the -s of _arguments will help here, but how do you use it
> without mucking up all the long options? Two separate calls to
> _arguments?
No, `_arguments' has quite a bit of magic built in. One can use `-s'
together with long options without problems. `_rpm' describes a
`-pipe' option and even that seems to work (btw. is that correct, or
is the option really named `--pipe').
About the completion of `rpm -ihv': this is a bit of a problem,
because the first call to `_arguments' has to handle the `-i' and the
secoand call has to handle the rest of the line. The patch tries to
achieve this by using `-i+:*:...' on the first call (this didn't work
before -- the hunks in `_arguments' should fix it) and adding a
specification for the `-i' option on the second call.
For a simple thing such as this, this trick works. If we find an
example where it doesn't work, we'll probably have to allow option
descriptions to say that `everything up to this option is to be
removed from the option string from the line', so that the next call
to `_arguments' sees only those options it knows of. Or maybe we can
find a better solution.
Bye
Sven
diff -u -r oldcompletion/Base/_arguments Completion/Base/_arguments
--- oldcompletion/Base/_arguments Wed Sep 8 09:03:47 1999
+++ Completion/Base/_arguments Wed Sep 8 13:24:25 1999
@@ -6,7 +6,7 @@
setopt localoptions extendedglob
local args rest ws cur nth def nm expl descr action opt arg tmp xor
-local single uns ret=1 soptseq soptseq1 sopts prefix _line odescr
+local single uns ret=1 aret soptseq soptseq1 sopts prefix _line odescr
local beg optbeg argbeg nargbeg inopt inrest fromrest cmd="$words[1]"
local matched curopt
@@ -488,7 +488,7 @@
fi
if [[ "$def" = [^*]*[^\\]:*[^\\]:* ]]; then
def="${def#?*[^\\]:*[^\\]:}"
- else
+ elif [[ "$def" != \** ]]; then
def=''
fi
fi
@@ -548,7 +548,7 @@
def="${def#?*[^\\]:*[^\\]:}"
optbeg="$beg"
argbeg="$beg"
- else
+ elif [[ "$def" != \** ]]; then
def=''
fi
fi
@@ -560,12 +560,16 @@
if [[ -n "$uns" ]]; then
uns="${(@j::)${(v)=xors[(I)${ws[1][1]}[$uns]]}#[-+]}"
- tmp=(
- "opts[${(@)^opts[(I)${ws[1][1]}[$uns]]}]"
- "dopts[${(@)^dopts[(I)${ws[1][1]}[$uns]]}]"
- "odopts[${(@)^odopts[(I)${ws[1][1]}[$uns]]}]"
- )
- (( $#tmp )) && unset "$tmp[@]"
+ if [[ -n "$uns" ]]; then
+ tmp=(
+ "opts[${(@)^opts[(I)${ws[1][1]}[$uns]]}]"
+ "dopts[${(@)^dopts[(I)${ws[1][1]}[$uns]]}]"
+ "odopts[${(@)^odopts[(I)${ws[1][1]}[$uns]]}]"
+ "xors[${(@)^xors[(I)${ws[1][1]}[$uns]]}]"
+ )
+ odescr=( "${(@)odescr:#${ws[1][1]}[$uns]:*}" )
+ (( $#tmp )) && unset "$tmp[@]"
+ fi
fi
# If we didn't find a matching option description and we were
@@ -672,12 +676,16 @@
if [[ -n "$uns" ]]; then
uns="${(@j::)${(v)=xors[(I)${ws[1][1]}[$uns]]}#[-+]}"
- tmp=(
- "opts[${(@)^opts[(I)${pre[1]}[$uns]]}]"
- "dopts[${(@)^dopts[(I)${pre[1]}[$uns]]}]"
- "odopts[${(@)^odopts[(I)${pre[1]}[$uns](|=)]}]"
- )
- (( $#tmp )) && unset "$tmp[@]"
+ if [[ -n "$uns" ]]; then
+ tmp=(
+ "opts[${(@)^opts[(I)${pre[1]}[$uns]]}]"
+ "dopts[${(@)^dopts[(I)${pre[1]}[$uns]]}]"
+ "odopts[${(@)^odopts[(I)${pre[1]}[$uns](|=)]}]"
+ "xors[${(@)^xors[(I)${pre[1]}[$uns]]}]"
+ )
+ odescr=( "${(@)odescr:#${pre[1]}[$uns]:*}" )
+ (( $#tmp )) && unset "$tmp[@]"
+ fi
fi
# If we aren't in an argument directly after a option name, all option
@@ -740,7 +748,7 @@
options=( "${(@kv)_options}" )
state="${${action[3,-1]##[ ]#}%%[ ]#}"
compstate[restore]=''
- return 300
+ aret=yes
else
if [[ "${(t)line}" != *local* ]]; then
local line
@@ -799,7 +807,7 @@
# Probably add the option names.
if [[ -n "$opt" &&
- ( nm -eq compstate[nmatches] ||
+ ( ( nm -eq compstate[nmatches] && -z "$aret" ) ||
-z "$compconfig[option_prefix]" ||
"$compconfig[option_prefix]" = *\!${cmd}* ||
"$PREFIX" = [-+]* ) ]]; then
@@ -881,6 +889,8 @@
break
done
+
+[[ -n "$aret" ]] && return 300
# Set the return value.
diff -u -r oldcompletion/Linux/_rpm Completion/Linux/_rpm
--- oldcompletion/Linux/_rpm Wed Sep 8 09:03:54 1999
+++ Completion/Linux/_rpm Wed Sep 8 13:24:33 1999
@@ -50,21 +50,26 @@
# Do simple completions or get the first state.
-_arguments \
+_arguments -s \
'--rcfile:resource file:_files' \
'--ftpproxy:FTP proxy server:_hosts' \
'--ftpport:FTP port number:' \
'-q:*:query:->query' \
- -{V,v,vv,y,-{setperms,setugids,querytags,initdb,showrc}} \
- '-pipe:*:pipe command:_command_names -e' \
+ '*-v' \
+ -{V,y,-{setperms,setugids,querytags,initdb,showrc}} \
+ '-pipe:pipe command:_command_names -e' \
'--verify:*:verify:->verify' \
- -{i,-install}':*:install:->install' \
- -{U,-upgrade}':*:upgrade:->upgrade' \
- -{e,-erase}':*:uninstall:->uninstall' \
+ '-i+:*:install:->install' \
+ '--install:*:install:->install' \
+ '-U+:*:upgrade:->upgrade' \
+ '--upgrade:*:upgrade:->upgrade' \
+ '-e+:*:uninstall:->uninstall' \
+ '--erase:*:uninstall:->uninstall' \
-'b+:build stage:((p\:execute\ \%prep\ stage l\:do\ a\ list\ check c\:execute\ build\ stage i\:execute\ install\ stage b\:build\ a\ binary\ package a\:build\ binary\ and\ source\ packages)):*:build:->build_b' \
-'t+:build stage:((p\:execute\ \%prep\ stage l\:do\ a\ list\ check c\:execute\ build\ stage i\:execute\ install\ stage b\:build\ a\ binary\ package a\:build\ binary\ and\ source\ packages)):*:build:->build_t' \
--{rebuild,rmsource,recompile,resign,addsign}':*:RPM package:->package' \
- -{K,-checksig}':*:sigcheck:->sigcheck' \
+ '-K+:*:sigcheck:->sigcheck' \
+ '--checksig:*:sigcheck:->sigcheck' \
'--rebuilddb:*:rebuild:->rebuild' && ret=0
# As long as we have a state name...
@@ -85,8 +90,8 @@
case "$lstate" in
query)
- _arguments \
- -{v,vv} \
+ _arguments -s \
+ '*-v' \
'--rcfile:resource file:_files' \
'--ftpproxy:FTP proxy server:_hosts' \
'--ftpport:FTP port number:' \
@@ -101,8 +106,8 @@
'*:RPM package:->package_or_file' && ret=0
;;
verify)
- _arguments \
- -{v,vv} \
+ _arguments -s \
+ '*-v' \
'--rcfile:resource file:_files' \
'--ftpproxy:FTP proxy server:_hosts' \
'--ftpport:FTP port number:' \
@@ -112,11 +117,13 @@
'*:RPM package:->package' && ret=0
;;
upgrade)
- tmp=( --oldpackage )
+ tmp=( -U --oldpackage )
;&
install)
- _arguments "$tmp[@]" \
- -{v,vv} \
+ (( $#tmp )) || tmp=(-i)
+#set -x
+ _arguments -s "$tmp[@]" \
+ '*-v' \
'--rcfile:resource file:_files' \
'--ftpproxy:FTP proxy server:_hosts' \
'--ftpport:FTP port number:' \
@@ -128,8 +135,8 @@
'*:pkg file:->package_file' && ret=0
;;
uninstall)
- _arguments \
- -{v,vv} \
+ _arguments -s \
+ '*-v' -e \
'--rcfile:resource file:_files' \
'--ftpproxy:FTP proxy server:_hosts' \
'--ftpport:FTP port number:' \
@@ -144,8 +151,8 @@
build_t)
(( $#tmp )) || tmp=( '*:tar file:_files -g \*.\(\#i\)tar\(.\*\|\)' )
- _arguments \
- -{v,vv} \
+ _arguments -s \
+ '*-v' \
'--rcfile:resource file:_files' \
'--ftpproxy:FTP proxy server:_hosts' \
'--ftpport:FTP port number:' \
@@ -156,8 +163,8 @@
'--timecheck:time check (seconds):' "$tmp[1]" && ret=0
;;
sigcheck)
- _arguments \
- -{v,vv} \
+ _arguments -s \
+ '*-v' -K \
'--rcfile:resource file:_files' \
'--ftpproxy:FTP proxy server:_hosts' \
'--ftpport:FTP port number:' \
@@ -165,8 +172,8 @@
'*:RPM package file:->package_or_file' && ret=0
;;
rebuild)
- _arguments \
- -{v,vv} \
+ _arguments -s \
+ '*-v' \
'--rcfile:resource file:_files' \
'--ftpproxy:FTP proxy server:_hosts' \
'--ftpport:FTP port number:' \
@@ -185,7 +192,8 @@
if compset -P ftp:; then
_hosts -S/ && ret=0
else
- _files -g '*.(#i)rpm' && ret=0
+ _description expl 'RPM package file'
+ _files "$expl[@]" -g '*.(#i)rpm' && ret=0
fi
;;
tags)
diff -u od/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- od/Zsh/compsys.yo Tue Sep 7 14:58:11 1999
+++ Doc/Zsh/compsys.yo Wed Sep 8 11:47:28 1999
@@ -1000,7 +1000,11 @@
word from the line is considered to contain only one option (or
none). By giving the tt(-s) option to this function (as the first
argument), options are considered to be one-character options and the
-strings from the line may contain more than one such option letter.
+strings from the line may contain more than one such option
+letter. However, strings beginning with two hyphens (like
+`tt(-)tt(-prefix)') are still considered to contain only one option
+name. This allows the use of the `tt(-s)' option to describe
+single-letter options together with such long option names.
The function can also be made to automatically complete long options
for commands that support the `tt(-)tt(-help)' option as, for example,
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author