Skip to content

Commit 09d2b7f

Browse files
author
Dinesh Kumar
committed
adding -n flag to autofill the password, and making vars local to functions
1 parent 81ae7b2 commit 09d2b7f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lazy-connect.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ USAGE:
5858
lazy-connect - Shell function to fuzzy search an IPSec VPN by name
5959
and connect to it automatically.
6060
61+
-n - Connect to VPN by autofilling password
6162
-i - Initialize lazy-connect.
6263
Stores the secret and VPN list to ~/.config/lazy-connect/
6364
-u - Update lazy-connect
@@ -67,7 +68,7 @@ EOF
6768
}
6869

6970
function _lazy_connect_get_totp() {
70-
secret_key=$1
71+
local secret_key=$1
7172
case $TOTP_MODE in
7273
oathtool)
7374
password=$(oathtool --totp --base32 $secret_key)
@@ -89,7 +90,7 @@ function _lazy_connect_get_totp() {
8990
}
9091

9192
function _lazy_connect() {
92-
vpn_name=$1
93+
local vpn_name=$1
9394
_lazy_connect_get_totp $2
9495

9596
if [ -z "$password" ]; then
@@ -105,7 +106,12 @@ function _lazy_connect() {
105106
esac
106107
fi
107108

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
109115

110116
osascript <<EOF
111117
on connectVpn(vpnName, password, autofill)
@@ -130,7 +136,7 @@ function _lazy_connect() {
130136
end tell
131137
end connectVpn
132138
133-
connectVpn("$vpn_name", "$password", "$LAZY_CONNECT_AUTOFILL")
139+
connectVpn("$vpn_name", "$password", "$_lazy_connect_auto_fill_pwd")
134140
EOF
135141
}
136142

@@ -144,7 +150,7 @@ function lazy-connect() {
144150
local OPTIND
145151
mkdir -p $_lazy_connect_config_dir
146152

147-
while getopts "iruh" opt; do
153+
while getopts "iruhn" opt; do
148154
case $opt in
149155
h)
150156
_lazy_connect_usage
@@ -163,6 +169,12 @@ function lazy-connect() {
163169
_lazy_connect_update
164170
return 0
165171
;;
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+
;;
166178
\?)
167179
echo "Invalid Option: -$OPTARG."
168180
_lazy_connect_usage

0 commit comments

Comments
 (0)