-
Notifications
You must be signed in to change notification settings - Fork 2
/
func.zsh
55 lines (47 loc) · 3.02 KB
/
func.zsh
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
#######################
## defined function ##
#######################
function wip() {
/sbin/ifconfig en0|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d 'addr:'
}
function aip() {
/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d 'addr:'
}
function ip_addr() {
if [ -n "$(wip)" ]; then
wip
else
aip
fi
}
# g_os = 'unknown'
function os(){
if [ "$(uname)"=="Darwin" ]; then
g_os="Mac"
elif [ "$(expr substr $(uname -s) 1 5)"=="Linux" ]; then
g_os="Linux"
elif [ "$(expr substr $(uname -s) 1 10)"=="MINGW32_NT" ]; then
g_os="Win"
fi
}
function hostname(){
if [ "$(uname)"=="Darwin" ]; then
scutil --get ComputerName
else
echo "Not Support!"
#exit
fi
}
function realpath ()
{
f=$@;
if [ -d "$f" ]; then
base="";
dir="$f";
else
base="/$(basename "$f")";
dir=$(dirname "$f");
fi;
dir=$(cd "$dir" && /bin/pwd);
echo "$dir$base"
}