mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-03-13 21:33:22 +01:00
feat(git-commit-plugin): add new flag -a|--attention & similar
This commit is contained in:
parent
40ff950fcd
commit
becf703656
1 changed files with 44 additions and 3 deletions
|
@ -14,6 +14,48 @@ _git_commit_aliases=(
|
|||
'wip'
|
||||
)
|
||||
|
||||
local -a _git_commit_flags
|
||||
_git_commit_flags=(
|
||||
'-s'
|
||||
'--scope'
|
||||
'-a'
|
||||
'--attention'
|
||||
'-sa'
|
||||
'-as'
|
||||
)
|
||||
|
||||
remove_flags() {
|
||||
local message="$1"
|
||||
local flags=("${@:2}")
|
||||
|
||||
local regex=$(IFS="|"; echo "${flags[*]}")
|
||||
|
||||
message=$(sed -E "s/\s($regex)\s|\s($regex)$//g" <<< "$message")
|
||||
|
||||
echo "$message"
|
||||
}
|
||||
|
||||
build_message () {
|
||||
if [[ "$*" =~ (-sa|-as) ]]; then
|
||||
local attention='!'
|
||||
local scope="($2)"
|
||||
shift 2
|
||||
else
|
||||
if [[ "$*" =~ (-s|--scope) ]]; then
|
||||
local scope="($2)"
|
||||
shift 2
|
||||
fi
|
||||
|
||||
if [[ "$*" =~ (-a|--attention) ]]; then
|
||||
local attention='!'
|
||||
fi
|
||||
fi
|
||||
|
||||
local message="'$type'${scope}$attention: $@";
|
||||
|
||||
git commit -m $(remove_flags "$message" "${_git_commit_flags[@]}")
|
||||
};
|
||||
|
||||
local alias type
|
||||
for type in "${_git_commit_aliases[@]}"; do
|
||||
# an alias can't be named "revert" because the git command takes precedence
|
||||
|
@ -23,10 +65,9 @@ for type in "${_git_commit_aliases[@]}"; do
|
|||
*) alias=$type ;;
|
||||
esac
|
||||
|
||||
local func='!a() { if [ "$1" = "-s" ] || [ "$1" = "--scope" ]; then local scope="$2"; shift 2; git commit -m "'$type'(${scope}): ${@}"; else git commit -m "'$type': ${@}"; fi }; a'
|
||||
if ! git config --global --get-all alias.${alias} >/dev/null 2>&1; then
|
||||
git config --global alias.${alias} "$func"
|
||||
git config --global alias.${alias} build_message
|
||||
fi
|
||||
done
|
||||
|
||||
unset _git_commit_aliases alias type func
|
||||
unset _git_commit_aliases _flags alias type
|
||||
|
|
Loading…
Add table
Reference in a new issue