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,12 @@ 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 " copying password clipboard $3 "
113
+ echo " $password " | pbcopy
114
+ fi
109
115
110
116
osascript << EOF
111
117
on connectVpn(vpnName, password, autofill)
@@ -130,7 +136,7 @@ function _lazy_connect() {
130
136
end tell
131
137
end connectVpn
132
138
133
- connectVpn("$vpn_name ", "$password ", "$LAZY_CONNECT_AUTOFILL ")
139
+ connectVpn("$vpn_name ", "$password ", "$_lazy_connect_auto_fill_pwd ")
134
140
EOF
135
141
}
136
142
@@ -144,7 +150,7 @@ function lazy-connect() {
144
150
local OPTIND
145
151
mkdir -p $_lazy_connect_config_dir
146
152
147
- while getopts " iruh " opt; do
153
+ while getopts " iruhn " opt; do
148
154
case $opt in
149
155
h)
150
156
_lazy_connect_usage
@@ -163,6 +169,12 @@ function lazy-connect() {
163
169
_lazy_connect_update
164
170
return 0
165
171
;;
172
+ n)
173
+ local _secret=$( cat $_lazy_connect_config_dir /secret)
174
+ local _vpn_name=$( cat $_lazy_connect_config_dir /vpns | fzf --height=10 --ansi --reverse --select-1)
175
+ _lazy_connect " $_vpn_name " " $_secret " true
176
+ return 0
177
+ ;;
166
178
\? )
167
179
echo " Invalid Option: -$OPTARG ."
168
180
_lazy_connect_usage
0 commit comments