Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to complete alias after alias of sudo?



On Thu, Jun 01, 2017 at 10:19:45AM +0100, Peter Stephenson wrote:
> 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
Thanks. But looks like the situation is a bit different. I have aliased
'sd' to 'sudo -i ', so another alias after 'sd' will be expanded before
command running. So the alias won't be passed to another shell. But
looks like it's not easy to enable alias completion in this situation?



Messages sorted by: Reverse Date, Date, Thread, Author