#!/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 . [ -z "$DOCKER_FINANCE_CONTAINER_FLOW" ] && exit 1 function docker-finance::completion() { local -r _cur="${COMP_WORDS[COMP_CWORD]}" local -r _prev="${COMP_WORDS[COMP_CWORD - 1]}" local _profiles mapfile -t _profiles < <(pushd "${DOCKER_FINANCE_CONTAINER_FLOW}"/profiles &>/dev/null && ls -d */*) declare -r _profiles local -r _commands=("all" "edit" "fetch" "import" "ledger" "ledger-ui" "ledger-web" "meta" "reports" "root" "taxes") local _reply case $COMP_CWORD in 1) mapfile -t _reply < <(compgen -W "${_profiles[*]}" -- "$_cur") declare -r _reply COMPREPLY=("${_reply[@]}") ;; 2) mapfile -t _reply < <(compgen -W "${_commands[*]}" -- "$_cur") declare -r _reply COMPREPLY=("${_reply[@]}") ;; 3) # NOTE: same as in impl [ -z "$global_arg_delim_2" ] && global_arg_delim_2="=" # Disable space after completion compopt -o nospace case "$_prev" in all) mapfile -t _reply < <(compgen -W "help year${global_arg_delim_2}" -- "$_cur") ;; edit) mapfile -t _reply < <(compgen -W "help type${global_arg_delim_2} account${global_arg_delim_2}" -- "$_cur") ;; fetch) mapfile -t _reply < <(compgen -W "help all${global_arg_delim_2} price${global_arg_delim_2} api${global_arg_delim_2} account${global_arg_delim_2} year${global_arg_delim_2} chain${global_arg_delim_2} blockchain${global_arg_delim_2}" -- "$_cur") ;; import) mapfile -t _reply < <(compgen -W "help year${global_arg_delim_2}" -- "$_cur") ;; ledger | hledger) mapfile -t _reply < <(compgen -W "-h" -- "$_cur") ;; ledger-ui | hledger-ui) mapfile -t _reply < <(compgen -W "-h" -- "$_cur") ;; ledger-web | hledger-web) mapfile -t _reply < <(compgen -W "-h" -- "$_cur") ;; meta) # NOTE: args are dependent upon metadata contents mapfile -t _reply < <(compgen -W "help" -- "$_cur") ;; reports) mapfile -t _reply < <(compgen -W "help all${global_arg_delim_2} type${global_arg_delim_2} interval${global_arg_delim_2} year${global_arg_delim_2}" -- "$_cur") ;; root) # TODO: currently no-op ;; taxes) mapfile -t _reply < <(compgen -W "help all${global_arg_delim_2} tag${global_arg_delim_2} account${global_arg_delim_2} year${global_arg_delim_2} write${global_arg_delim_2}" -- "$_cur") ;; esac declare -r _reply COMPREPLY=("${_reply[@]}") ;; *) COMPREPLY=() ;; esac } complete -F docker-finance::completion finance complete -F docker-finance::completion finance.bash complete -F docker-finance::completion docker-finance complete -F docker-finance::completion dfi # vim: sw=2 sts=2 si ai et