-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-new.sh
68 lines (58 loc) · 1.41 KB
/
git-new.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
#!/usr/bin/env bash
#
# New git repository
# refer to https://github.com/tj/git-extras/blob/main/bin/git-setup
# see https://git-scm.com/docs/git-sh-setup
USAGE="\
[<options>] [<directory>]
options:
-m <msg> Use the given <msg> as the commit message
-h Show this help"
#SUBDIRECTORY_OK=
NONGIT_OK=Yes
. "$(git --exec-path)/git-sh-setup"
# global variable
COMMIT_MESSAGE='Initial commit'
if [ "$1" == "-m" ]; then
COMMIT_MESSAGE=$2
shift; shift
elif [ "$1" == "-h" ]; then
usage && exit 0
fi
gitdirexists() {
if [ -d ".git" ]; then
echo ".git directory already exists, aborting"
exit 1
fi
}
gitinit() {
git init
}
gittouch() {
for filename in "$@"; do
if [ ! -f "$filename" ]; then
touch "$filename" && git add "$filename"
fi
done
}
gitadd() {
git add .
}
gitcommit() {
git commit --allow-empty -m "$COMMIT_MESSAGE"
}
gitconfig() {
git config --global alias.gi '!f() { curl -sL https://www.toptal.com/developers/gitignore/api/$@ ;}; f'
git config --global alias.ga '!f() { curl -sL https://gitattributes.com/api/$@ ;}; f'
echo "Use 'git gi Go > .gitignore' to set gitignore file."
echo "Use 'git ga go,vim > .gitattributes' to set gitattributes file."
}
dir=$(test -z "$*" && echo "." || echo "$*")
mkdir -p "$dir" \
&& cd "$dir" \
&& gitdirexists \
&& gitinit \
&& gittouch .gitignore .gitattributes LICENSE README.md \
&& gitadd \
&& gitcommit \
&& gitconfig