Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to complete alias after alias of sudo?
- X-seq: zsh-users 22722
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: How to complete alias after alias of sudo?
- Date: Thu, 01 Jun 2017 10:19:45 +0100
- Cms-type: 201P
- In-reply-to: <20170601054320.GA3602@localhost.localdomain>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Organization: Samsung Cambridge Solution Centre
- References: <CGME20170531082709epcas5p4cb74739bb440049fd96ca18a08489bbd@epcas5p4.samsung.com> <20170531064655.GA8512@localhost.localdomain> <20170531094310.59bb7110@pwslap01u.europe.root.pri> <20170601054320.GA3602@localhost.localdomain>
On Thu, 1 Jun 2017 13:43:20 +0800
Han Pingtian <hanpt@xxxxxxxxxxxxxxxxxx> wrote:
> Looks like if change the line 52 of _sudo from
>
> 52 '(-)1:command: _command_names -e'
>
> to
>
> 52 '(-)1:command: _command_names'
>
> then alias will be listed. But looks like it's not a good idea to
> complete alias after sudo?
With -s or -i (which is what you said yesterday, and it went slightly
over my head, so I missed the point), it is executing a shell command
line. Then actually I think there *is* an argument for making the
completion more complete. I'm not sure how good the argument is, though
--- the -s and -i arguments are potentially dangerous and ideally the
shell being run is a pruned version that may not have the same aliases
defined. That said, what you complete isn't determining how safe your
sudo environment is anyway, so maybe this is a non-issue.
Anyway, we could do this.
pws
diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo
index aa7a1a4..0b09ded 100644
--- a/Completion/Unix/Command/_sudo
+++ b/Completion/Unix/Command/_sudo
@@ -41,6 +41,8 @@ if [[ $service = sudoedit ]] || (( $words[(i)-e] < $words[(i)^(*sudo|-[^-]*)] ))
args=( -A "-*" $args '!(-V --version -h --help)-e' '*:file:_files' )
else
cmd="$words[1]"
+ local ext
+ (( ${words[(I)-[is]]} == 0 )) && ext=" -e"
args+=(
'(-e --edit 1 *)'{-e,--edit}'[edit files instead of running a command]' \
'(-s --shell)'{-s,--shell}'[run shell as the target user; a command may also be specified]' \
@@ -49,7 +51,7 @@ else
'(-E --preserve-env -i --login -s --shell -e --edit)'{-E,--preserve-env}'[preserve user environment when running command]' \
'(-H --set-home -i --login -s --shell -e --edit)'{-H,--set-home}"[set HOME variable to target user's home dir]" \
'(-P --preserve-groups -i -login -s --shell -e --edit)'{-P,--preserve-groups}"[preserve group vector instead of setting to target's]" \
- '(-)1:command: _command_names -e'
+ "(-)1:command: _command_names$ext"
'*::arguments:{ _comp_priv_prefix=( $cmd -n ${(kv)opt_args[(I)(-[ugHEP]|--(user|group|set-home|preserve-env|preserve-groups))]} ) ; _normal }'
)
fi
Messages sorted by:
Reverse Date,
Date,
Thread,
Author