* Re: PATCH: _groups and _condition
@ 2000-03-13 12:17 Sven Wischnowsky
0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 2000-03-13 12:17 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer wrote:
> On Mar 12, 3:22pm, Oliver Kiddle wrote:
> } Subject: PATCH: _groups and _condition
> }
> } Also here, is a patch against _condition so that it completes only files
> } after more of its options.
>
> This question isn't really directed at Oliver, but:
>
> Out of curiosity, why doesn't _condition complete any of the options
> themselves? E.g. If I do
>
> zsh% [[ -<TAB>
>
> it just inserts a space. I expected it to list -n, -z, -t, etc.
Because it's really old and noone took the time to change it.
The patch also fixes a problem when completing after `[[ ... && <TAB>'
-- it thought it were in command position.
Bye
Sven
diff -ru ../z.old/Completion/Base/_condition Completion/Base/_condition
--- ../z.old/Completion/Base/_condition Mon Mar 13 11:14:30 2000
+++ Completion/Base/_condition Mon Mar 13 13:14:20 2000
@@ -1,11 +1,55 @@
#compdef -condition-
-local prev="$words[CURRENT-1]"
+local prev="$words[CURRENT-1]" ret=1
if [[ "$prev" = -o ]]; then
_tags -C -o options && _options
elif [[ "$prev" = -([a-hkprsuwxLOGSN]|[no]t|ef) ]]; then
_tags -C "$prev" files && _files
else
- _alternative 'files:: _files' 'parameters:: _parameters'
+ if [[ "$PREFIX" = -* ]] ||
+ ! zstyle -T ":completion:${curcontext}:options" prefix-needed; then
+
+ if [[ "$prev" = (\[\[|\|\||\&\&|\!|\() ]]; then
+ _describe -o 'condition code' \
+ '( -a:existing\ file
+ -b:block\ special\ file
+ -c:character\ special\ file
+ -d:directory
+ -e:existing\ file
+ -f:regular\ file
+ -g:setgid\ bit
+ -h:symbolic\ link
+ -k:sticky\ bit
+ -n:non-empty\ string
+ -o:option
+ -p:named\ pipe
+ -r:readable\ file
+ -s:non-empty\ file
+ -t:terminal\ file\ descriptor
+ -u:setuid\ bit
+ -w:writable\ file
+ -x:executable\ file
+ -z:empty\ string
+ -L:symbolic\ link
+ -O:own\ file
+ -G:group-owned\ file
+ -S:socket
+ -N:unread\ file)' && ret=0
+ else
+ _describe -o 'condition code' \
+ '( -nt:newer\ than
+ -ot:older\ than
+ -ef:same\ file
+ -eq:numerically\ equal
+ -ne:numerically\ not\ equal
+ -lt:numerically\ less\ than
+ -le:numerically\ less\ then\ or\ equal
+ -lt:numerically\ greater\ than
+ -le:numerically\ greater\ then\ or\ equal)' && ret=0
+ fi
+ fi
+ _alternative 'files:: _files' 'parameters:: _parameters' && ret=0
+
+ return ret
fi
diff -ru ../z.old/Src/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- ../z.old/Src/Zle/zle_tricky.c Mon Mar 13 11:14:14 2000
+++ Src/Zle/zle_tricky.c Mon Mar 13 13:11:36 2000
@@ -978,7 +978,7 @@
* this would be to pass the command line through the parser too, *
* and get the arguments that way. Maybe in 3.1... */
do {
- lincmd = ((incmdpos && !ins) || (oins == 2 && i == 2) ||
+ lincmd = ((incmdpos && !ins && !incond) || (oins == 2 && i == 2) ||
(ins == 3 && i == 1));
linredir = (inredir && !ins);
oins = ins;
@@ -1023,7 +1023,7 @@
if (tok == ENDINPUT)
break;
if ((ins && (tok == DO || tok == SEPER)) ||
- (ins == 2 && i == 2) || (ins == 3 && i == 3) ||
+ (ins == 2 && i == 2) || (ins == 3 && i == 3) ||
tok == BAR || tok == AMPER ||
tok == BARAMP || tok == AMPERBANG ||
((tok == DBAR || tok == DAMPER) && !incond)) {
@@ -1060,6 +1060,12 @@
inwhat = IN_COND;
} else if (linredir)
continue;
+ if (incond) {
+ if (tok == DBAR)
+ tokstr = "||";
+ else if (tok == DAMPER)
+ tokstr = "&&";
+ }
if (!tokstr)
continue;
/* Hack to allow completion after `repeat n do'. */
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: _groups and _condition
2000-03-12 15:30 ` Oliver Kiddle
@ 2000-03-12 22:34 ` Bart Schaefer
0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2000-03-12 22:34 UTC (permalink / raw)
To: Oliver Kiddle, Zsh workers
On Mar 12, 3:30pm, Oliver Kiddle wrote:
} Subject: Re: PATCH: _groups and _condition
}
} Sorry, I yet again forgot to turn off word-wrap before sending a patch.
Your _groups is out of date -- my copy of _groups has
... $(_call groups ypcat group.byname) ...
And:
} --- Compoletion/Base/_condition.bak Sun Mar 12 06:42:06 2000
} +++ Compoletion/Base/_condition Sun Mar 12 06:46:23 2000
^^^
I don't have this directory. :-)
Here's a cleaned-up patch. I don't have ypcat, so I can't test it ...
Index: Completion/Base/_condition
===================================================================
@@ -4,7 +4,7 @@
if [[ "$prev" = -o ]]; then
_tags -C -o options && _options
-elif [[ "$prev" = -([no]t|ef) ]]; then
+elif [[ "$prev" = -([a-hkprsuwxLOGSN]|[no]t|ef) ]]; then
_tags -C "$prev" files && _files
else
_alternative 'files:: _files' 'parameters:: _parameters'
Index: Completion/User/_groups
===================================================================
@@ -1,13 +1,14 @@
#compdef newgrp
-local expl groups
+local expl groups tmp
_wanted groups expl group || return 1
if ! zstyle -a ":completion:${curcontext}:" groups groups; then
(( $+_cache_groups )) ||
- if (( ${+commands[ypcat]} )); then
- : ${(A)_cache_groups:=${${(s: :)$(_call groups ypcat group.byname)}%%:*}} # If you use YP
+ if (( ${+commands[ypcat]} )) &&
+ tmp=$(_call groups ypcat group.byname); then
+ : ${(A)_cache_groups:=${${(f)tmp}%%:*}} # If you use YP
else
: ${(A)_cache_groups:=${${(s: :)$(</etc/group)}%%:*}}
fi
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: _groups and _condition
2000-03-12 15:22 Oliver Kiddle
2000-03-12 15:30 ` Oliver Kiddle
@ 2000-03-12 21:36 ` Bart Schaefer
1 sibling, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2000-03-12 21:36 UTC (permalink / raw)
To: Oliver Kiddle, Zsh workers
On Mar 12, 3:22pm, Oliver Kiddle wrote:
} Subject: PATCH: _groups and _condition
}
} Also here, is a patch against _condition so that it completes only files
} after more of its options.
This question isn't really directed at Oliver, but:
Out of curiosity, why doesn't _condition complete any of the options
themselves? E.g. If I do
zsh% [[ -<TAB>
it just inserts a space. I expected it to list -n, -z, -t, etc.
} Incidentally, I had a look at whether it would be possible to add a
} completion for test and, more specifically, the '[' builtin. Putting
} [ or \[ after #compdef doesn't work.
I can't see any reason why it shouldn't. (The form with no backslash.)
It works for me. Did you remember to remove your ~/.zcompdump file?
} I can't use '[' as a key to an
} associative array if I use an assignment like: foo[\[]=whatever though
} it works fine if I do: a='[';foo[$a]=whatever or use an array style
} assignment.
That's because the string inside [ ] isn't tokenized yet at the point
where foo[\[] is tested by isident(). As a result, skipparens() finds
what appear to be unbalanced brackets. This is a known bug with the
parser, resulting from the way associative arrays were grafted on.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: _groups and _condition
2000-03-12 15:22 Oliver Kiddle
@ 2000-03-12 15:30 ` Oliver Kiddle
2000-03-12 22:34 ` Bart Schaefer
2000-03-12 21:36 ` Bart Schaefer
1 sibling, 1 reply; 5+ messages in thread
From: Oliver Kiddle @ 2000-03-12 15:30 UTC (permalink / raw)
To: Zsh workers
Sorry, I yet again forgot to turn off word-wrap before sending a patch.
Oliver
--- Completion/User/_groups.bak Thu Feb 17 17:52:19 2000
+++ Completion/User/_groups Sun Mar 12 07:18:55 2000
@@ -1,13 +1,13 @@
#compdef newgrp
-local expl groups
+local expl groups tmp
_wanted groups expl group || return 1
if ! zstyle -a ":completion:${curcontext}:" groups groups; then
(( $+_cache_groups )) ||
- if (( ${+commands[ypcat]} )); then
- : ${(A)_cache_groups:=${${(s: :)$(ypcat group.byname)}%%:*}} # If you use YP
+ if (( ${+commands[ypcat]} )) && tmp=$(ypcat group.byname); then
+ : ${(A)_cache_groups:=${${(f)tmp}%%:*}} # If you use YP
else
: ${(A)_cache_groups:=${${(s: :)$(</etc/group)}%%:*}}
fi
--- Compoletion/Base/_condition.bak Sun Mar 12 06:42:06 2000
+++ Compoletion/Base/_condition Sun Mar 12 06:46:23 2000
@@ -4,7 +4,7 @@
if [[ "$prev" = -o ]]; then
_tags -C -o options && _options
-elif [[ "$prev" = -([no]t|ef) ]]; then
+elif [[ "$prev" = -([a-hkprsuwxLOGSN]|[no]t|ef) ]]; then
_tags -C "$prev" files && _files
else
_alternative 'files:: _files' 'parameters:: _parameters'
^ permalink raw reply [flat|nested] 5+ messages in thread
* PATCH: _groups and _condition
@ 2000-03-12 15:22 Oliver Kiddle
2000-03-12 15:30 ` Oliver Kiddle
2000-03-12 21:36 ` Bart Schaefer
0 siblings, 2 replies; 5+ messages in thread
From: Oliver Kiddle @ 2000-03-12 15:22 UTC (permalink / raw)
To: Zsh workers
When completing groups, just checking that the ypcat command exists is
not a reliable way of determining if YP is being used: it exists here
but isn't used. This patch to _groups, makes it also check the exit code
from ypcat (which fails here). There may be better ways of determining
if NIS is being used. Doesn't it use something like '+:+' as the last
line of /etc/passwd?
Also here, is a patch against _condition so that it completes only files
after more of its options. Incidentally, I had a look at whether it
would be possible to add a completion for test and, more specifically,
the '[' builtin. Putting [ or \[ after #compdef doesn't work. I can't
use '[' as a key to an associative array if I use an assignment like:
foo[\[]=whatever though it works fine if I do: a='[';foo[$a]=whatever
or use an array style assignment.
Oliver Kiddle
--- Completion/User/_groups.bak Thu Feb 17 17:52:19 2000
+++ Completion/User/_groups Sun Mar 12 07:18:55 2000
@@ -1,13 +1,13 @@
#compdef newgrp
-local expl groups
+local expl groups tmp
_wanted groups expl group || return 1
if ! zstyle -a ":completion:${curcontext}:" groups groups; then
(( $+_cache_groups )) ||
- if (( ${+commands[ypcat]} )); then
- : ${(A)_cache_groups:=${${(s: :)$(ypcat group.byname)}%%:*}} #
If you use YP
+ if (( ${+commands[ypcat]} )) && tmp=$(ypcat group.byname); then
+ : ${(A)_cache_groups:=${${(f)tmp}%%:*}} # If you use YP
else
: ${(A)_cache_groups:=${${(s: :)$(</etc/group)}%%:*}}
fi
--- Completion/Base/_condition.bak Sun Mar 12 06:42:06 2000
+++ Completion/Base/_condition Sun Mar 12 06:46:23 2000
@@ -4,7 +4,7 @@
if [[ "$prev" = -o ]]; then
_tags -C -o options && _options
-elif [[ "$prev" = -([no]t|ef) ]]; then
+elif [[ "$prev" = -([a-hkprsuwxLOGSN]|[no]t|ef) ]]; then
_tags -C "$prev" files && _files
else
_alternative 'files:: _files' 'parameters:: _parameters'
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2000-03-13 12:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-13 12:17 PATCH: _groups and _condition Sven Wischnowsky
-- strict thread matches above, loose matches on Subject: below --
2000-03-12 15:22 Oliver Kiddle
2000-03-12 15:30 ` Oliver Kiddle
2000-03-12 22:34 ` Bart Schaefer
2000-03-12 21:36 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).