mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-30 17:50:07 +00:00
style: break long lines
This commit is contained in:
parent
cb81849cfe
commit
06059baa1f
2 changed files with 57 additions and 41 deletions
|
@ -1,8 +1,10 @@
|
||||||
# git-commit-template plugin
|
# git-commit-template plugin
|
||||||
|
|
||||||
To better write git commit messages, we can use template to specify the desired description and type of message.
|
To better write git commit messages, we can use template to specify the
|
||||||
|
desired description and type of message.
|
||||||
|
|
||||||
To use it, add `git-commit-template` to the plugins array in your zshrc file:
|
To use it, add `git-commit-template` to the plugins array in your zshrc
|
||||||
|
file:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
plugins=(... git-commit-template)
|
plugins=(... git-commit-template)
|
||||||
|
@ -16,7 +18,8 @@ plugins=(... git-commit-template)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
All you have to do is call the `gct` command and fill in the items that are not optional at each step to prepare the message format.
|
All you have to do is call the `gct` command and fill in the items that
|
||||||
|
are not optional at each step to prepare the message format.
|
||||||
|
|
||||||
![gct](https://raw.githubusercontent.com/ghasemdev/git-commit-template/master/images/1.png)
|
![gct](https://raw.githubusercontent.com/ghasemdev/git-commit-template/master/images/1.png)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
function git_commit_template() {
|
git_commit_template() {
|
||||||
# Check in this directory git exist
|
# Check in this directory git exist
|
||||||
if [ ! -d .git ]; then
|
if [ ! -d .git ]; then
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -12,7 +12,9 @@ function git_commit_template() {
|
||||||
RESET="\033[0m"
|
RESET="\033[0m"
|
||||||
|
|
||||||
# Valid types
|
# Valid types
|
||||||
TYPES=("feat" "fix" "docs" "style" "refactor" "pref" "test" "build" "ci" "chore" "revert")
|
TYPES=("feat" "fix" "docs" "style" "refactor"
|
||||||
|
"pref" "test" "build" "ci" "chore" "revert")
|
||||||
|
|
||||||
NUMBERS=("1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11")
|
NUMBERS=("1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11")
|
||||||
|
|
||||||
# Type section
|
# Type section
|
||||||
|
@ -21,24 +23,30 @@ function git_commit_template() {
|
||||||
printf "${CYAN}1. feat${RESET} - A new feature.\n"
|
printf "${CYAN}1. feat${RESET} - A new feature.\n"
|
||||||
printf "${CYAN}2. fix${RESET} - A bug fix.\n"
|
printf "${CYAN}2. fix${RESET} - A bug fix.\n"
|
||||||
printf "${CYAN}3. docs${RESET} - Documentation only changes.\n"
|
printf "${CYAN}3. docs${RESET} - Documentation only changes.\n"
|
||||||
printf "${CYAN}4. style${RESET} - Changes that do notaffect the meaning of the code (white-space, formatting, missing semi-colons, etc).\n"
|
printf "${CYAN}4. style${RESET} - Changes that do notaffect the meaning of \
|
||||||
printf "${CYAN}5. refactor${RESET} - A Code change that neither fixes a bug nor adds a feature.\n"
|
the code (white-space, formatting, missing semi-colons, etc).\n"
|
||||||
|
printf "${CYAN}5. refactor${RESET} - A Code change that neither fixes a bug \
|
||||||
|
nor adds a feature.\n"
|
||||||
printf "${CYAN}6. pref${RESET} - A code change that improves performance.\n"
|
printf "${CYAN}6. pref${RESET} - A code change that improves performance.\n"
|
||||||
printf "${CYAN}7. test${RESET} - Adding missing tests or correcting existing tests.\n"
|
printf "${CYAN}7. test${RESET} - Adding missing tests or correcting existing \
|
||||||
printf "${CYAN}8. build${RESET} - Changes that effect the build system or external dependencies (example scopes: glup, broccoli, npm).\n"
|
tests.\n"
|
||||||
printf "${CYAN}9. ci${RESET} - Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs).\n"
|
printf "${CYAN}8. build${RESET} - Changes that effect the build system or \
|
||||||
printf "${CYAN}10. chore${RESET} - Other changes that don't modify src or test files.\n"
|
external dependencies (example scopes: glup, broccoli, npm).\n"
|
||||||
|
printf "${CYAN}9. ci${RESET} - Changes to our CI configuration files and \
|
||||||
|
scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs).\n"
|
||||||
|
printf "${CYAN}10. chore${RESET} - Other changes that don't modify src or test \
|
||||||
|
files.\n"
|
||||||
printf "${CYAN}11. revert${RESET} - Reverts a previous commit.\n\n"
|
printf "${CYAN}11. revert${RESET} - Reverts a previous commit.\n\n"
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
read -e TYPE
|
read -e type_var
|
||||||
# To lower case
|
# To lower case
|
||||||
TYPE=${TYPE,,}
|
type_var=${type_var,,}
|
||||||
# When input type is valid loop break
|
# When input type is valid loop break
|
||||||
if [[ " ${NUMBERS[*]} " =~ " ${TYPE} " ]]; then
|
if [[ " ${NUMBERS[*]} " =~ " ${type_var} " ]]; then
|
||||||
TYPE="${TYPES[TYPE - 1]}"
|
type_var="${TYPES[type_var - 1]}"
|
||||||
break
|
break
|
||||||
elif [[ " ${TYPES[*]} " =~ " ${TYPE} " ]]; then
|
elif [[ " ${TYPES[*]} " =~ " ${type_var} " ]]; then
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
printf "${RED}❌ Please select a valid type.${RESET}\n"
|
printf "${RED}❌ Please select a valid type.${RESET}\n"
|
||||||
|
@ -47,19 +55,21 @@ function git_commit_template() {
|
||||||
|
|
||||||
# Scppe section
|
# Scppe section
|
||||||
printf "\n${BLUE}>>> Scope of this change (optional)?${RESET}\n"
|
printf "\n${BLUE}>>> Scope of this change (optional)?${RESET}\n"
|
||||||
printf "The scope could be anything specifying place of the commit change e.g a file name, function name, class name, component name etc.\n\n"
|
printf "The scope could be anything specifying place of the commit change e.g \
|
||||||
read -e SCOPE
|
a file name, function name, class name, component name etc.\n\n"
|
||||||
|
read -e scope
|
||||||
|
|
||||||
# Subject section
|
# Subject section
|
||||||
printf "\n${BLUE}>>> Short description?${RESET}\n"
|
printf "\n${BLUE}>>> Short description?${RESET}\n"
|
||||||
printf "The short description contains succinct description of the change:\n"
|
printf "The short description contains succinct description of the change:\n"
|
||||||
printf ' • use the imperative, present tense: "change" not "changed" nor "changes"\n'
|
printf " • use the imperative, present tense: 'change' not 'changed' nor \
|
||||||
|
'changes'\n"
|
||||||
printf " • don't capitalize first letter\n"
|
printf " • don't capitalize first letter\n"
|
||||||
printf " • no dot (.) at the end\n\n"
|
printf " • no dot (.) at the end\n\n"
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
read -e SHORT_DESC
|
read -e short_desc
|
||||||
if [ -z "$SHORT_DESC" ]; then
|
if [ -z "$short_desc" ]; then
|
||||||
printf "${RED}❌ Short description can not be empty.${RESET}\n"
|
printf "${RED}❌ Short description can not be empty.${RESET}\n"
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
|
@ -68,43 +78,46 @@ function git_commit_template() {
|
||||||
|
|
||||||
# Description section
|
# Description section
|
||||||
printf "\n${BLUE}>>> Long description (optional)?${RESET}\n"
|
printf "\n${BLUE}>>> Long description (optional)?${RESET}\n"
|
||||||
printf "The body should include the motivation for the change and contrast this with previous behavior.\n\n"
|
printf "The body should include the motivation for the change and contrast \
|
||||||
read -e LONG_DESC
|
this with previous behavior.\n\n"
|
||||||
|
read -e long_desc
|
||||||
|
|
||||||
# Breaking changes section
|
# Breaking changes section
|
||||||
printf "\n${BLUE}>>> Breaking changes (optional)?${RESET}\n"
|
printf "\n${BLUE}>>> Breaking changes (optional)?${RESET}\n"
|
||||||
printf "note the reason for a breaking change within the commit.\n\n"
|
printf "note the reason for a breaking change within the commit.\n\n"
|
||||||
read -e BREAKING_CHANGES
|
read -e breaking_changes
|
||||||
|
|
||||||
# Closed issues section
|
# Closed issues section
|
||||||
printf "\n${BLUE}>>> Closed issues (optional)?${RESET}\n"
|
printf "\n${BLUE}>>> Closed issues (optional)?${RESET}\n"
|
||||||
printf "The syntax for closing keywords depends on whether the issue is in the same repository as the pull request.\n"
|
printf "The syntax for closing keywords depends on whether the issue is in \
|
||||||
|
the same repository as the pull request.\n"
|
||||||
printf " • Issue in the same repository -> Closes #10\n"
|
printf " • Issue in the same repository -> Closes #10\n"
|
||||||
printf " • Issue in a different repository -> Fixes octo-org/octo-repo#100\n"
|
printf " • Issue in a different repository -> Fixes octo-org/octo-repo#100\n"
|
||||||
printf " • Multiple issues -> Resolves #10, resolves #123, resolves octo-org/octo-repo#100\n\n"
|
printf " • Multiple issues -> Resolves #10, resolves #123, resolves \
|
||||||
read -e CLOSED_ISSUES
|
octo-org/octo-repo#100\n\n"
|
||||||
|
read -e closed_issues
|
||||||
|
|
||||||
# Result section
|
# Result section
|
||||||
if [ ! -z "$SCOPE" ]; then
|
if [ ! -z "$scope" ]; then
|
||||||
SCOPE="(${SCOPE})"
|
scope="(${scope})"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "$BREAKING_CHANGES" ]; then
|
if [ ! -z "$breaking_changes" ]; then
|
||||||
BREAKING_CHANGES="BREAKING CHANGE: ${BREAKING_CHANGES}"
|
breaking_changes="BREAKING CHANGE: ${breaking_changes}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "\n ${GREEN}${TYPE}${SCOPE}: ${SHORT_DESC}
|
printf "\n ${GREEN}${type_var}${scope}: ${short_desc}
|
||||||
${LONG_DESC}
|
${long_desc}
|
||||||
${BREAKING_CHANGES}
|
${breaking_changes}
|
||||||
${CLOSED_ISSUES}${RESET}\n\n"
|
${closed_issues}${RESET}\n\n"
|
||||||
|
|
||||||
# Git commit
|
# Git commit
|
||||||
RESULT_CODE=$?
|
result_code=$?
|
||||||
if [ "$RESULT_CODE" = 0 ]; then
|
if [ "$result_code" = 0 ]; then
|
||||||
git commit -m "${TYPE}${SCOPE}: ${SHORT_DESC}
|
git commit -m "${type_var}${scope}: ${short_desc}
|
||||||
${LONG_DESC}
|
${long_desc}
|
||||||
${BREAKING_CHANGES}
|
${breaking_changes}
|
||||||
${CLOSED_ISSUES}"
|
${closed_issues}"
|
||||||
else
|
else
|
||||||
printf "\n${RED}❌ An error occurred. Please try again.${RESET}\n"
|
printf "\n${RED}❌ An error occurred. Please try again.${RESET}\n"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue