58
58
lazy-connect - Shell function to fuzzy search an IPSec VPN by name
59
59
and connect to it automatically.
60
60
61
+ -n - Connect to VPN by autofilling password
61
62
-i - Initialize lazy-connect.
62
63
Stores the secret and VPN list to ~/.config/lazy-connect/
63
64
-u - Update lazy-connect
67
68
}
68
69
69
70
function _lazy_connect_get_totp() {
70
- secret_key=$1
71
+ local secret_key=$1
71
72
case $TOTP_MODE in
72
73
oathtool)
73
74
password=$( oathtool --totp --base32 $secret_key )
@@ -89,7 +90,7 @@ function _lazy_connect_get_totp() {
89
90
}
90
91
91
92
function _lazy_connect() {
92
- vpn_name=$1
93
+ local vpn_name=$1
93
94
_lazy_connect_get_totp $2
94
95
95
96
if [ -z " $password " ]; then
@@ -105,7 +106,11 @@ function _lazy_connect() {
105
106
esac
106
107
fi
107
108
108
- [[ " $LAZY_CONNECT_AUTOFILL " -eq " true" ]] && echo -n " $password " | pbcopy
109
+ if [ " $3 " = " true" ]; then
110
+ local _lazy_connect_auto_fill_pwd=" true"
111
+ else
112
+ echo " $password " | pbcopy
113
+ fi
109
114
110
115
osascript << EOF
111
116
on connectVpn(vpnName, password, autofill)
@@ -130,7 +135,7 @@ function _lazy_connect() {
130
135
end tell
131
136
end connectVpn
132
137
133
- connectVpn("$vpn_name ", "$password ", "$LAZY_CONNECT_AUTOFILL ")
138
+ connectVpn("$vpn_name ", "$password ", "$_lazy_connect_auto_fill_pwd ")
134
139
EOF
135
140
}
136
141
@@ -144,7 +149,7 @@ function lazy-connect() {
144
149
local OPTIND
145
150
mkdir -p $_lazy_connect_config_dir
146
151
147
- while getopts " iruh " opt; do
152
+ while getopts " iruhn " opt; do
148
153
case $opt in
149
154
h)
150
155
_lazy_connect_usage
@@ -163,6 +168,12 @@ function lazy-connect() {
163
168
_lazy_connect_update
164
169
return 0
165
170
;;
171
+ n)
172
+ local _secret=$( cat $_lazy_connect_config_dir /secret)
173
+ local _vpn_name=$( cat $_lazy_connect_config_dir /vpns | fzf --height=10 --ansi --reverse --select-1)
174
+ _lazy_connect " $_vpn_name " " $_secret " true
175
+ return 0
176
+ ;;
166
177
\? )
167
178
echo " Invalid Option: -$OPTARG ."
168
179
_lazy_connect_usage
0 commit comments