├── LICENSE ├── README.md ├── _path_files ├── demo.gif ├── examples ├── English.txt ├── nihongo.txt ├── スクリーンショット │ └── .keep ├── ピアノ.txt ├── 日本人.txt ├── 日本語.txt └── 日本語の スペースや"クォート"'混じり'.txt └── zsh-romaji-complete.plugin.zsh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Shotaro Aoyama 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zsh-romaji-complete 2 | 3 | zshのタブ補完でローマ字による日本語ファイル名補完ができるようにします。 4 | 5 | 例: `niho` で`日本`で始まるファイル名が補完されます。 6 | 7 | 8 | 9 | ## セットアップ 10 | 11 | ### 1. kakasiをインストール 12 | 13 | ```console 14 | $ git clone --depth 1 git@github.com:loretoparisi/kakasi.git 15 | $ cd kakasi 16 | $ ./configure && make && make install 17 | ``` 18 | 19 | ### 2. zsh-romaji-completeをインストール 20 | 21 | #### a) Plugin manager 22 | 23 | ##### zinit 24 | ``` 25 | zinit light aoyama-val/zsh-romaji-complete 26 | ``` 27 | 28 | ##### oh-my-zsh 29 | ``` 30 | git clone https://github.com/aoyama-val/zsh-romaji-complete.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-romaji-complete 31 | ``` 32 | 33 | .zshrcに以下を追加 34 | ``` 35 | plugins=([既存のplugin...] zsh-romaji-complete) 36 | ``` 37 | 38 | 39 | #### b) Manual 40 | 41 | お好きな場所にクローンします: 42 | 43 | ```console 44 | $ git clone git@github.com:aoyama-val/zsh-romaji-complete.git 45 | ``` 46 | 47 | `~/.zshrc`に下記を追加: 48 | 49 | ``` 50 | bindkey "^I" menu-expand-or-complete 51 | fpath+=({クローンしたディレクトリ} $fpath) 52 | . {クローンしたディレクトリ}/zsh-romaji-complete.plugin.zsh 53 | ``` 54 | 55 | zshのデフォルトでは `^I` は `expand-or-complete`ですが、それだと候補が複数ある場合に何も補完されません。 56 | -------------------------------------------------------------------------------- /_path_files: -------------------------------------------------------------------------------- 1 | #compdef -redirect-,-default-,-default- 2 | 3 | # デフォルトの_path_filesを呼ぶ 4 | for dir in $fpath; do 5 | if [ "$dir" != "${0:h:A}" -a -e "$dir/_path_files" ]; then 6 | . "$dir/_path_files" "$@" 7 | break 8 | fi 9 | done 10 | 11 | # 日本語をローマ字に変換し、元の日本語と併記する 12 | kanji-to-romaji() { 13 | local tmp="/tmp/kanji-to-romaji" 14 | cat > "$tmp" 15 | case $OSTYPE in 16 | darwin*) local f=$(iconv -l | grep 'UTF.*MAC' | sed 's/ .*//') ;; 17 | *) local f=utf8 ;; 18 | esac 19 | if iconv --version 2> /dev/null | grep 'GNU libiconv' > /dev/null; then 20 | # iconv (GNU libiconv 1.11) (Mac) 21 | paste <(iconv --byte-subst='?' --unicode-subst='' -f $f -t euc-jp "$tmp" | kakasi -w | kakasi -Ja -Ha -Ka -Ea | sed 's/ //g') "$tmp" 22 | else 23 | paste <(iconv -f $f -t euc-jp "$tmp" | kakasi -w | kakasi -Ja -Ha -Ka -Ea | sed 's/ //g') "$tmp" 24 | fi 25 | rm "$tmp" 26 | } 27 | 28 | local word="${words[CURRENT]}" 29 | local matches=$(command ls | grep '[^ -~]' | kanji-to-romaji | grep -i "^${word}" | awk -F $'\t' '{print $NF}') 30 | local files=(${(f)matches}) # 改行でsplit 31 | 32 | if [ "$files" != "" ]; then 33 | compadd -J file -U $files 34 | fi 35 | 36 | return 0 37 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoyama-val/zsh-romaji-complete/0ae9dd03b6e55339ec10d0cc1cdbffb60f2fd87a/demo.gif -------------------------------------------------------------------------------- /examples/English.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoyama-val/zsh-romaji-complete/0ae9dd03b6e55339ec10d0cc1cdbffb60f2fd87a/examples/English.txt -------------------------------------------------------------------------------- /examples/nihongo.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoyama-val/zsh-romaji-complete/0ae9dd03b6e55339ec10d0cc1cdbffb60f2fd87a/examples/nihongo.txt -------------------------------------------------------------------------------- /examples/スクリーンショット/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoyama-val/zsh-romaji-complete/0ae9dd03b6e55339ec10d0cc1cdbffb60f2fd87a/examples/スクリーンショット/.keep -------------------------------------------------------------------------------- /examples/ピアノ.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoyama-val/zsh-romaji-complete/0ae9dd03b6e55339ec10d0cc1cdbffb60f2fd87a/examples/ピアノ.txt -------------------------------------------------------------------------------- /examples/日本人.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoyama-val/zsh-romaji-complete/0ae9dd03b6e55339ec10d0cc1cdbffb60f2fd87a/examples/日本人.txt -------------------------------------------------------------------------------- /examples/日本語.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoyama-val/zsh-romaji-complete/0ae9dd03b6e55339ec10d0cc1cdbffb60f2fd87a/examples/日本語.txt -------------------------------------------------------------------------------- /examples/日本語の スペースや"クォート"'混じり'.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoyama-val/zsh-romaji-complete/0ae9dd03b6e55339ec10d0cc1cdbffb60f2fd87a/examples/日本語の スペースや"クォート"'混じり'.txt -------------------------------------------------------------------------------- /zsh-romaji-complete.plugin.zsh: -------------------------------------------------------------------------------- 1 | command -v kakasi > /dev/null 2>&1 || echo "zsh-romaji-complete: kakasi not installed" 1>&2 2 | --------------------------------------------------------------------------------