| 1 |
# bash completion for secret-tool(1) -*- shell-script -*- |
| 2 |
|
| 3 |
_comp_cmd_secret_tool() |
| 4 |
{ |
| 5 |
local cur prev words cword was_split comp_args |
| 6 |
_comp_initialize -s -- "$@" || return |
| 7 |
|
| 8 |
[[ $was_split ]] && return |
| 9 |
|
| 10 |
local -i i |
| 11 |
local mode="" has_mode="" word |
| 12 |
for i in ${!words[*]}; do |
| 13 |
if [[ $i -gt 0 && ${words[i]} != -* ]]; then |
| 14 |
((i != cword)) && mode=${words[i]} has_mode=set |
| 15 |
break |
| 16 |
fi |
| 17 |
done |
| 18 |
if [[ ! $has_mode ]]; then |
| 19 |
# generate modes |
| 20 |
_comp_compgen_split -- "$("$1" nonexistent-mode 2>&1 | |
| 21 |
while read -r first second third rest; do |
| 22 |
if [[ $first == "${1##*/}" ]]; then |
| 23 |
printf "%s\n" "$second" |
| 24 |
elif [[ $first == usage: && $second == "${1##*/}" ]]; then |
| 25 |
printf "%s\n" "$third" |
| 26 |
fi |
| 27 |
done)" |
| 28 |
return |
| 29 |
fi |
| 30 |
|
| 31 |
case $mode in |
| 32 |
store) |
| 33 |
if [[ ${words[*]} != *\ --label[\ =]* ]]; then |
| 34 |
_comp_compgen -- -W "--label=" |
| 35 |
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace |
| 36 |
fi |
| 37 |
;; |
| 38 |
search) |
| 39 |
local -A opts=([--all]="" [--unlock]="") |
| 40 |
for word in "${words[@]:2}"; do |
| 41 |
[[ $word ]] && unset -v 'opts[$word]' |
| 42 |
done |
| 43 |
((${#opts[@]})) && |
| 44 |
_comp_compgen -- -W '"${!opts[@]}"' |
| 45 |
;; |
| 46 |
esac |
| 47 |
} && |
| 48 |
complete -F _comp_cmd_secret_tool secret-tool |
| 49 |
|
| 50 |
# ex: filetype=sh |