-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpressvpnctl
More file actions
224 lines (198 loc) · 5.84 KB
/
expressvpnctl
File metadata and controls
224 lines (198 loc) · 5.84 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env bash
# Bash completion for expressvpnctl.
_expressvpnctl_regions() {
local line
expressvpnctl get regions 2>/dev/null | while IFS= read -r line; do
[[ -n $line ]] && printf '%s\n' "$line"
done
}
_expressvpnctl_complete_regions() {
local cur=$1
shift
local match_cur=$cur
local quoted=0
local line
local candidate
local escaped
local -a candidates=("$@")
local -a matches=()
if [[ $match_cur == \'* ]]; then
quoted=1
match_cur=${match_cur:1}
elif [[ $match_cur == \"* ]]; then
quoted=1
match_cur=${match_cur:1}
fi
# Users may pre-escape shell metacharacters (e.g. foo-\(bar\)); match against raw values.
match_cur=${match_cur//\\}
while IFS= read -r line; do
[[ -n $line ]] && candidates+=("$line")
done < <(_expressvpnctl_regions)
for candidate in "${candidates[@]}"; do
[[ $candidate == "$match_cur"* ]] && matches+=("$candidate")
done
for candidate in "${matches[@]}"; do
if ((quoted)); then
COMPREPLY+=("$candidate")
else
printf -v escaped '%q' "$candidate"
COMPREPLY+=("$escaped")
fi
done
}
_expressvpnctl() {
local cur prev words cword
_init_completion -s || return
local options="--timeout -t --debug -d --help -h --version -v"
local commands="background connect dedicatedip disconnect get install-chrome-extension install-firefox-extension login logout monitor resetsettings set speedtest status"
local cmd=""
local cmd_index=-1
local i
if [[ $prev == "--timeout" || $prev == "-t" ]]; then
COMPREPLY=( $(compgen -W "5 10 15 30 60 120" -- "$cur") )
return
fi
for ((i=1; i<${#words[@]}; i++)); do
case "${words[i]}" in
--timeout|-t)
((i++))
continue
;;
--timeout=*)
continue
;;
--debug|-d|--help|-h|--version|-v)
continue
;;
--)
if (( i + 1 < ${#words[@]} )); then
cmd=${words[i+1]}
cmd_index=$((i + 1))
fi
break
;;
-*)
continue
;;
*)
cmd=${words[i]}
cmd_index=$i
break
;;
esac
done
if [[ $cur == -* ]]; then
COMPREPLY=( $(compgen -W "$options" -- "$cur") )
return
fi
if [[ -z $cmd ]]; then
COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
return
fi
if (( cword == cmd_index )); then
COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
return
fi
case "$cmd" in
background)
if (( cword == cmd_index + 1 )); then
COMPREPLY=( $(compgen -W "enable disable" -- "$cur") )
fi
;;
connect)
if (( cword == cmd_index + 1 )); then
_expressvpnctl_complete_regions "$cur" "smart"
fi
;;
dedicatedip)
if (( cword == cmd_index + 1 )); then
COMPREPLY=( $(compgen -W "status unlock ip" -- "$cur") )
fi
;;
get|monitor)
if (( cword == cmd_index + 1 )); then
local types="allowlan autoconnect blockAds blockAdult blockAll blockMalicious blockTrackers connectionstate debuglogging dnsconfigured networklock protocol pubip region regions smart split-app splittunnel vpnip"
COMPREPLY=( $(compgen -W "$types" -- "$cur") )
fi
;;
login)
if (( cword == cmd_index + 1 )); then
_filedir
fi
;;
set)
if (( cword == cmd_index + 1 )); then
local types="allowlan autoconnect blockAds blockAdult blockAll blockMalicious blockTrackers debuglogging networklock protocol region split-app splittunnel"
COMPREPLY=( $(compgen -W "$types" -- "$cur") )
return
fi
if (( cword == cmd_index + 2 )); then
local type=${words[cmd_index+1]}
case "$type" in
allowlan|autoconnect|blockAds|blockAdult|blockAll|blockMalicious|blockTrackers|debuglogging|networklock|splittunnel)
COMPREPLY=( $(compgen -W "true false" -- "$cur") )
;;
protocol)
COMPREPLY=( $(compgen -W "auto lightwayudp lightwaytcp openvpnudp openvpntcp wireguard" -- "$cur") )
;;
region)
_expressvpnctl_complete_regions "$cur" "smart"
;;
split-app)
if [[ $cur == *:* ]]; then
local prefix=${cur%%:*}
local path=${cur#*:}
local matches=()
local file
while IFS= read -r file; do
matches+=("${prefix}:$file")
done < <(compgen -f -- "$path")
COMPREPLY=("${matches[@]}")
else
COMPREPLY=( $(compgen -W "bypass: vpn: remove:" -- "$cur") )
fi
;;
esac
fi
;;
speedtest)
local -a speedtest_args=()
local arg
for ((i=cmd_index + 1; i<cword; i++)); do
speedtest_args+=("${words[i]}")
done
if ((${#speedtest_args[@]} == 0)); then
COMPREPLY=( $(compgen -W "json automatic manual" -- "$cur") )
_expressvpnctl_complete_regions "$cur"
return
fi
if ((${#speedtest_args[@]} == 1)); then
arg=${speedtest_args[0]}
case "$arg" in
json)
COMPREPLY=( $(compgen -W "automatic manual" -- "$cur") )
_expressvpnctl_complete_regions "$cur"
;;
manual)
_expressvpnctl_complete_regions "$cur"
;;
*)
;;
esac
return
fi
if ((${#speedtest_args[@]} == 2)); then
if [[ ${speedtest_args[0]} == "json" && ${speedtest_args[1]} != "automatic" && ${speedtest_args[1]} != "manual" ]]; then
COMPREPLY=( $(compgen -W "automatic manual" -- "$cur") )
return
fi
if [[ ${speedtest_args[0]} == "json" && ${speedtest_args[1]} == "manual" ]]; then
_expressvpnctl_complete_regions "$cur"
return
fi
return
fi
;;
esac
}
complete -F _expressvpnctl expressvpnctl