Skip to content

Commit

Permalink
⬆️ Upgrade pypinyin
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Apr 19, 2024
1 parent 5949bc3 commit b0cbc38
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ expansions

## Dependencies

- [pypinyin](https://github.com/mozillazg/python-pinyin)
- [pypinyin](https://github.com/mozillazg/python-pinyin) `>= 0.51.0`

## Install

Expand Down
27 changes: 19 additions & 8 deletions pinyin-completion.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b0cbc38

Please sign in to comment.