-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
66 lines (52 loc) · 1.35 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
#!/bin/sh
set -e
_green() {
printf '\033[1;31;32m%b\033[0m\n' "$1"
}
_red() {
printf '\033[1;31;40m%b\033[0m\n' "$1"
}
_exists() {
cmd="$1"
if [ -z "$cmd" ]; then
_red "Usage: _exists cmd"
return 1
fi
if eval type type >/dev/null 2>&1; then
eval type "$cmd" >/dev/null 2>&1
elif command >/dev/null 2>&1; then
command -v "$cmd" >/dev/null 2>&1
else
which "$cmd" >/dev/null 2>&1
fi
return "$?"
}
main() {
if [ "$(uname -s)" != "Darwin" ]; then
_red "Unsupported operating system, Darwin?";
return 1;
fi
if [ ! -d ".git" ]; then
_red "Dir .git not find, Please git init first?";
return 1;
fi
if [ -f .git/hooks/pre-commit ]; then
rm .git/hooks/pre-commit;
fi
if [ -f .git/hooks/commit-msg ]; then
rm .git/hooks/commit-msg;
fi
# curl https://raw.githubusercontent.com/li-zeyuan/golang_git_hook/master/commit-msg.sh -o .git/hooks/commit-msg
curl https://raw.githubusercontent.com/li-zeyuan/golang_git_hook/master/pre-commit.sh -o .git/hooks/pre-commit
# chmod +x .git/hooks/commit-msg
chmod +x .git/hooks/pre-commit
# 安装全局git_template
if [ -d ~/.git_template ]; then
rm -r ~/.git_template
fi
mkdir -p ~/.git_template/hooks
git config --global init.templatedir '~/.git_template'
cp .git/hooks/pre-commit ~/.git_template/hooks
_green "Install Success!"
}
main "$@"