はじめに
自分でリポジトリをフォーク、クローンしてるけど、ローカルの別ディレクトリにもoriginのリポジトリをクローンしているってことよくあるだろうし、そのoriginのリポジトリまでcdしたいこともよくあると思う
$ echo $PWD /Users/naari3/src/github.com/naari3/hyper-nice-repo # ここにいるけど $ cd /Users/naari3/src/github.com/alice/hyper-nice-repo # ここに移動したい
ので移動するためのzsh functionを書いた
requirements
多分よくある組み合わせだと思います みなさんpecoもghqも使ってますよね?
ソース
function peco-cd-forked-repo () { local current_repo_name="$(basename "$PWD")" local selected_dir=$(ghq list --full-path --exact $current_repo_name | peco --prompt="cd-ghq-fork >" --query "$LBUFFER") if [ -n "$selected_dir" ]; then BUFFER="cd $selected_dir" zle accept-line fi }
変哲なことはしていない
僕はこれを適当なkeybindで発火するように設定していていつでもリポジトリを反復横跳び出来るようにしている
おわりに
pecoはすごい