前の記事( http://qiita.com/tetsutan/items/1bd13f79fdaf0b17cceb )のスクリプトにキャッシュ生成をさせるように変更しました
ghq listで良いのではと思われるかもしれませんが、mruのリストが欲しかったのです。
[ -f $ZSH_CUSTOM/lazy/cdgitroot.zsh ] && source $ZSH_CUSTOM/lazy/cdgitroot.zsh
function chpwd() {
_reg_pwd_gitroot
}
これで ~/.cdgitroot
ファイルにgit/hgのトップディレクトリが保存されるようになります。
ほぼ同じような操作になるので、cddを参考にさせていただきました。
chpwdのところは、add-zsh-hook chpwd hoge
のほうがいいのかな?
あとはpecoに素直にかませるだけです。
function peco-cdgitroot() {
local selected_dir=$(_echo_gitroot | peco )
if [ -n "$selected_dir" ]; then
BUFFER="cd ${selected_dir}"
zle accept-line
fi
zle clear-screen
}
zle -N peco-cdgitroot
bindkey '^@' peco-cdgitroot