iwata.git-now/git-now-add
Toshiyuki Kawanishi 5f3a359a0f Prefix config
2014-06-14 11:48:46 +09:00

64 lines
1.4 KiB
Bash

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 :