LoginSignup
3
3

More than 5 years have passed since last update.

pecoでgitのルートに移動する その2

Posted at

前の記事( 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
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3