-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·117 lines (99 loc) · 3.2 KB
/
setup.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
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
#!/bin/bash
set -e # exit on first error
SCRIPT_DIR=$( cd $( dirname $(readlink -f ${BASH_SOURCE[0]}) ) && pwd )
BIN_DIR=$HOME/bin
BASHRC_PATH=${HOME}/.bashrc
setupBin(){
if [ ! -d $BIN_DIR ]; then
mkdir $BIN_DIR
fi
# find_all_folders
APP_NAME="find_all_folders"
if [ -f $BIN_DIR/$APP_NAME ]; then
echo "Found bin entry: $BIN_DIR/$APP_NAME"
else
ln -sfn $SCRIPT_DIR/tools/$APP_NAME $BIN_DIR/$APP_NAME
fi
# git_update_batch
APP_NAME="git_update_batch"
if [ -f $BIN_DIR/$APP_NAME ]; then
echo "Found bin entry: $BIN_DIR/$APP_NAME"
else
ln -sfn $SCRIPT_DIR/tools/$APP_NAME $BIN_DIR/$APP_NAME
fi
# find_git_repo
APP_NAME="find_git_repo"
if [ -f $BIN_DIR/$APP_NAME ]; then
echo "Found bin entry: $BIN_DIR/$APP_NAME"
else
ln -sfn $SCRIPT_DIR/tools/$APP_NAME $BIN_DIR/$APP_NAME
fi
# echo_with_color
APP_NAME="echo_with_color"
if [ -f $BIN_DIR/$APP_NAME ]; then
echo "Found bin entry: $BIN_DIR/$APP_NAME"
else
ln -sfn $SCRIPT_DIR/tools/$APP_NAME $BIN_DIR/$APP_NAME
fi
# gitcd
APP_NAME="gitcd"
if (grep -q "${APP_NAME}" ${BASHRC_PATH}); then
echo "Found bashrc entry: . ${SCRIPT_DIR}/tools/${APP_NAME}"
else
echo ". ${SCRIPT_DIR}/tools/${APP_NAME}" >> ${BASHRC_PATH}
fi
# update
source ${BASHRC_PATH}
echo "setup to $HOME/.bashrc successfully! (Except gitcd that requires to be installed to bashrc)"
}
setupBashrc() {
# find_all_folders
APP_NAME="find_all_folders"
if (grep -q "${APP_NAME}" ${BASHRC_PATH}); then
echo "Found bashrc entry: ${APP_NAME}=$SCRIPT_DIR/tools/${APP_NAME}"
else
echo "alias ${APP_NAME}='${SCRIPT_DIR}/tools/${APP_NAME}'" >> ${BASHRC_PATH}
fi
# git_update_batch
APP_NAME="git_update_batch"
if (grep -q "${APP_NAME}" ${BASHRC_PATH}); then
echo "Found bashrc entry: ${APP_NAME}=$SCRIPT_DIR/tools/${APP_NAME}"
else
echo "alias ${APP_NAME}='${SCRIPT_DIR}/tools/${APP_NAME}'" >> ${BASHRC_PATH}
fi
# find_git_repo
APP_NAME="find_git_repo"
if (grep -q "${APP_NAME}" ${BASHRC_PATH}); then
echo "Found bashrc entry: ${APP_NAME}=$SCRIPT_DIR/tools/${APP_NAME}"
else
echo "alias ${APP_NAME}='${SCRIPT_DIR}/tools/${APP_NAME}'" >> ${BASHRC_PATH}
fi
# echo_with_color
APP_NAME="echo_with_color"
if (grep -q "${APP_NAME}" ${BASHRC_PATH}); then
echo "Found bashrc entry: ${APP_NAME}=$SCRIPT_DIR/tools/${APP_NAME}"
else
echo "alias ${APP_NAME}='${SCRIPT_DIR}/tools/${APP_NAME}'" >> ${BASHRC_PATH}
fi
# gitcd
APP_NAME="gitcd"
if (grep -q "${APP_NAME}" ${BASHRC_PATH}); then
echo "Found bashrc entry: . ${SCRIPT_DIR}/tools/${APP_NAME}"
else
echo ". ${SCRIPT_DIR}/tools/${APP_NAME}" >> ${BASHRC_PATH}
fi
# update
source ${BASHRC_PATH}
echo "setup to $HOME/.bashrc successfully!"
}
setup() {
if [ $# = 0 ]; then
setupBin
fi
case $1 in
"bin" ) setupBin;;
"bashrc" ) setupBashrc;;
?) echo "Support installation option: bin ($HOME/bin, default for no arg) or bashrc ($HOME/.bashrc)." && exit;;
esac
}
setup $@