blob: 6901d14a911dfd2b93a931a4af7a4ff9a0a8261f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# bash completion for firefly (firefly-cli)
# Install: source this file, or drop it in /etc/bash_completion.d/ or
# /usr/share/bash-completion/completions/firefly
#
# Generated by scripts/gen_completion.py -- do not edit by hand.
# Regenerate when commands change (see CLAUDE.md):
# python scripts/gen_completion.py > completions/firefly.bash
_firefly() {
local cur prev words cword
_init_completion 2>/dev/null || {
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
words=("${COMP_WORDS[@]}")
cword=$COMP_CWORD
}
local global_opts="--human --url --token -h --help"
local groups="auth account category tag tx"
# Find the group and leaf among the words (skip the program name at 0).
local group="" leaf="" i
for ((i=1; i < cword; i++)); do
local w="${words[i]}"
case "$w" in
-*) ;; # an option, skip
--url|--token) ((i++));; # option that takes a value
*)
if [[ -z $group ]]; then group="$w"
elif [[ -z $leaf ]]; then leaf="$w"
fi
;;
esac
done
# Leaf-specific options.
local leaf_opts=""
case "$group $leaf" in
"auth set") leaf_opts="--token --url";;
"account balance") leaf_opts="--at";;
"account create") leaf_opts="--currency --if-not-exists --opening-balance --type";;
"account list") leaf_opts="--type";;
"tx add") leaf_opts="--category --date --desc --dry-run --from --skip-dupes --tags --to --type";;
"tx delete") leaf_opts="--yes";;
"tx edit") leaf_opts="--amount --category --date --desc --from --tags --to --type";;
"tx list") leaf_opts="--account --all --flat --limit --since --until";;
esac
# Leaves per group.
local leaves=""
case "$group" in
auth) leaves="set test";;
account) leaves="balance create get list";;
category) leaves="list";;
tag) leaves="list";;
tx) leaves="add delete edit get list search";;
esac
# Flag values: when the previous word is a flag with a fixed value set for
# this command, suggest those values instead of more flags.
local vals=""
case "$group $leaf $prev" in
"account create --type") vals="asset expense revenue";;
"account list --type") vals="asset expense revenue liability";;
"tx add --type") vals="withdrawal deposit transfer";;
"tx edit --type") vals="withdrawal deposit transfer";;
esac
if [[ -n $vals ]]; then
COMPREPLY=($(compgen -W "$vals" -- "$cur"))
return
fi
if [[ -z $group ]]; then
COMPREPLY=($(compgen -W "$groups $global_opts" -- "$cur"))
elif [[ -z $leaf ]]; then
COMPREPLY=($(compgen -W "$leaves" -- "$cur"))
else
COMPREPLY=($(compgen -W "$leaf_opts --help" -- "$cur"))
fi
}
complete -F _firefly firefly
|