@@ -66,6 +66,7 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
6666
6767-i - Initialize lazy-connect. Stores the TOTP secret and VPN list.
6868-r - Refresh vpn list in ~/.config/lazy-connect .
69+ -y - Select the last selected VPN.
6970-n - Do not fill the password automatically. Instead copy the password to clipboard.
7071-h - Show this help.
7172EOF
@@ -191,11 +192,13 @@ function _lazy_connect_mojave() {
191192 tell group 1
192193 click button "Connect"
193194 end tell
195+ log "Connected"
194196 else if (value of attribute "AXValue" of static text 1 of r as string) is equal to connectedVpnName then
195197 log "Disconnecting from vpn " & vpnName
196198 tell group 1
197199 click button "Disconnect"
198200 end tell
201+ log "Disconnected"
199202 else
200203 log "Couldn't connect or disconnect the VPN, didn't find any exact match. The network found was: "
201204 log (value of attribute "AXValue" of static text 1 of r as string)
@@ -218,12 +221,24 @@ version_lt() {
218221 [ " $1 " = " $2 " ] && return 1 || version_lte $1 $2
219222}
220223
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+
221235function lazy-connect() {
222236 local OPTIND
223237 local autofill=" true"
238+ local choose_last=" false"
224239 mkdir -p $_lazy_connect_config_dir
225240
226- while getopts " irnh " opt; do
241+ while getopts " irnhy " opt; do
227242 case $opt in
228243 h)
229244 _lazy_connect_usage
@@ -242,6 +257,10 @@ function lazy-connect() {
242257 autofill=" false"
243258 shift $(( OPTIND - 1 ))
244259 ;;
260+ y)
261+ choose_last=" true"
262+ shift $(( OPTIND - 1 ))
263+ ;;
245264 \? )
246265 echo " Invalid Option: -$OPTARG ."
247266 _lazy_connect_usage
@@ -261,8 +280,13 @@ function lazy-connect() {
261280 return 1
262281 fi
263282
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
266290
267291 mac_version=$( sw_vers -productVersion)
268292 is_less_than_mojave=$( version_lt $mac_version 10.14 && echo " yes" || echo " no" )
@@ -271,7 +295,7 @@ function lazy-connect() {
271295 else
272296 [ -z " $vpn_name " ] || _lazy_connect_mojave " $vpn_name " " $secret " " $autofill "
273297 fi
274-
298+ echo -n $vpn_name > $_lazy_connect_config_dir /last_vpn
275299}
276300
277301lazy-connect " $@ "
0 commit comments