@@ -66,6 +66,7 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
66
66
67
67
-i - Initialize lazy-connect. Stores the TOTP secret and VPN list.
68
68
-r - Refresh vpn list in ~/.config/lazy-connect .
69
+ -y - Select the last selected VPN.
69
70
-n - Do not fill the password automatically. Instead copy the password to clipboard.
70
71
-h - Show this help.
71
72
EOF
@@ -191,11 +192,13 @@ function _lazy_connect_mojave() {
191
192
tell group 1
192
193
click button "Connect"
193
194
end tell
195
+ log "Connected"
194
196
else if (value of attribute "AXValue" of static text 1 of r as string) is equal to connectedVpnName then
195
197
log "Disconnecting from vpn " & vpnName
196
198
tell group 1
197
199
click button "Disconnect"
198
200
end tell
201
+ log "Disconnected"
199
202
else
200
203
log "Couldn't connect or disconnect the VPN, didn't find any exact match. The network found was: "
201
204
log (value of attribute "AXValue" of static text 1 of r as string)
@@ -218,12 +221,24 @@ version_lt() {
218
221
[ " $1 " = " $2 " ] && return 1 || version_lte $1 $2
219
222
}
220
223
224
+ _get_last_selected_vpn () {
225
+ if [ -f $_lazy_connect_config_dir /last_vpn ]; then
226
+ last_vpn=$( cat $_lazy_connect_config_dir /last_vpn)
227
+ fi
228
+ if [ -z " $last_vpn " ]; then
229
+ echo " 0"
230
+ else
231
+ echo $last_vpn
232
+ fi
233
+ }
234
+
221
235
function lazy-connect() {
222
236
local OPTIND
223
237
local autofill=" true"
238
+ local choose_last=" false"
224
239
mkdir -p $_lazy_connect_config_dir
225
240
226
- while getopts " irnh " opt; do
241
+ while getopts " irnhy " opt; do
227
242
case $opt in
228
243
h)
229
244
_lazy_connect_usage
@@ -242,6 +257,10 @@ function lazy-connect() {
242
257
autofill=" false"
243
258
shift $(( OPTIND - 1 ))
244
259
;;
260
+ y)
261
+ choose_last=" true"
262
+ shift $(( OPTIND - 1 ))
263
+ ;;
245
264
\? )
246
265
echo " Invalid Option: -$OPTARG ."
247
266
_lazy_connect_usage
@@ -261,8 +280,13 @@ function lazy-connect() {
261
280
return 1
262
281
fi
263
282
264
- vpn_name=$( cat $_lazy_connect_config_dir /vpns |
265
- fzf --height=10 --ansi --reverse --query " $* " --select-1)
283
+ last_vpn=$( _get_last_selected_vpn)
284
+ if [ " true" == " $choose_last " -a " 0" != " $last_vpn " ]; then
285
+ vpn_name=$last_vpn
286
+ else
287
+ vpn_name=$( cat $_lazy_connect_config_dir /vpns |
288
+ fzf --height=10 --ansi --reverse --query " $* " --select-1)
289
+ fi
266
290
267
291
mac_version=$( sw_vers -productVersion)
268
292
is_less_than_mojave=$( version_lt $mac_version 10.14 && echo " yes" || echo " no" )
@@ -271,7 +295,7 @@ function lazy-connect() {
271
295
else
272
296
[ -z " $vpn_name " ] || _lazy_connect_mojave " $vpn_name " " $secret " " $autofill "
273
297
fi
274
-
298
+ echo -n $vpn_name > $_lazy_connect_config_dir /last_vpn
275
299
}
276
300
277
301
lazy-connect " $@ "
0 commit comments