-
-
Save ckerr/0a25283ed7e6f214b1b349180985c929 to your computer and use it in GitHub Desktop.
zsh tab completion for https://github.com/electron/build-tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#compdef e | |
# if using oh-my-zsh, install in ~/.oh-my-zsh/completions/ | |
declare -a __e_options=() | |
function __e_get_cmd_options() { | |
local -a options=() | |
"$@" --help | \ | |
awk '/^Options:/{flag=1;next}/^$/{flag=0}flag' | \ | |
sed 's/ /;/g' | cut -f2 -d';' | \ | |
sed 's/^-[a-zA-Z0-9], //g' | \ | |
cut -f1 -d' ' | \ | |
while read -r option; do | |
options+=($option) | |
done | |
__e_options=($options[@]) | |
} | |
declare -a __e_subcommands=() | |
function __e_get_cmd_subcommands() { | |
local -a subcommands=() | |
"$@" --help | \ | |
awk '/^Commands:/{flag=1;next}/^$/{flag=0}flag' | \ | |
sed 's/ /;/g' | cut -f2 -d';' | \ | |
sed 's/|/\n/' | \ | |
cut -f1 -d' ' | \ | |
while read -r subcommand; do | |
subcommands+=($subcommand) | |
done | |
__e_subcommands=("$subcommands[@]") | |
} | |
declare -a __e_configs=() | |
function __e_get_configs() { | |
local -a configs=() | |
e show configs | \ | |
sed 's/..//' | \ | |
sort | \ | |
while read -r configname; do | |
configs+=($configname) | |
done | |
__e_configs=("$configs[@]") | |
} | |
declare -a __e_targets=() | |
function __e_get_targets() { | |
local -a targets=() | |
e build --list-targets | \ | |
sed 's/, / /g' | \ | |
tr ' ' '\n' | \ | |
sort | \ | |
while read -r target; do | |
targets+=($target) | |
done | |
__e_targets=("$targets[@]") | |
} | |
__e_get_cmd_subcommands e | |
__e_get_cmd_options e | |
declare line | |
_arguments -C \ | |
'1: :($__e_subcommands $__e_options)' \ | |
'*::arg:->args' \ | |
&& ret=0 | |
case $line[1] in | |
(use) | |
__e_get_configs | |
_arguments -C \ | |
'1: :($__e_configs)' \ | |
'*::arg:->args' \ | |
&& ret=0 | |
;; | |
(build|make) | |
__e_get_targets | |
__e_get_cmd_subcommands e $line[1] | |
__e_get_cmd_options e $line[1] | |
_arguments -C \ | |
'1: :("${__e_targets[@]}" $__e_subcommands $__e_options)' \ | |
'*::arg:->args' \ | |
&& ret=0 | |
;; | |
(*) | |
__e_get_cmd_subcommands e $line[1] | |
__e_get_cmd_options e $line[1] | |
_arguments -C \ | |
'1: :($__e_subcommands $__e_options)' \ | |
'*::arg:->args' \ | |
&& ret=0 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment