Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
sudo completion
- X-seq: zsh-workers 5836
- From: "Andrej Borsenkow" <borsenkow.msk@xxxxxx>
- To: "ZSH workers mailing list" <zsh-workers@xxxxxxxxxxxxxx>
- Subject: sudo completion
- Date: Tue, 16 Mar 1999 20:06:26 +0300
- Importance: Normal
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author