-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-lc
executable file
·69 lines (61 loc) · 1.61 KB
/
git-lc
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
#!/bin/zsh
print_usage(){
echo 'Usage: git-lc [-flags] "commit message"\n' 2>&1
echo ' git-lc - add all files and commit locally with a meassage\n'
echo ' "commit message" - required, the message assigned to the commit'
echo '\n [-flags]:'
echo ' -h prints out this message'
echo ' -s commit only staged files'
echo ' -d debug mode ON'
}
# TODO #6 add the ability to just `git commit`, aka for the editor to open a commit dialog instad of using the `-m` flag
isFlagged='false'
onlyStaged='false'
debug='false'
while getopts ':hsd' flag; do
case "${flag}" in
h)
print_usage
return 0
;;
s)
isFlagged='true'
onlyStaged='true'
;;
d)
isFlagged='true'
debug='true'
;;
?)
printf "Invalid option: -${OPTARG}.\n\n" >&2
print_usage
return 1
;;
esac
done
if [[ $isFlagged == 'true' ]]; then
shift
fi
if [[ $onlyStaged == 'false' ]]; then
git add . -v
fi
if [[ ${#} -lt 1 ]]; then
echo 'Must have commit message\n\n'
echo "Recieved ${#}"
print_usage
return 1
fi
if [[ $debug == 'true' ]]; then
echo '\n\n######################### Debugging mode ON #########################\n\n'
echo "WARNING: Debugging mode disabpled 'git push' command\n"
echo "parsed flags: ${flags}"
if [[ $onlyStaged == 'true' ]]; then
echo -e "\tListing staged files:"
printf "\t\033[32m%s\033[0m\n" $(git diff --name-only --cached)
fi
echo "message: ${1}"
echo "is flagged: ${isFlagged}"
echo '\n\n######################### end of debugging messages #########################\n\n'
return
fi
git commit -m "${1}"