diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2a3c079..c66ebe8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: check-added-large-files - id: fix-byte-order-marker @@ -21,7 +21,7 @@ repos: - id: check-toml - id: check-json - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.5.4 + rev: v1.5.5 hooks: - id: remove-crlf - repo: https://github.com/codespell-project/codespell @@ -45,11 +45,11 @@ repos: hooks: - id: check-mailmap - repo: https://github.com/rhysd/actionlint - rev: v1.6.26 + rev: v1.6.27 hooks: - id: actionlint - repo: https://github.com/adrienverge/yamllint - rev: v1.33.0 + rev: v1.35.1 hooks: - id: yamllint - repo: https://github.com/executablebooks/mdformat @@ -63,10 +63,11 @@ repos: - mdformat-toc - mdformat-deflist - mdformat-beautysh - - mdformat-black + - mdformat-ruff - mdformat-config + - mdformat-web - repo: https://github.com/DavidAnson/markdownlint-cli2 - rev: v0.11.0 + rev: v0.13.0 hooks: - id: markdownlint-cli2 additional_dependencies: diff --git a/README.md b/README.md index 8b0742c..18b98d7 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ expansions ## Dependencies -- [pypinyin](https://github.com/mozillazg/python-pinyin) +- [pypinyin](https://github.com/mozillazg/python-pinyin) `>= 0.51.0` ## Install diff --git a/pinyin-completion.plugin.zsh b/pinyin-completion.plugin.zsh index 202ef5d..cf32758 100644 --- a/pinyin-completion.plugin.zsh +++ b/pinyin-completion.plugin.zsh @@ -47,7 +47,9 @@ local -A _punctuation_map=( _pinyin_comp() { # unix file names can contain '\n', so use '\0' to separate them - local IFS=$'\0' suffix file result k v + local IFS=$'\0' suffix result file k v + local -i i=1 + local -a files results if [ "$words[1]" = cd ] ; then suffix=/ else @@ -57,17 +59,26 @@ _pinyin_comp() for file in $(print -nN ${1:h}/*"$suffix"); do file="${file#./}" if [[ $file =~ [^[:ascii:]] ]]; then - result="$(pypinyin -fslug -sz -p= "$file")" - for k v in ${(kv)FUZZY} ${(kv)_punctuation_map}; do - result="${result//$k/$v}" - done + files+=($file) else result="$file" - fi - if [[ $result == $1* ]]; then - reply+=(${(q)file}) + if [[ $result == $1* ]]; then + reply+=(${(q)file}) + fi fi done + if (( $#files )); then + results=(${(f)$(pypinyin -fslug -sz -p= $files)}) + for result in $results; do + for k v in ${(kv)FUZZY} ${(kv)_punctuation_map}; do + result="${result//$k/$v}" + done + if [[ $result == $1* ]]; then + reply+=(${(q)${files[i]}}) + fi + i=$((i + 1)) + done + fi } # pinyin-comp is performed as one part of user-expand