2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

Zshでcdrをpecoにかませると便利ですね。
http://qiita.com/syui/items/f2fe51d00378210d10b1
僕はこの方のスクリプトを使わさせてもらっています。

ところで、僕は作業するときにgitのルートディレクトリへ移動してから何をするかを考えるので、cdrと組み合わせてそれを実行させたいと思います。

$ cdr -l | awk '{ print "\\ls -d " $2 "/.git" " 2>/dev/null" }' | sh \
      | sed -e "s;^$HOME;~;" | sed -e "s|/\.git$||" | peco

これを関数にしてbindkeyして使っています


function peco-git-cd() {
    local selected_dir=$(cdr -l | awk '{ print "\\ls -d " $2 "/.git" " 2>/dev/null" }' | sh \
      | sed -e "s;^$HOME;~;" | sed -e "s|/\.git$||" | peco )
    if [ -n "$selected_dir" ]; then
        BUFFER="cd ${selected_dir}"
        zle accept-line
    fi
    zle clear-screen
}
zle -N peco-git-cd
bindkey '^@' peco-git-cd


ちょっと実行に時間が掛かるのでシェルの効率化やキャッシュやら作ったほうがいいんでしょうけど、まずは許容範囲という感じです。

2
3
1

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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?