38 lines
876 B
Bash
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
|