-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
82 lines (66 loc) · 1.54 KB
/
install.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
#!/bin/bash
echo "Your shell is: $SHELL"
home=`env | grep ^HOME= | cut -c 6-`
path=$home/scripts/git-shortcut
getEnvVarPath() {
if [[ "$(uname)" == "Darwin" ]]; then
# Mac OS X 操作系统
if [[ "$SHELL" == *"bin/zsh" ]]; then
echo "$home/.zshrc"
else
echo "$home/.bash_profile"
fi
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]]; then
# GNU/Linux操作系统
if [[ "$SHELL" == *"bin/zsh" ]]; then
echo "$home/.zshrc"
else
echo "$home/.bashrc"
fi
elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]]; then
# Windows NT操作系统
echo ''
fi
}
exsist() {
echo $(grep -w "git-shortcut" "$(getEnvVarPath)")
}
envExsist() {
grep 'g-completion' "$(getEnvVarPath)" >/dev/null 2>&1
}
writeEnv() {
echo "# git-shortcut start
export PATH=\$PATH:$path
alias g=g
if [ -f "$path/g-completion.bash" ]; then
. $path/g-completion.bash
fi
# git-shortcut end
" >> `getEnvVarPath`
}
# debug
# rm -rf ~/scripts
# release
sh ./build.sh
# create dir and copy files
rm -rf $path
mkdir -p $path
cp -r ./release/* $path
chmod +x $path/g
chmod +x $path/g-completion.bash
# set path
echo "Your env file: $(getEnvVarPath)"
if [ -z "$(exsist)" ]; then
echo 'Setting env...'
writeEnv
fi
# oh-my-zsh may throw errors in bash environment
source "$(getEnvVarPath)" >/dev/null 2>&1
if [ -f "$path/g" ] && envExsist; then
cat <<eof
Install success! Please Restart your terminal.
Run \`g\` to see help.
eof
else
echo 'Some errors occurred. Please check your command line environment.'
fi