First stab
This commit is contained in:
parent
2daffc8694
commit
c6b841de6c
12
abra
12
abra
@ -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
37
completion.bash
Normal 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
|
Loading…
Reference in New Issue
Block a user