salman-abedin / devour

X11 window swallower
GNU General Public License v2.0
415 stars 30 forks source link

Autocompletion #2

Closed MarcinWieczorek closed 4 years ago

MarcinWieczorek commented 4 years ago

Hello, thank you for the tool.

I copied and reduced sudo's zsh autocompletion, I thought I'd share. I would do a pull request, but I don't really understand how it works. Hope you merge it some day.

#compdef devour

setopt localoptions extended_glob

local environ e cmd
local -a args
local -a _comp_priv_prefix

zstyle -a ":completion:${curcontext}:" environ environ

for e in "${environ[@]}"
do local -x "$e"
done

args+=(
  '(-)1:command: _command_names -e'
  '*::arguments:{ _comp_priv_prefix=( $cmd -n ${(kv)opt_args[(I)(-[ugHEP]|--(user|group|set-home|preserve-env|preserve-groups))]} ) ; _normal }'
)

_arguments -s -S $args
salman-abedin commented 4 years ago

I seek to keep my scripts portable and turning it into a shell specific script would defeat that purpose. Glad to know you got some use out of it though.

MarcinWieczorek commented 4 years ago

Autocompletion is an addition to the script, it tunes the shell to the tool and not the other way. It's your choice though.

AriaMoradi commented 4 years ago

complete -cf devour would be much simpler but you need to add it to your .bashrc