Created
April 20, 2010 14:54
-
-
Save hchbaw/372569 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!zsh | |
# エディタのファイルの履歴を補完候補にするようなスクリプトです | |
_rf () { | |
local ref=$1 | |
shift | |
local -a xs | |
xs=("$@") | |
local -a ret | |
ret=() | |
for x in $xs | |
do [[ -e "${x/\~/$HOME/}" ]] && ret=($ret $x) | |
done | |
: ${(AP)ref::=${(@)ret}} | |
} | |
rppc= | |
fppc= | |
rf_prefix_r= | |
rf_prefix_f= | |
_recent_files () { | |
compstate[pattern_match]="-" | |
zstyle -s ":completion:${curcontext}:relative-path" prefix-c rppc | |
zstyle -s ":completion:${curcontext}:full-path" prefix-c fppc | |
: ${rf_prefix_r::="$rppc$PREFIX"} | |
: ${rf_prefix_f::="$fppc$PREFIX"} | |
return 1 | |
} | |
_rf_viminfo_relative_path () { | |
local -a _viminfo | |
local f="$HOME/.viminfo" | |
local pwd=$(readlink -f $PWD) | |
_rf _viminfo ${${${${(uf@)"$(<$f)"}:#^>*}#> }/$pwd\//} | |
PREFIX=$rf_prefix_r | |
compadd -aQ -V viminfor -X viminfo-relative-path - _viminfo | |
return 1 | |
} | |
_rf_viminfo_full_path () { | |
local -a _viminfo | |
local f="$HOME/.viminfo" | |
_rf _viminfo ${${${(uf@)"$(<$f)"}:#^>*}#> } | |
PREFIX=$rf_prefix_f | |
compadd -aQ -V viminfof -X viminfo-full-path - _viminfo | |
return 1 | |
} | |
_rf_recentf_relative_path () { | |
local -a _recentf | |
local s=" " | |
local f="$HOME/.recentf" | |
PREFIX=$rf_prefix_r | |
_rf _recentf ${(Q)${${${${(uf@)"$(<$f)"}:#^${s}\"*}/$PWD\//}/$HOME\//\~/}##* } | |
compadd -aQ -V recentfr -X recentf-relative-path - _recentf | |
return 1 | |
} | |
_rf_recentf_full_path () { | |
local -a _recentf | |
local s=" " | |
local f="$HOME/.recentf" | |
PREFIX=$rf_prefix_f | |
_rf _recentf ${(Q)${${${(uf@)"$(<$f)"}:#^${s}\"*}/$HOME\//\~/}##* } | |
compadd -aQ -V recentff -X recentf-fullpath - _recentf | |
return 1 | |
} | |
_rf_end () { | |
(( $compstate[nmatches] )) || { | |
local -a c | |
c=(${rppc} ${fppc}) | |
zle -M "No matches for: [${(j.|.)c}]$PREFIX" | |
} | |
} | |
zstyle ':completion:recent-files:*:relative-path' prefix-c '' | |
zstyle ':completion:recent-files:*:full-path' prefix-c '*' | |
zstyle ':completion:recent-files::::' completer \ | |
_recent_files _rf_viminfo_relative_path _rf_viminfo_full_path \ | |
_rf_recentf_relative_path _rf_recentf_full_path _rf_end | |
zstyle ':completion:recent-files-relative-path:*:relative-path' prefix-c '*' | |
zstyle ':completion:recent-files-relative-path:*:full-path' prefix-c '' | |
zstyle ':completion:recent-files-relative-path::::' completer \ | |
_recent_files _rf_viminfo_relative_path _rf_recentf_relative_path _rf_end | |
zle -C recent-files-relative-path complete-word _generic | |
zle -C recent-files complete-word _generic | |
# zle -C recent-files-relative-path list-choices _generic | |
# zle -C recent-files list-choices _generic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment