-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfunctions.sh
75 lines (66 loc) · 1.58 KB
/
functions.sh
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
# get the relative path to current dir
function relpath() {
realpath --relative-to='.' $1
}
# virtual activate
function wk() {
if [[ $# == 0 ]]; then
dest="."
elif [ -d $1 ]; then
dest="$1"
else
printf "$1 is not a directory.\n"
return 1
fi
for actv in $(find $dest -depth -4 -type f -name activate)
do
if source $actv; then
echo -e "loading \033[35m$(dirname $(dirname $actv))\033[0m"
return
fi
done
echo 'Venv: Cannot find the activate file.'
}
# Proxy
function proxy() {
if [ -z "$ALL_PROXY" ]; then
if [[ $1 == "-s" ]]; then
export ALL_PROXY="socks5://127.0.0.1:1086"
else
export ALL_PROXY="http://127.0.0.1:1087"
fi
printf "Proxy on: $ALL_PROXY\n";
else
unset ALL_PROXY;
printf 'Proxy off\n';
fi
}
# fix brew include files
function fixBrewInclude() {
cd $BREWHOME/include
for dir in `find -L ../opt -name include`
do
for include in `ls $dir`
do
local SRC="$dir/$include"
if [ -d $SRC ] || [[ ${SRC##*.} == "h" ]]; then
local DST="./$include"
[[ -e $DST ]] || echo "ln -s $SRC $DST"
fi
done
done
cd -
}
# kill tmux's session
function tkill() {
if [[ "$1" == "-a" ]]; then
tmux kill-session -a
else
for target in $@
do
if tmux kill-session -t $target; then
echo "Tmux session $target has been killed"
fi
done
fi
}