-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-cdd-aim
executable file
·83 lines (72 loc) · 1.54 KB
/
git-cdd-aim
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
#!/usr/bin/env sh
. cdd-shared
usage() {
echo "git cdd aim"
echo " "
echo "Setup a commit message."
echo " "
echo "options:"
echo "-m, --message <message>"
echo " commit message"
}
further_usage() {
if [ -n "$1" ]; then
echo "Commit started:"
echo "\"$1\""
echo "Next steps:"
echo " "
fi
echo " amend Change commit message prior to committing changes."
echo " fire Commit changes with the current message."
echo " forget Remove commit message."
}
cmd_aim() {
if [ -e "$CDD_COMMIT_MSG" ]; then
echo "A previous commit message exist."
echo " "
further_usage ""
echo " "
echo "Or manually delete $CDD_COMMIT_MSG"
exit 1
fi
if [ "$#" -lt 1 ]; then
open_editor; exit 0
fi
flag="$1"; shift
case $flag in
"-m"|"--message")
if [ -z "$1" ]; then
open_editor; exit 0
fi
write_message "$1"; exit 0
;;
*)
usage; exit 1
;;
esac
}
open_editor() {
touch "$CDD_COMMIT_MSG"
printf "\n\n# If applied, this commit will…" > "$CDD_COMMIT_MSG"
export editor
get_editor
"$editor" "$CDD_COMMIT_MSG"
if [ ! -s "$CDD_COMMIT_MSG" ]; then
rm "$CDD_COMMIT_MSG"
echo " "
echo "Please add a commit message to start with."
echo " "
exit 1
fi
unset editor
further_usage "$(grep "^[^#]" "$CDD_COMMIT_MSG")"
}
write_message() {
if [ "$#" -lt 1 ] || [ -z "$1" ]; then
cmd_aim "$@"; exit 0
fi
touch "$CDD_COMMIT_MSG"
echo "$1" > "$CDD_COMMIT_MSG"
further_usage "$1"
exit 0
}