From 543072ab3750b9feb4dc38486d2fd3c84f279da2 Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Sun, 1 Nov 2020 21:08:45 +0200 Subject: [PATCH] Add zsh completion, remove compat hacks from bash Ref #5 --- completion/_abra | 52 +++++++++++++++++++++++++ completion.bash => completion/abra.bash | 16 +------- 2 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 completion/_abra rename completion.bash => completion/abra.bash (87%) diff --git a/completion/_abra b/completion/_abra new file mode 100644 index 0000000..2cb1f76 --- /dev/null +++ b/completion/_abra @@ -0,0 +1,52 @@ +#compdef abra + +_abra () { + local context state line curcontext="$curcontext" ret=1 + _arguments -n : \ + {-h,--help}'[Help message]' \ + '1:commands:(app server)' \ + '*::arguments:->arguments' \ + && ret=0 + + case $state in + (arguments) + curcontext="${curcontext%:*:*}:abra-arguments-$words[1]:" + case $words[1] in + (app) + _arguments \ + '1: :_abra_apps' \ + && ret=0 + ;; + (server) + _arguments \ + '1:servers:_abra_servers' \ + && ret=0 + ;; + esac + ;; + esac + + return ret +} + +_abra_servers() { + _path_files -/W $HOME/.abra/servers +} + +_abra_apps() +{ + local newapps apps=($HOME/.abra/servers/*/*.env) + typeset -a apps + newapps=() + for app in $apps; do + newapps+=($(_abra_basename "${app}")) + done + _describe -t apps 'app' newapps +} + +_abra_basename() +{ + printf -- "${1##*/}" +} + +_abra "$@" diff --git a/completion.bash b/completion/abra.bash similarity index 87% rename from completion.bash rename to completion/abra.bash index 8241393..5507bfb 100644 --- a/completion.bash +++ b/completion/abra.bash @@ -40,13 +40,8 @@ _abra_complete_apps() _abra_complete() { - # https://github.com/andsens/homeshick/blob/master/completions/homeshick-completion.bash - if $_ABRA_HAS_COMPOPT; then - compopt +o default +o nospace - COMPREPLY=() - else - COMPREPLY=('') - fi + compopt +o default +o nospace + COMPREPLY=() local -r cmds=' app @@ -119,11 +114,4 @@ _abra_complete() fi } -# https://github.com/andsens/homeshick/blob/master/completions/homeshick-completion.bash -if type compopt &>/dev/null; then - _ABRA_HAS_COMPOPT=true -else - _ABRA_HAS_COMPOPT=false -fi - complete -o default -F _abra_complete abra