Skip to content

Instantly share code, notes, and snippets.

@EkkoG
Last active February 5, 2018 16:29
Show Gist options
  • Save EkkoG/d5873db2b4db17f1d7bb68299c60738f to your computer and use it in GitHub Desktop.
Save EkkoG/d5873db2b4db17f1d7bb68299c60738f to your computer and use it in GitHub Desktop.
#!/bin/bash
usage()
{
echo "git commit,可使用 -d 附加信息类型,如:
-d add [添加]
-d mod [修改]
-d fix [修复]" 1>&2;
exit 1;
}
while getopts ":d:" o; do
case "${o}" in
d)
addition_opt=${OPTARG}
if [ "${OPTARG}x" == "fixx" ];then
message_type="[修复]"
fi
if [ "${OPTARG}x" == "addx" ];then
message_type="[新增]"
fi
if [ "${OPTARG}x" == "modx" ];then
message_type="[修改]"
fi
;;
*)
echo "" > /dev/null 2>&1
;; esac
done
args="$*"
if [ "${addition_opt}x" == "x" ];then
git commit $args
else
# 得到最后一个参数,及 commit message
all=$#
message=${!all}
delete=("-d" $addition_opt $message)
for del in ${delete[@]}
do
args=( "${args[@]/$del}" )
done
# 使用本来的参数和 message 附加类型加上原 message 进行提交
git commit $args "$message_type$message"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment