Skip to content

Commit 27c8bb8

Browse files
Merge pull request #16 from arunvelsriram/toggle-autofill
Add flag to toggle autofilling the password
2 parents aeb8276 + 8e9e0ac commit 27c8bb8

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ sudo ln -s ~/.lazy-connect/lazy-connect /usr/local/bin/lazy-connect
3333
lazy-connect - Shell function to fuzzy search an IPSec VPN by name
3434
and connect to it automatically.
3535
36-
-i - Initialize lazy-connect.
37-
Stores the secret and VPN list to ~/.config/lazy-connect/
38-
-r - refresh vpn list in ~/.config/lazy-connect
39-
-h - Show this help
36+
-i - Initialize lazy-connect. Stores the TOTP secret and VPN list.
37+
-r - Refresh vpn list in ~/.config/lazy-connect .
38+
-n - Do not fill the password automatically. Instead copy the password to clipboard.
39+
-h - Show this help.
4040
```
4141

4242
### YubiKey Support

lazy-connect

+21-10
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ USAGE:
6464
lazy-connect - Shell function to fuzzy search an IPSec VPN by name
6565
and connect to it automatically.
6666
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.
7071
EOF
7172
}
7273

@@ -95,6 +96,7 @@ function _lazy_connect_get_totp() {
9596
function _lazy_connect() {
9697
vpn_name=$1
9798
_lazy_connect_get_totp $2
99+
local autofill=$3
98100

99101
if [ -z "$password" ]; then
100102
case $TOTP_MODE in
@@ -107,19 +109,23 @@ function _lazy_connect() {
107109
return 1
108110
;;
109111
esac
112+
elif [ "$autofill" == "false" ]; then
113+
echo -n "$password" | pbcopy
110114
fi
111115

112116
osascript <<EOF
113-
on connectVpn(vpnName, password)
117+
on connectVpn(vpnName, password, autofill)
114118
tell application "System Events"
115119
tell process "SystemUIServer"
116120
set vpnMenu to (menu bar item 1 of menu bar 1 where description is "VPN")
117121
tell vpnMenu to click
118122
try
119123
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
123129
on error errorStr
124130
if errorStr does not contain "Can’t get menu item" and errorStr does not contain vpnName then
125131
display dialog errorStr
@@ -129,15 +135,16 @@ function _lazy_connect() {
129135
end tell
130136
end connectVpn
131137
132-
connectVpn("$vpn_name", "$password")
138+
connectVpn("$vpn_name", "$password", "$autofill")
133139
EOF
134140
}
135141

136142
function lazy-connect() {
137143
local OPTIND
144+
local autofill="true"
138145
mkdir -p $_lazy_connect_config_dir
139146

140-
while getopts "iruh" opt; do
147+
while getopts "irnh" opt; do
141148
case $opt in
142149
h)
143150
_lazy_connect_usage
@@ -152,6 +159,10 @@ function lazy-connect() {
152159
_lazy_connect_vpn_refresh
153160
return 0
154161
;;
162+
n)
163+
autofill="false"
164+
shift $((OPTIND - 1))
165+
;;
155166
\?)
156167
echo "Invalid Option: -$OPTARG."
157168
_lazy_connect_usage
@@ -173,7 +184,7 @@ function lazy-connect() {
173184

174185
vpn_name=$(cat $_lazy_connect_config_dir/vpns |
175186
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"
177188
}
178189

179190
lazy-connect "$@"

0 commit comments

Comments
 (0)