forked from JackSlateur/backurne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_completion
62 lines (57 loc) · 1.48 KB
/
bash_completion
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
_backurne(){
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
subcmd="${COMP_WORDS[1]}"
if [ "$prev" == "backurne" ]
then
opts="backup check check-snap list-mapped ls map unmap"
COMPREPLY=($(compgen -W "$opts" -- ${cur}))
return 0
fi
if [ "$subcmd" == "unmap" ]
then
if [ "$prev" == "unmap" ]
then
opts="$(backurne list-mapped --json | jq -r .[].parent_image)"
else
prev=$(echo $prev | tr -d '\\')
opts="$(backurne list-mapped --json | jq -r ".[] | select(.parent_image | contains(\"$prev\")) | .parent_snap")"
fi
COMPREPLY=($(compgen -W "$opts" -- ${cur}))
return 0
fi
if [ "$subcmd" == "ls" ]
then
if [ "$cur" == "" ]
then
opts="$(backurne ls --json | jq -r .[].uuid)"
COMPREPLY=($(compgen -W "$opts" -- ${cur}))
else
opts="$(backurne ls --json | jq -r .[].uuid | grep $cur)"
COMPREPLY=($opts $(compgen -W "$opts" -- ${cur}))
fi
return 0
fi
if [ "$subcmd" == "map" ]
then
if [ "$prev" == "map" ]
then
if [ "$cur" == "" ]
then
opts="$(backurne ls --json | jq -r .[].uuid)"
COMPREPLY=($(compgen -W "$opts" -- ${cur}))
else
opts="$(backurne ls --json | jq -r .[].uuid | grep $cur)"
COMPREPLY=($opts $(compgen -W "$opts" -- ${cur}))
fi
else
prev=$(echo $prev | tr -d '\\')
opts="$(backurne ls --json $prev | jq -r .[].uuid)"
COMPREPLY=($(compgen -W "$opts" -- ${cur}))
fi
return 0
fi
}
command -v jq && complete -o filenames -F _backurne backurne