summaryrefslogtreecommitdiff
path: root/completion/etoolkit.bash
diff options
context:
space:
mode:
Diffstat (limited to 'completion/etoolkit.bash')
-rw-r--r--completion/etoolkit.bash105
1 files changed, 105 insertions, 0 deletions
diff --git a/completion/etoolkit.bash b/completion/etoolkit.bash
new file mode 100644
index 0000000..2e80811
--- /dev/null
+++ b/completion/etoolkit.bash
@@ -0,0 +1,105 @@
1# etoolkit bash-completion
2# -*- shell-script -*-
3
4_instances() {
5
6 local instances
7
8 if [[ -n ${2} ]]; then
9 instances="$(etoolkit -c $2 -l 2> /dev/null)"
10 else
11 instances="$(etoolkit -l 2> /dev/null)"
12 fi
13
14 if [[ $? -eq 0 ]]; then
15 COMPREPLY+=($(compgen -W "$instances" -- "$1"))
16 fi
17
18}
19
20
21_etoolkit() {
22
23 local all_params config_file c cur i no_output numwords prev spawn
24 COMPREPLY=()
25 cur="${COMP_WORDS[COMP_CWORD]}"
26 prev="${COMP_WORDS[COMP_CWORD-1]}"
27 numwords=${#COMP_WORDS[*]}
28 no_output=0
29 spawn=0
30 all_params="-d --decrypt-value -e --encrypt-value -l --list -h --help
31 -P --master-password-prompt -p --generate-master-password-hash
32 -c --config-file -E --echo -m --multiple-values -q --no-output
33 -s --spawn -v --version"
34 # if [ ${prev:0:1} == "-" ]
35
36 if [ ${COMP_CWORD} -eq 1 ]; then
37 # first param
38 COMPREPLY=($(compgen -W "$all_params" -- "$cur"))
39 _instances "$cur"
40 return
41 else
42 # param >= 2
43 # handle all instance-relevant params
44 for ((i = 0; i < ${numwords} + 1; i++ )); do
45 c=${COMP_WORDS[${i}]}
46 if [[ ${c} == "-c" || ${c} == "--config-file" ]]; then
47 config_file="${COMP_WORDS[${i} + 1]}"
48 elif [[ ${c} == "-s" || ${c} == "--spawn" ]]; then
49 spawn=1
50 elif [[ ${c} == "-q" || ${c} == "--no-output" ]]; then
51 no_output=1
52 fi
53 done
54 fi
55
56 case $prev in
57 "-c" | "--config-file")
58 COMPREPLY=($(compgen -f -- "$cur"))
59 return
60 ;;
61 "-d" | "--decrypt-value")
62 COMPREPLY=($(compgen -W "-m --multiple-values -P --master-password-prompt" -- "$cur"))
63 return
64 ;;
65 "-e" | "--encrypt-value")
66 COMPREPLY=($(compgen -W "-E --echo -m --multiple-values -P --master-password-prompt" -- "$cur"))
67 return
68 ;;
69 "-E" | "--echo")
70 COMPREPLY=($(compgen -W "-e --encrypt-value -m --multiple-values -P --master-password-prompt" -- "$cur"))
71 return
72 ;;
73 "-m" | "--multiple-values")
74 COMPREPLY=($(compgen -W "-d --decrypt-value -E -e --echo --encrypt-value -P --master-password-prompt" -- "$cur"))
75 return
76 ;;
77 "-P" | "--master-password-prompt")
78 COMPREPLY=($(compgen -W "-d --decrypt-value -E -e --echo --encrypt-value -m --multiple-values" -- "$cur"))
79 return
80 ;;
81 "-s" | "--spawn")
82 COMPREPLY=($(compgen -c -- "$cur"))
83 return
84 ;;
85 esac
86
87 # assume instance and handle only instance params
88 if [[ -z ${config_file} ]]; then
89 COMPREPLY+=($(compgen -W "-c --config-file" -- "$cur"))
90 fi
91
92 if [[ ${spawn} -ne 1 ]]; then
93 COMPREPLY+=($(compgen -W "-s --spawn" -- "$cur"))
94 fi
95
96 if [[ ${no_output} -ne 1 ]]; then
97 COMPREPLY+=($(compgen -W "--no-output -q" -- "$cur"))
98 fi
99
100 _instances "$cur" "$config_file"
101
102}
103
104
105complete -F _etoolkit etoolkit