-
Notifications
You must be signed in to change notification settings - Fork 1
/
_path_files
36 lines (31 loc) · 1.14 KB
/
_path_files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#compdef -redirect-,-default-,-default-
# デフォルトの_path_filesを呼ぶ
for dir in $fpath; do
if [ "$dir" != "${0:h:A}" -a -e "$dir/_path_files" ]; then
. "$dir/_path_files" "$@"
break
fi
done
# 日本語をローマ字に変換し、元の日本語と併記する
kanji-to-romaji() {
local tmp="/tmp/kanji-to-romaji"
cat > "$tmp"
case $OSTYPE in
darwin*) local f=$(iconv -l | grep 'UTF.*MAC' | sed 's/ .*//') ;;
*) local f=utf8 ;;
esac
if iconv --version 2> /dev/null | grep 'GNU libiconv' > /dev/null; then
# iconv (GNU libiconv 1.11) (Mac)
paste <(iconv --byte-subst='?' --unicode-subst='<U+%04X>' -f $f -t euc-jp "$tmp" | kakasi -w | kakasi -Ja -Ha -Ka -Ea | sed 's/ //g') "$tmp"
else
paste <(iconv -f $f -t euc-jp "$tmp" | kakasi -w | kakasi -Ja -Ha -Ka -Ea | sed 's/ //g') "$tmp"
fi
rm "$tmp"
}
local word="${words[CURRENT]}"
local matches=$(command ls | grep '[^ -~]' | kanji-to-romaji | grep -i "^${word}" | awk -F $'\t' '{print $NF}')
local files=(${(f)matches}) # 改行でsplit
if [ "$files" != "" ]; then
compadd -J file -U $files
fi
return 0