1
- #! /bin/bash
1
+ #! /bin/bash
2
+
3
+ config_dir=~ /.config/lazy-connect
4
+ lazy_connect_dir=~ /.lazy-connect
2
5
3
6
function _lazy_connect_init() {
4
- config_dir=~ /.config/lazy-connect
5
7
echo -n " Secret Key: "
6
8
read -s secret_key
7
9
echo " **********"
8
10
echo $secret_key > $config_dir /secret
11
+ _lazy_connect_vpn_refresh
12
+ }
9
13
10
- osascript << EOF |
14
+ function _lazy_connect_vpn_refresh() {
15
+ echo " refreshing vpn..."
16
+ vpnNames=$( osascript << EOF
11
17
tell application "System Events"
12
18
tell process "SystemUIServer"
13
19
set vpnMenu to (menu bar item 1 of menu bar 1 where description is "VPN")
@@ -27,10 +33,12 @@ function _lazy_connect_init() {
27
33
end tell
28
34
end tell
29
35
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
34
42
}
35
43
36
44
function _lazy_connect_usage() {
@@ -44,6 +52,7 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
44
52
-i - Initialize lazy-connect.
45
53
Stores the secret and VPN list to ~/.config/lazy-connect/
46
54
-u - Update lazy-connect
55
+ -r - Refresh vpn list in ~/.config/lazy-connect
47
56
-h - Show this help
48
57
EOF
49
58
}
78
87
}
79
88
80
89
function _lazy_connect_update() {
81
- lazy_connect_dir=~ /.lazy-connect
82
90
git -C $lazy_connect_dir pull origin master
83
91
echo -e " \n\nRun the below command or restart your shell."
84
92
echo " $ source $lazy_connect_dir /lazy-connect.sh"
85
93
}
86
94
87
95
function lazy-connect() {
88
96
local OPTIND
89
- config_dir=~ /.config/lazy-connect
90
97
mkdir -p $config_dir
91
98
92
- while getopts " ihu " opt; do
99
+ while getopts " iruh " opt; do
93
100
case $opt in
94
101
h)
95
102
_lazy_connect_usage
@@ -99,6 +106,10 @@ function lazy-connect() {
99
106
_lazy_connect_init
100
107
return 0
101
108
;;
109
+ r)
110
+ _lazy_connect_vpn_refresh
111
+ return 0
112
+ ;;
102
113
u)
103
114
_lazy_connect_update
104
115
return 0
@@ -120,4 +131,4 @@ function lazy-connect() {
120
131
vpn_name=$( cat $config_dir /vpns \
121
132
| fzf --height=10 --ansi --reverse)
122
133
[ -z " $vpn_name " ] || _lazy_connect " $vpn_name " " $secret "
123
- }
134
+ }
0 commit comments