-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump.sh
executable file
·105 lines (85 loc) · 1.86 KB
/
bump.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
#!/bin/bash
version="0.1.0"
author="Kevin Gimbel"
author_url="<http://kevingimbel.com>"
github_url="https://github.com/kevingimbel/bump"
github_issues="$github_url/issues"
program_name="$(basename "$0")"
do_commit=""
if [ -z "$_bump_default_git" ]; then
_bump_default_git="[BUMP]"
fi
# Print out version information
version() {
printf "%s\n" "Version $version" \
"by $author $author_url" \
"" \
"Report Issues on $github_issues"
exit
}
# Print out usage information
usage() {
printf "%s\n" \
"Usage: $program_name [options] Message" \
"Write a bump text to bump.txt" \
"" \
"Options:" \
echo "
-u,--usage & Show usage message
-h,--help & Show help
-v,--version & Show version and author info
-g, --git & add all changes to git and create commit message
" | column -s\& -t
echo ""
echo "Environment variables:"
echo "
_bump_default_git & \"$_bump_default_git\"
" | column -s\& -t
echo ""
echo "Report Issues on $github_issues"
exit
}
help() {
printf "%s\n" \
"Run $program_name 'message' to write a bump message to the bump.txt file" \
"in the current directory."
exit
}
write_bump() {
if [ "$1" == "" ]; then
echo "Empty text. See $program_name --usage"
exit
fi
if [ ! -f "./bump.txt" ]; then
echo "Creating bump.txt file"
touch "./bump.txt"
fi
bump_message="[$(date +%x)] $1"
echo "$bump_message" >> ./bump.txt && echo "Bump text written to bump.txt"
if [ ! -z "$do_commit" ]; then
git add . && git commit -m "$_bump_default_git $1"
fi
exit $?
}
# We assume message the last argument is the message.
# If it is not, it will be set below.
msg=${@:$#}
case "$1" in
'-u' | '--usage')
usage
;;
'-h' | '--help')
help
;;
'-v' | '--version')
version
;;
'-g' | '--git')
do_commit="true"
;;
'-m' | '--msg')
msg=$2
;;
esac
shift
write_bump "$msg"