This repository has been archived on 2021-07-03. You can view files and clone it, but cannot push or open issues or pull requests.
abra/completion.bash
2020-10-30 17:52:47 +02:00

38 lines
876 B
Bash

#!/env bash
#/usr/bin/env bash
_abra_completions()
{
local CUR PREV COMMANDS_LIST COMMANDS
CUR=${COMP_WORDS[COMP_CWORD]}
PREV=${COMP_WORDS[COMP_CWORD-1]}
mapfile -t COMMANDS_LIST < <(abra command_ls)
echo "${COMMANDS_LIST[@]}"
case ${COMP_CWORD} in
1)
COMPREPLY=($(compgen -W "${COMMANDS_LIST[*]%% *}" -- ${CUR}))
;;
2)
SUB_COMMANDS=()
for COMMAND in "${COMMANDS_LIST[@]}"; do
echo $PREV
if [[ COMMAND =~ $PREV ]]; then
echo "FOUND $PREV $COMMAND"
SUB_COMMANDS+=("$COMMAND")
fi
done
COMPREPLY=($(compgen -W "${COMMANDS[*]#* }" -- ${CUR}))
;;
*)
echo $COMP_CWORD
COMPREPLY=()
;;
esac
}
complete -F _abra_completions abra