Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- git
- peco
- dasel

## Installation

Expand Down Expand Up @@ -35,3 +36,7 @@ git-commit--select-prefix
### emacs の場合

WIP

## Reference

- https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#type
43 changes: 43 additions & 0 deletions prefixes.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[[prefixes]]
key = "build"
description = "Changes that affect the build system or external dependencies (e.g., updating dependencies, modifying build scripts)"

[[prefixes]]
key = "chore"
description = "Changes to the build process or auxiliary tools and libraries such as documentation generation"

[[prefixes]]
key = "ci"
description = "Changes to CI configuration files and scripts"

[[prefixes]]
key = "docs"
description = "Documentation only changes"

[[prefixes]]
key = "feat"
description = "A new feature"

[[prefixes]]
key = "fix"
description = "A bug fix"

[[prefixes]]
key = "perf"
description = "A code change that improves performance"

[[prefixes]]
key = "refactor"
description = "A code change that neither fixes a bug nor adds a feature"

[[prefixes]]
key = "revert"
description = "Reverts a previous commit"

[[prefixes]]
key = "style"
description = "Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)"

[[prefixes]]
key = "test"
description = "Adding missing or correcting existing tests"
63 changes: 35 additions & 28 deletions zsh-select-commit-prefix.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
#!/bin/zsh
function git-commit--select-prefix() {
#TODO: tomlから選択できるprefixを読み込むようにする
prefixes=(
"build"
"chore"
"ci"
"docs"
"feat"
"fix"
"perf"
"refactor"
"revert"
"style"
"test"
)
printf "%s\n" "${prefixes[@]}" | peco | xargs -o -IPREFIX git commit -m "PREFIX: " -e
local toml_file=$HOME/.local/share/sheldon/repos/github.com/YuMuuu/zsh-select-commit-prefix/prefixes.toml
local choices=()
local prefix=""
local description=""

if [[ -f "$GIT_COMMIT_SELECT_PREFIX_TOML_FILE" ]]; then
toml_file=$GIT_COMMIT_SELECT_PREFIX_TOML_FILE
else
toml_file=$HOME/.local/share/sheldon/repos/github.com/YuMuuu/zsh-select-commit-prefix/prefixes.toml
fi

if [[ -f "$toml_file" ]]; then
keys=($(dasel -f "$toml_file" -r toml '.prefixes.all().key' 2>/dev/null ))
descriptions=$(dasel -f "$toml_file" -r toml '.prefixes.all().description' 2>/dev/null)
descriptions_array=()
while IFS= read -r line; do
descriptions_array+=("$line")
done <<< "$descriptions"

choices=()
for ((i=0; i<${#keys[@]}; i++)); do
choices+=("${keys[i]}: ${descriptions_array[i]}")
done
fi

if [[ -z "${choices[0]}" ]]; then
choices=("${choices[@]:1}")
fi

choices=("${choices[@]//\'/}")

local selected=$(printf "%s\n" "${choices[@]}" | peco)
prefix=${selected%%:*}

git commit -e -m "${prefix}: "
}














zle -N git-commit--select-prefix