@@ -64,9 +64,10 @@ USAGE:
64
64
lazy-connect - Shell function to fuzzy search an IPSec VPN by name
65
65
and connect to it automatically.
66
66
67
- -i - Initialize lazy-connect. Stores the TOTP secret and VPN list
68
- -r - Refresh vpn list in ~/.config/lazy-connect
69
- -h - Show this help
67
+ -i - Initialize lazy-connect. Stores the TOTP secret and VPN list.
68
+ -r - Refresh vpn list in ~/.config/lazy-connect .
69
+ -n - Do not fill the password automatically. Instead copy the password to clipboard.
70
+ -h - Show this help.
70
71
EOF
71
72
}
72
73
@@ -95,6 +96,7 @@ function _lazy_connect_get_totp() {
95
96
function _lazy_connect() {
96
97
vpn_name=$1
97
98
_lazy_connect_get_totp $2
99
+ local autofill=$3
98
100
99
101
if [ -z " $password " ]; then
100
102
case $TOTP_MODE in
@@ -107,19 +109,23 @@ function _lazy_connect() {
107
109
return 1
108
110
;;
109
111
esac
112
+ elif [ " $autofill " == " false" ]; then
113
+ echo -n " $password " | pbcopy
110
114
fi
111
115
112
116
osascript << EOF
113
- on connectVpn(vpnName, password)
117
+ on connectVpn(vpnName, password, autofill )
114
118
tell application "System Events"
115
119
tell process "SystemUIServer"
116
120
set vpnMenu to (menu bar item 1 of menu bar 1 where description is "VPN")
117
121
tell vpnMenu to click
118
122
try
119
123
click menu item vpnName of menu 1 of vpnMenu
120
- delay 2
121
- keystroke password
122
- keystroke return
124
+ if autofill is equal to "true" then
125
+ delay 2
126
+ keystroke password
127
+ keystroke return
128
+ end if
123
129
on error errorStr
124
130
if errorStr does not contain "Can’t get menu item" and errorStr does not contain vpnName then
125
131
display dialog errorStr
@@ -129,15 +135,16 @@ function _lazy_connect() {
129
135
end tell
130
136
end connectVpn
131
137
132
- connectVpn("$vpn_name ", "$password ")
138
+ connectVpn("$vpn_name ", "$password ", " $autofill " )
133
139
EOF
134
140
}
135
141
136
142
function lazy-connect() {
137
143
local OPTIND
144
+ local autofill=" true"
138
145
mkdir -p $_lazy_connect_config_dir
139
146
140
- while getopts " iruh " opt; do
147
+ while getopts " irnh " opt; do
141
148
case $opt in
142
149
h)
143
150
_lazy_connect_usage
@@ -152,6 +159,10 @@ function lazy-connect() {
152
159
_lazy_connect_vpn_refresh
153
160
return 0
154
161
;;
162
+ n)
163
+ autofill=" false"
164
+ shift $(( OPTIND - 1 ))
165
+ ;;
155
166
\? )
156
167
echo " Invalid Option: -$OPTARG ."
157
168
_lazy_connect_usage
@@ -173,7 +184,7 @@ function lazy-connect() {
173
184
174
185
vpn_name=$( cat $_lazy_connect_config_dir /vpns |
175
186
fzf --height=10 --ansi --reverse --query " $* " --select-1)
176
- [ -z " $vpn_name " ] || _lazy_connect " $vpn_name " " $secret "
187
+ [ -z " $vpn_name " ] || _lazy_connect " $vpn_name " " $secret " " $autofill "
177
188
}
178
189
179
190
lazy-connect " $@ "
0 commit comments