-
Notifications
You must be signed in to change notification settings - Fork 135
/
basic.sh
executable file
·63 lines (55 loc) · 1.39 KB
/
basic.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
function brew_install() {
quiet=false
while getopts ":q" opt
do
case $opt in
q)
quiet=true
;;
? )
echo "Unrecognized argument"
echo "Usage: brew_install -q package_name"
return 1
;;
esac
done
shift "$((OPTIND-1))"
if [ -z "$1" ]; then
echo "Usage: brew_install [-q] package_name"
fi
if [[ ! -e /usr/local/bin/$1 ]]; then
if [ "$quiet" = false ]; then
echo "Installing $1"
fi
brew install $1
else
if [ "$quiet" = false ]; then
echo "You have installed $1"
fi
fi
}
# Usage: mv $1 to $1_backup
function backup_file() {
if [ $# != 1 ]; then
echo "Usage: backup_file pat_to_file"
fi
if [[ -e $1 ]]; then
mv $1 $1"_backup"
fi
}
# copy to path and create this path if not exist
function bs_cp() {
if [ $# != 2 ]; then
echo "Usage: bs_cp file destination"
fi
test -d "$2" || mkdir -p "$2" && cp "$1" "$2"
}
# fanqiang is not necessary in tt network
function not_tt_network() {
ssid=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}')
if [[ $ssid = *"Bytedance"* ]]; then
return 1
else
return 0
fi
}