Skip to content

Commit 1fd31ea

Browse files
author
Dinesh Kumar
committed
Disable update prompt with env, refresh vpn list without updating secret
1 parent 7b236da commit 1fd31ea

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
3737
3838
-i - Initialize lazy-connect.
3939
Stores the secret and VPN list to ~/.config/lazy-connect/
40+
-r - refresh vpn list in ~/.config/lazy-connect
4041
-h - Show this help
4142
```
4243

lazy-connect.sh

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
#! /bin/bash
1+
#!/bin/bash
2+
3+
config_dir=~/.config/lazy-connect
4+
lazy_connect_dir=~/.lazy-connect
25

36
function _lazy_connect_init() {
4-
config_dir=~/.config/lazy-connect
57
echo -n "Secret Key: "
68
read -s secret_key
79
echo "**********"
810
echo $secret_key > $config_dir/secret
11+
_lazy_connect_vpn_refresh
12+
}
913

10-
osascript <<EOF |
14+
function _lazy_connect_vpn_refresh() {
15+
echo "refreshing vpn..."
16+
vpnNames=$(osascript <<EOF
1117
tell application "System Events"
1218
tell process "SystemUIServer"
1319
set vpnMenu to (menu bar item 1 of menu bar 1 where description is "VPN")
@@ -27,10 +33,12 @@ function _lazy_connect_init() {
2733
end tell
2834
end tell
2935
EOF
30-
tr , '\n' | sed 's/ Connect/Connect/g' > $config_dir/vpns
31-
32-
echo "VPN List:"
33-
cat $config_dir/vpns | nl
36+
)
37+
cp $config_dir/vpns ${TMPDIR}lc_vpns
38+
updated_vpns=$(echo $vpnNames | sed -e "s/Connect //g; s/Disconnect //g;" | tr , "\n" | xargs -I{} echo {})
39+
echo $updated_vpns > $config_dir/vpns
40+
echo "Updated VPN List:"
41+
diff $config_dir/vpns ${TMPDIR}lc_vpns
3442
}
3543

3644
function _lazy_connect_usage() {
@@ -44,6 +52,7 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
4452
-i - Initialize lazy-connect.
4553
Stores the secret and VPN list to ~/.config/lazy-connect/
4654
-u - Update lazy-connect
55+
-r - Refresh vpn list in ~/.config/lazy-connect
4756
-h - Show this help
4857
EOF
4958
}
@@ -78,18 +87,16 @@ EOF
7887
}
7988

8089
function _lazy_connect_update() {
81-
lazy_connect_dir=~/.lazy-connect
8290
git -C $lazy_connect_dir pull origin master
8391
echo -e "\n\nRun the below command or restart your shell."
8492
echo "$ source $lazy_connect_dir/lazy-connect.sh"
8593
}
8694

8795
function lazy-connect() {
8896
local OPTIND
89-
config_dir=~/.config/lazy-connect
9097
mkdir -p $config_dir
9198

92-
while getopts "ihu" opt; do
99+
while getopts "iruh" opt; do
93100
case $opt in
94101
h)
95102
_lazy_connect_usage
@@ -99,6 +106,10 @@ function lazy-connect() {
99106
_lazy_connect_init
100107
return 0
101108
;;
109+
r)
110+
_lazy_connect_vpn_refresh
111+
return 0
112+
;;
102113
u)
103114
_lazy_connect_update
104115
return 0
@@ -120,4 +131,4 @@ function lazy-connect() {
120131
vpn_name=$(cat $config_dir/vpns \
121132
| fzf --height=10 --ansi --reverse)
122133
[ -z "$vpn_name" ] || _lazy_connect "$vpn_name" "$secret"
123-
}
134+
}

0 commit comments

Comments
 (0)