diff --git a/README.md b/README.md index 2dee0bb..490288c 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ - git - peco +- dasel ## Installation @@ -35,3 +36,7 @@ git-commit--select-prefix ### emacs の場合 WIP + +## Reference + +- https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#type diff --git a/prefixes.toml b/prefixes.toml new file mode 100644 index 0000000..f9e0fb5 --- /dev/null +++ b/prefixes.toml @@ -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" diff --git a/zsh-select-commit-prefix.plugin.zsh b/zsh-select-commit-prefix.plugin.zsh index d1a12b0..5b8f70b 100644 --- a/zsh-select-commit-prefix.plugin.zsh +++ b/zsh-select-commit-prefix.plugin.zsh @@ -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 \ No newline at end of file