* sudo completion
@ 1999-03-16 17:06 Andrej Borsenkow
0 siblings, 0 replies; only message in thread
From: Andrej Borsenkow @ 1999-03-16 17:06 UTC (permalink / raw)
To: ZSH workers mailing list
As I quite often use sudo, I really like to have it. May be, it will be of
some use to others.
Just a comment - there is no way for sudo to run internal (builtin) command,
so, I explicitly complete only external commands if we are in command
position.
cheers
/andrej
P.S. I don't provide a it as a patch as I don't deem it good enough. It
works for me though ...
#defcomp sudo
emulate -RL zsh
##
## Get the position of the first non-option argument (it should be command)
## The $words[1] is always "sudo"
##
local -i i=1 cmd=0
while [[ $i -lt $#words ]]
do
case $words[++i] in
-? )
continue
;;
* )
if [[ $i -gt 2 && ($words[i-1] == -p || $words[i-1] == -u) ]]
then
continue
fi
cmd=$i
break
;;
esac
done
##
## If we are at the first non-option argument, simply complete it
## as if it were external command
## If we are after the first non-option argument, complete
## as if it were given command
## Else the only sesnible completion seems to be for -u (users)
##
if [[ $cmd -gt 0 && -position cmd ]]
then
compgen -m
elif [[ $cmd -gt 0 && -position cmd -1 ]]
_normal
elif [[ -current -1 -u ]]
then
compgen -u
else
return 0
fi
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1999-03-17 9:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-16 17:06 sudo completion Andrej Borsenkow
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).