From 336699e2497da29c9730392957cdf86cf0fabdcc Mon Sep 17 00:00:00 2001 From: YuMuuu Date: Wed, 27 Nov 2024 06:36:18 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20prefix=E3=82=92toml=E3=81=8B?= =?UTF-8?q?=E3=82=89=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wip wip wip wip wip wip wip wip wip wip wip wip --- README.md | 5 +++ prefixes.toml | 43 ++++++++++++++++++++++++++ zsh-select-commit-prefix.plugin.zsh | 47 +++++++++++++++-------------- 3 files changed, 73 insertions(+), 22 deletions(-) create mode 100644 prefixes.toml 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..a67cfee 100644 --- a/zsh-select-commit-prefix.plugin.zsh +++ b/zsh-select-commit-prefix.plugin.zsh @@ -1,33 +1,36 @@ #!/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 -} - - - - - - + export XDG_DATA_HOME=$HOME/.local/share + local toml_file=$XDG_DATA_HOME/sheldon/repos/github.com/YuMuuu/zsh-select-commit-prefix/prefixes.toml + local choices=() + local prefix="" + local description="" + 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 From a215e619d9a09638bff7b13c8ff7180b8050d748 Mon Sep 17 00:00:00 2001 From: YuMuuu Date: Wed, 27 Nov 2024 17:07:19 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20tomlfile=E3=82=92=E5=A4=96=E9=83=A8?= =?UTF-8?q?=E3=81=8B=E3=82=89=E6=8C=87=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsh-select-commit-prefix.plugin.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zsh-select-commit-prefix.plugin.zsh b/zsh-select-commit-prefix.plugin.zsh index a67cfee..5b8f70b 100644 --- a/zsh-select-commit-prefix.plugin.zsh +++ b/zsh-select-commit-prefix.plugin.zsh @@ -1,11 +1,15 @@ #!/bin/zsh function git-commit--select-prefix() { - export XDG_DATA_HOME=$HOME/.local/share - local toml_file=$XDG_DATA_HOME/sheldon/repos/github.com/YuMuuu/zsh-select-commit-prefix/prefixes.toml + 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 ))