-
Notifications
You must be signed in to change notification settings - Fork 14
/
git-now-add
63 lines (56 loc) · 1.42 KB
/
git-now-add
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
usage() {
echo "usage: git now add [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]"
echo " [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]"
echo " [--refresh] [--ignore-errors] [--ignore-missing] [--stat | -s] [--push]"
echo " [--] [<filepattern>...]"
}
cmd_default() {
if [ $BRACKET = "true" ]; then
prefix_str="[${PREFIX}]"
else
prefix_str=$PREFIX
fi
MESSAGE="${prefix_str} `date +\"%Y/%m/%d %T\"`"
if [ $# -eq 0 ]; then
git add -u
printf "${MESSAGE}\n\n%s" "`git diff --cached --no-ext-diff`" | git commit -F -
else
local is_all=false
local is_stat=false
local is_push=false
local args=()
# args loop
for arg in "$@"
do
if [ $arg = "--stat" ] || [ $arg = "-s" ]; then
is_stat=true
elif [ $arg = "--all" ]; then
is_all=true
elif [ $arg = "--push" ]; then
is_push=true
else
n=${#args[@]}
args[$n]=$arg
fi
done
if ! $is_all; then
git add ${args[@]}
else
git add -u
git add .
fi
if $is_stat; then
printf "${MESSAGE}\n\n%s" "`git diff --cached --stat --no-ext-diff`" | git commit -F -
else
printf "${MESSAGE}\n\n%s" "`git diff --cached --no-ext-diff`" | git commit -F -
fi
if $is_push; then
git push
fi
fi
}
cmd_help() {
usage
exit 0
}
# vim: set ff=unix ft=sh :