This repository has been archived by the owner on Dec 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnhctl-bash-completion.bash
122 lines (115 loc) · 4.09 KB
/
nhctl-bash-completion.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# based on the apt and apt-get completion scripts
_nhctl()
{
local cur prev words cword
_init_completion -n = || return
COMPREPLY=()
local special i
for (( i=0; i < ${#words[@]}-1; i++ )); do
if [[ ${words[i]} == @(restart|update|status|add-user|del-user|disable-user|enable-user|notify-reboot|list-services) ]]; then
special=${words[i]}
break
fi
done
if [[ "$cur" == -* ]]; then
case $special in
restart)
COMPREPLY=( $( compgen -W '-f --force' -- "$cur" ) )
;;
add-user)
COMPREPLY=( $( compgen -W '-u -k -d -i
--username --ssh-public-key --discord-name --discord-id' -- "$cur" ) )
;;
del-user)
COMPREPLY=( $( compgen -W '-u --username --remove-home' -- "$cur" ) )
;;
disable-user)
COMPREPLY=( $( compgen -W '-u --username' -- "$cur" ) )
;;
enable-user)
COMPREPLY=( $( compgen -W '-u --username' -- "$cur" ) )
;;
notify-reboot)
COMPREPLY=( $( compgen -W '-l -m --list --message' -- "$cur" ) )
;;
*)
COMPREPLY=()
;;
esac
return
fi
if [[ -n $special ]]; then
case $special in
restart|update|status)
COMPREPLY=( $( compgen -W '$(nhctl -q list-services)' -- "$cur" ) )
;;
add-user)
case $prev in
-k|--ssh-public-key)
_filedir pub
return
;;
-u|-d|-i|--username|--discord-name|--discord-id)
COMPREPLY=()
return
;;
*)
COMPREPLY=( $( compgen -W '-u -k -d -i
--username --ssh-public-key --discord-name --discord-id' -- "$cur" ) )
;;
esac
;;
del-user)
case $prev in
-u|--username)
COMPREPLY=( $( compgen -W "$(ls /opt/nintendohomebrew/etc/nhd/discord-id)" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W '-u --username --remove-home' -- "$cur") )
;;
esac
;;
disable-user)
case $prev in
-u|--username)
COMPREPLY=( $( compgen -W "$(ls /opt/nintendohomebrew/etc/nhd/discord-id)" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W '-u --username' -- "$cur") )
;;
esac
;;
enable-user)
case $prev in
-u|--username)
COMPREPLY=( $( compgen -W "$(ls /opt/nintendohomebrew/etc/nhd/discord-id)" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W '-u --username' -- "$cur") )
;;
esac
;;
notify-reboot)
case $prev in
-m|--message)
COMPREPLY=( $( compgen -W "$(ls /opt/nintendo/etc/nhd/notify-reboot)" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W '-l -m --list --message' -- "$cur" ) )
;;
esac
;;
*)
COMPREPLY=()
;;
esac
return
fi
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-h -q -v --help --quiet --verbose' -- "$cur" ) )
else
COMPREPLY=( $( compgen -W 'restart update status add-user del-user disable-user enable-user notify-reboot list-services' -- "$cur" ) )
fi
} &&
complete -F _nhctl nhctl