Add zsh completion, remove compat hacks from bash

Ref #5
This commit is contained in:
3wc 2020-11-01 21:08:45 +02:00
parent 57e3a34133
commit 543072ab37
2 changed files with 54 additions and 14 deletions

52
completion/_abra Normal file
View File

@ -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 "$@"

View File

@ -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