-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdeactivate
37 lines (31 loc) · 949 Bytes
/
deactivate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# The shebang is just a hint for editors.
function _restore_var() {
if [ -n "$1" ]; then
local VAR="_socks_cli_saved_$1"
if _defined "${VAR}"; then
echo "export $1=\"\${${VAR}}\"; unset ${VAR}"
else
# Check if the variable really exists, for security.
# e.g. to avoid code injection or something else.
_defined "$1" && echo "unset $1"
fi
fi
}
if [ "${_socks_cli}" = "1" ]; then
# Execute deactivation hooks
for support in "${_socks_cli_supports[@]}"; do
_hook="socks_cli_deactivate_$support"
_is_function_exist "$_hook" && "$_hook"
done
# Restore variables
for var in "${_socks_cli_saved_vars[@]}"; do
eval "$(_restore_var $var)"
# Rehash if PATH changed
if [ "$var" = "PATH" ]; then
hash -r
fi
done
unset _socks_cli_shadow_inited
unset _socks_cli
fi