-
Notifications
You must be signed in to change notification settings - Fork 0
/
amend
executable file
·85 lines (63 loc) · 1.94 KB
/
amend
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
#!/bin/bash
REPO_TYPE=$(get-repo-type)
#Black 0;30 Dark Gray 1;30
#Red 0;31 Light Red 1;31
#Green 0;32 Light Green 1;32
#Brown/Orange 0;33 Yellow 1;33
#Blue 0;34 Light Blue 1;34
#Purple 0;35 Light Purple 1;35
#Cyan 0;36 Light Cyan 1;36
#Light Gray 0;37 White 1;37
RED_TEXT='\033[0;31m'
LIGHT_GRAY_TEXT='\033[0;37m'
YELLOW_TEXT='\033[1;33m'
ORANGE_TEXT='\033[0;33m'
NO_COLOR='\033[0m' # No Color
#printf "I ${RED}love${NO_COLOR} Stack Overflow\n"
function ask_continue { action_name=$1
if [[ -z "${action_name}" ]]; then
action_name="continue"
fi
# -s do not echo input coming from a terminal
# -p prompt output the string PROMPT without a trailing newline before
# attempting to read
# -r do not allow backslashes to escape any characters
# -n nchars return after reading NCHARS characters rather than waiting
# for a newline,
read -n 1 -r -p "Press \"y\" to ${action_name}: " input
# new line but with stderr, escaping capture output
echo >&2
if [ "$input" != "Y" ] && [ "$input" != "y" ]; then
exit
fi
echo 1
}
function header { header_text=$@;
echo -e "\n\n${LIGHT_GRAY_TEXT}# ${header_text}:${NO_COLOR}\n"
}
if [[ -z "$REPO_TYPE" ]]; then
echo "Repo not detected"
exit
fi
echo "$REPO_TYPE repo detected"
if [ "$REPO_TYPE" == "git" ]; then
header "Staged files"
printf "${ORANGE_TEXT}"
git diff --name-only --cached
printf "${NO_COLOR}"
header "Commit info"
git log -1 --abbrev-commit --pretty=format:'%C(dim white)#%h %d%C(reset)%n%C(green)%cr%C(reset)%C(blue) <%an>%C(reset)%'
echo
echo
COMMIT_TEXT=$(git log -1 --abbrev-commit --pretty=format:'%s')
CONTINUE=$(ask_continue "amend \"${COMMIT_TEXT}\"")
if [[ "$CONTINUE" != "1" ]]; then
exit;
fi
git commit --amend
exit
fi
if [ "$REPO_TYPE" == "hg" ]; then
hg commit --amend
exit
fi