-
Notifications
You must be signed in to change notification settings - Fork 7
/
.bash_profile__utility
142 lines (121 loc) · 3.41 KB
/
.bash_profile__utility
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
###############
### UTILITY ###
###############
# set the console title (OSX Terminal and Windows GitBash only)
function console__set_title {
title="$1"
trap 'echo -ne "\033]0;"$title"\007"' DEBUG
}
# check if a program is installed. (true or false returns)
function cli__is_installed {
local is_installed=true
type $1 >/dev/null 2>&1 || { local is_installed=false; }
echo "$is_installed"
}
# proxy - check
function proxy__check {
if [[ -z "$HTTP_PROXY" && -z "$HTTPS_PROXY" ]]; then
echo false
else
echo "$HTTP_PROXY $HTTPS_PROXY"
fi
}
# proxy - set
function proxy__set {
export HTTP_PROXY=$1
export HTTPS_PROXY=$HTTP_PROXY
if [[ -n $2 ]]; then
export HTTPS_PROXY=$2
fi
export http_proxy=$HTTP_PROXY
export https_proxy=$HTTPS_PROXY
export RSYNC_PROXY=$HTTP_PROXY
if [[ $(cli__is_installed npm) == true ]]; then
export npm_config_proxy=$HTTP_PROXY
export npm_config_https_proxy=$HTTPS_PROXY
#npm config set proxy $HTTP_PROXY
#npm config set https-proxy $HTTPS_PROXY
fi
if [[ $(cli__is_installed git) == true ]]; then
git config --global http.proxy $HTTP_PROXY
git config --global https.proxy $HTTPS_PROXY
fi
#if [[ $(cli__is_installed apm) == true ]]; then
# apm config set http-proxy $HTTP_PROXY
# apm config set https-proxy $HTTPS_PROXY
#fi
}
# proxy - unset
function proxy__unset {
unset HTTP_PROXY
unset HTTPS_PROXY
unset http_proxy
unset https_proxy
unset RSYNC_PROXY
if [[ $(cli__is_installed npm) == true ]]; then
unset npm_config_proxy
unset npm_config_https_proxy
#npm config delete proxy
#npm config delete https-proxy
fi
if [[ $(cli__is_installed git) == true ]]; then
git config --global --unset http.proxy
git config --global --unset https.proxy
fi
#if [[ $(cli__is_installed apm) == true ]]; then
# apm config delete http-proxy
# apm config delete https-proxy
#fi
}
# get ip address
function network__get_ip {
case "$(uname -s)" in
Darwin)
echo $(ifconfig | grep 'inet.*cast' | cut -d' ' -f2)
;;
Linux)
echo $(ifconfig | grep 'inet.*cast' | cut -d':' -f2 | cut -d' ' -f1)
;;
MINGW*)
echo $(ipconfig | grep "IPv4 Address" | cut -d':' -f2 | sed 's/^ *//;s/ *$//')
;;
*)
echo "unknown"
;;
esac
}
# get gateway address
function network__get_gateway {
case "$(uname -s)" in
Darwin)
echo $(netstat -nr | grep "default" | head -n1 | awk '{print $2}')
;;
Linux)
echo $(netstat -nr | grep "0.0.0.0" | head -n1 | awk '{print $2}')
;;
MINGW*)
echo $(netstat -nr | grep "0.0.0.0" | head -n1 | awk '{print $3}')
;;
*)
echo "unknown"
;;
esac
}
# get broadcast address
function network__get_broadcast {
case "$(uname -s)" in
Darwin)
echo $(ifconfig | grep 'inet.*cast' | cut -d' ' -f6)
;;
Linux)
echo $(ifconfig | grep 'inet.*cast' | cut -d':' -f3 | cut -d' ' -f1)
;;
*)
echo "unknown"
;;
esac
}
# set JAVA_HOME ( ex:. java__use_jdk 1.8 )
function java__use_jdk {
export JAVA_HOME=$(/usr/libexec/java_home -v $@)
}