diff options
author | 2022-06-20 17:30:32 +0400 | |
---|---|---|
committer | 2022-06-20 06:30:32 -0700 | |
commit | 5d8a99e1d4009cb4b9c7766b2af76c3df8364670 (patch) | |
tree | 1e06d817f739ca82abb2d0b41a2d809898983466 | |
parent | 5eaf6d713e8d65121d47874faea832058ac1abc1 (diff) | |
download | bun-5d8a99e1d4009cb4b9c7766b2af76c3df8364670.tar.gz bun-5d8a99e1d4009cb4b9c7766b2af76c3df8364670.tar.zst bun-5d8a99e1d4009cb4b9c7766b2af76c3df8364670.zip |
Group zsh completion options by type (#194)
-rw-r--r-- | completions/bun.zsh | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/completions/bun.zsh b/completions/bun.zsh index 6298aa4b1..91becac35 100644 --- a/completions/bun.zsh +++ b/completions/bun.zsh @@ -1,4 +1,10 @@ _bun() { + zstyle ':completion:*:*:bun:*' group-name '' + zstyle ':completion:*:*:bun-grouped:*' group-name '' + + zstyle ':completion:*:*:bun::descriptions' format '%F{green}-- %d --%f' + zstyle ':completion:*:*:bun-grouped:*' format '%F{green}-- %d --%f' + local program=bun typeset -A opt_args local curcontext="$curcontext" state line context @@ -13,11 +19,11 @@ _bun() { cmd) local -a scripts_list IFS=$'\n' scripts_list=($(SHELL=zsh bun getcompletes i)) - compadd $scripts_list && ret=0 + scripts="scripts:scripts:(($scripts_list))" main_commands=('add\:"Add a dependency to package.json" bun\:"Generate a bundle" create\:"Create a new project" dev\:"Start a dev server" help\:"Show command help" install\:"Install packages from package.json" remove\:"Remove a dependency from package.json" run\:"Run a script or package bin" upgrade\:"Upgrade to the latest version of bun"') main_commands=($main_commands) - _alternative "args:bun:(($main_commands))" + _alternative "$scripts" "args:bun:(($main_commands))" ;; args) case $line[1] in @@ -242,22 +248,6 @@ _bun() { ;; - run) - - # ---- Command: help run - _arguments -s -C \ - '1: :->cmd1' \ - '2: :->cmd2' \ - '--version[Show version and exit]' \ - '-V[Show version and exit]' \ - '--cwd[Change directory]:cwd' \ - '--help[Show command help]' \ - '-h[Show command help]' \ - '--all[]' && - ret=0 - - ;; - create) # ---- Command: help create @@ -332,7 +322,6 @@ _bun() { ;; run) - # ---- Command: help run _arguments -s -C \ '1: :->cmd' \ @@ -438,7 +427,6 @@ _bun() { ;; run) - # ---- Command: run _arguments -s -C \ '1: :->cmd' \ @@ -454,6 +442,7 @@ _bun() { case $state in script) + curcontext="${curcontext%:*:*}:bun-grouped" _bun_run_param_script_completion ;; other) @@ -487,23 +476,22 @@ _bun() { _bun_run_param_script_completion() { local -a scripts_list IFS=$'\n' scripts_list=($(SHELL=zsh bun getcompletes s)) - compadd $scripts_list && ret=0 + scripts="scripts:scripts:(($scripts_list))" IFS=$'\n' bunjs=($(SHELL=zsh bun getcompletes j)) IFS=$'\n' bins=($(SHELL=zsh bun getcompletes b)) - if [ ! -z "$bunjs" -a "$bunjs" != " " ]; then - if [ ! -z "$bins" -a "$bins" != " " ]; then - compadd $bunjs && ret=0 - _alternative "args:bin:(($bins))" + if [ -n "$bunjs" ] && [ "$bunjs" != " " ]; then + if [ -n "$bins" ] && [ "$bins" != " " ]; then + _alternative $scripts "files:files:(($bunjs))" "bin:bin:(($bins))" return 1 fi - _alternative "args:Bun.js:(($bunjs))" + _alternative $scripts "args:Bun.js:(($bunjs))" fi - if [ ! -z "$bins" -a "$bins" != " " ]; then - _alternative "args:bin:(($bins))" + if [ -n "$bins" ] && [ "$bins" != " " ]; then + _alternative $scripts "args:bin:(($bins))" return 1 fi } |