From e333686c2ad3cba53625b35b361a00cadb281712 Mon Sep 17 00:00:00 2001 From: Federico Tensi Date: Thu, 26 Nov 2026 16:28:56 +0100 Subject: [PATCH] feat(git-commit): support optional commit body (#14169) --- plugins/git-commit/README.md | 8 ++++++-- plugins/git-commit/git-commands/omz_git_commit | 14 +++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/plugins/git-commit/README.md b/plugins/git-commit/README.md index ca3aed21b..79ff4fb3d 100644 --- a/plugins/git-commit/README.md +++ b/plugins/git-commit/README.md @@ -12,7 +12,7 @@ plugins=(... git-commit) ## Syntax ```zsh -git [(-s, --scope) ""] [(-a, --attention)] "" +git [(-s, --scope) ""] [(-a, --attention)] [(-b, --body) ""] "" ``` Where `type` is one of the following: @@ -30,6 +30,9 @@ Where `type` is one of the following: - `test` - `wip` +The optional `-b` / `--body` becomes the commit body (a blank line after the subject), as defined by +[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary). + > NOTE: the subcommand for `revert` type is `rev`, as otherwise it conflicts with the > git command of the same name. It will still generate a commit message in the format > `revert: ` @@ -39,6 +42,7 @@ Where `type` is one of the following: | Git subcommand | Command | | --------------------------------------------- | ---------------------------------------------------- | | `git style "remove trailing whitespace"` | `git commit -m "style: remove trailing whitespace"` | -| `git wip "work in progress"` | `git commit -m "work in progress"` | +| `git wip "work in progress"` | `git commit -m "wip: work in progress"` | | `git fix -s "router" "correct redirect link"` | `git commit -m "fix(router): correct redirect link"` | | `git rev -s "api" "rollback v2"` | `git commit -m "revert(api): rollback v2"` | +| `git feat -s "auth" -b "Keep session across redirects." "add login redirect"` | `git commit -m "feat(auth): add login redirect" -m "Keep session across redirects."` | diff --git a/plugins/git-commit/git-commands/omz_git_commit b/plugins/git-commit/git-commands/omz_git_commit index c493e6198..8555100b7 100755 --- a/plugins/git-commit/git-commands/omz_git_commit +++ b/plugins/git-commit/git-commands/omz_git_commit @@ -12,11 +12,11 @@ _omz_git_commit() { if [[ "$_type" == rev ]]; then _type=revert fi - local _scope _attention _message + local _scope _attention _message _body while [ $# -ne 0 ]; do case $1 in -s | --scope ) - if [ -z $2 ]; then + if [ -z "$2" ]; then echo >&2 "Missing scope!" return 1 fi @@ -27,12 +27,20 @@ _omz_git_commit() { _attention="!" shift 1 ;; + -b | --body ) + if [ -z "$2" ]; then + echo >&2 "Missing body!" + return 1 + fi + _body="$2" + shift 2 + ;; * ) _message="${_message} $1" shift 1 ;; esac done - git commit -m "${_type}${_scope:+(${_scope})}${_attention}:${_message}" + git commit -m "${_type}${_scope:+(${_scope})}${_attention}:${_message}" ${_body:+-m} ${_body:+"$_body"} } _omz_git_commit "$@"