Files
docker-finance/client/src/docker/completion.bash
Aaron Fiore 0db5566d9f client: add dfi alias
- `dfi` is now primary unified command (saves fingers)
  * `docker-finance` is still available, as this is only an addition
- Also fixes missing line continuation during install (#104)
2024-08-06 02:15:38 -07:00

103 lines
3.2 KiB
Bash

#!/usr/bin/env bash
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# If not yet installed, gracefully exit
if ! hash docker &>/dev/null; then
exit 0
fi
function docker-finance::completion()
{
local _cur="${COMP_WORDS[COMP_CWORD]}"
local _prev="${COMP_WORDS[COMP_CWORD - 1]}"
local _images
mapfile -t _images < <(docker image ls | grep ^docker-finance | cut -d'/' -f2- | cut -d' ' -f1-4 | sed -e 's/ /:/')
declare -r _images
local -r _commands=("gen" "edit" "build" "backup" "rm" "up" "down" "start" "stop" "run" "shell" "version" "license" "linter" "doxygen")
local _reply
case $COMP_CWORD in
1)
mapfile -t _reply < <(compgen -W "${_images[*]}" -- "$_cur")
declare -r _reply
# TODO: HACK for colon tag. Consider using bash-completion package.
for _r in "${_reply[@]}"; do
COMPREPLY+=("'${_r}'")
done
;;
2)
mapfile -t _reply < <(compgen -W "${_commands[*]}" -- "$_cur")
declare -r _reply
COMPREPLY=("${_reply[@]}")
;;
# TODO: multiple options (in 3) should have multiple completions
3)
# NOTE: same as in client impl
[ -z "$global_arg_delim_2" ] && global_arg_delim_2="="
# Disable space after completion
compopt -o nospace
case "$_prev" in
gen)
# TODO: _currently no-op
;;
edit)
mapfile -t _reply < <(compgen -W "help type${global_arg_delim_2}" -- "$_cur")
;;
build)
mapfile -t _reply < <(compgen -W "help type${global_arg_delim_2}" -- "$_cur")
;;
backup | rm | up | down | start | stop)
# TODO: _currently no-op
;;
shell)
mapfile -t _reply < <(compgen -W "help user${global_arg_delim_2}" -- "$_cur")
;;
version)
mapfile -t _reply < <(compgen -W "help type${global_arg_delim_2}" -- "$_cur")
;;
license)
mapfile -t _reply < <(compgen -W "help file${global_arg_delim_2}" -- "$_cur")
;;
linter)
mapfile -t _reply < <(compgen -W "help type${global_arg_delim_2} file${global_arg_delim_2}" -- "$_cur")
;;
doxygen)
mapfile -t _reply < <(compgen -W "help gen${global_arg_delim_2} rm${global_arg_delim_2}" -- "$_cur")
;;
esac
declare -r _reply
COMPREPLY=("${_reply[@]}")
;;
*)
COMPREPLY=()
;;
esac
}
complete -F docker-finance::completion docker.bash
complete -F docker-finance::completion docker-finance
complete -F docker-finance::completion dfi
# vim: sw=2 sts=2 si ai et