First stab

This commit is contained in:
3wc 2020-10-30 16:34:15 +02:00
parent 2daffc8694
commit c6b841de6c
2 changed files with 49 additions and 0 deletions

12
abra
View File

@ -842,6 +842,18 @@ sub_volume() {
docker volume $@
}
#######################################
# Bash completion helpers
#######################################
sub_command_ls() {
docopt_exit 2>&1 | \
tail -n+2 | \
sed -s -e 's/^\s\+//g' -e 's/(\([^)]*\)|.*)/\1/' -e 's/\[options\]//g' \
-e 's/ <[^>]\+>//g' -e 's/\.\.\.//g' -e 's/^abra\s*//' -e '/^$/d' | \
sort -u
}
#######################################
# Main
#######################################

37
completion.bash Normal file
View File

@ -0,0 +1,37 @@
#!/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