forked from home-assistant/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhassio.bash
108 lines (102 loc) · 3.51 KB
/
hassio.bash
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# bash completion for hassio
_hassio()
{
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local -a cmds=(homeassistant supervisor host hassos hardware snapshots
addons help)
local -a opts
local i cmd action
# Find out command and action
for ((i=1; i < COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} != -* ]]; then
if [[ -z $cmd ]]; then
cmd=${COMP_WORDS[i]}
else
action=${COMP_WORDS[i]}
break
fi
fi
done
# Process top level commands and options
if [[ -z $cmd ]]; then
case $cur in
-*) opts=(--debug --help --version) ;;
*) opts=("${cmds[@]}") ;;
esac
COMPREPLY=($(compgen -W '${opts[@]}' -- "$cur"))
return
fi
# Handle common command options
case $prev in --options|-o|--filter|-f|--help) return ;; esac
# Process command options and actions
case $cmd in
homeassistant|ha)
case $cur in
-*) opts=(--rawjson --options --filter --help) ;;
*) [[ -z $action ]] &&
opts=(info logs check restart start stop update) ;;
esac
;;
supervisor|su)
case $cur in
-*) opts=(--rawjson --options --filter --help) ;;
*) [[ -z $action ]] && opts=(info logs reload update) ;;
esac
;;
host|ho)
case $cur in
-*) opts=(--rawjson --options --filter --help) ;;
*) [[ -z $action ]] && opts=(reboot shutdown) ;;
esac
;;
hassos|os)
case $cur in
-*) opts=(--rawjson --options --filter --help) ;;
*) [[ -z $action ]] && opts=(info update) ;;
esac
;;
hardware|hw)
case $cur in
-*) opts=(--rawjson --filter --help) ;;
*) [[ -z $action ]] && opts=(info audio) ;;
esac
;;
snapshots|sn)
if [[ $prev =~ ^--name|--password$ ]]; then
: # nothing
elif [[ $prev == --slug ]]; then
opts=($("$1" snapshots list \
| jq -r .data.snapshots[].slug 2>/dev/null))
elif [[ $prev =~ ^info|restore|remove$ ]]; then
opts=(--slug)
else
case $cur in
-*) opts=(--rawjson --options --filter --slug --name
--password --help) ;;
*) [[ -z $action ]] &&
opts=(list info reload new restore remove) ;;
esac
fi
;;
addons|ad)
if [[ $prev == --name ]]; then
opts=($("$1" addons list | \
jq -r .data.addons[].slug 2>/dev/null))
elif [[ $prev == info ]]; then
opts=(--name)
else
case $cur in
-*) opts=(--rawjson --options --filter --name --help) ;;
*) [[ -z $action ]] &&
opts=(list info logo changelog logs stats reload
start stop install uninstall update) ;;
esac
fi
;;
help|h)
[[ -z $action ]] && opts=("${cmds[@]}")
;;
esac
COMPREPLY=($(compgen -W '${opts[@]}' -- "$cur"))
} &&
complete -F _hassio hassio