LoginSignup
1

More than 5 years have passed since last update.

pecoなどでbundleしてるgemのディレクトリにcdする

Posted at

zshのスクリプトで

bundle path [gem]
gemのパスを表示
bundle cd [gem]
gemのパスに移動

を作りました

必要なもの

  • anyframe
    • https://github.com/mollifier/anyframe
    • pecoとかpercolとかをよしなにしてくれるやつ
    • anyframeないけど、pecoとかは入ってるって場合は、 anyframe-selector-autoの部分をpecoとかに置き換えてください
  • pecoとかpercolとか

bundle path [gem]

asciicast

bundle cd [gem]

asciicast

source

~/.zshrc
_orig_bundle=$(which bundle)

# like: bundle list | anyframe-selector-auto
function bundle_path() {
    local gem
    if [ "$1" ]; then
        gem=$1
    else
        gem=$($_orig_bundle list | sed -e '1d' | cut -d'*' -f2 | cut -d' ' -f2- | anyframe-selector-auto)
        gem=$(echo $gem | cut -d' ' -f1)
    fi
    $_orig_bundle show $gem
}

# like: cd $(bundle list | anyframe-selector-auto)
function bundle_cd() {
    cd $(bundle_path "$@")
}

# bundle cd [gem]
# bundle path [gem]
function bundle() {
    if [ "$1" = "cd" ]; then
        shift
        bundle_cd "$@"
    elif [ "$1" = "path" ]; then
        shift
        bundle_path "$@"
    else
        $_orig_bundle $*
    fi
}

こういう実装にした理由

cd $(bundle show --paths | peco)にキーバインド当てるのが一番シンプルな実装ですが、

  • bundle show --paths はフルパスがでてpecoなどでの絞り込みの際に見づらい
  • キーバインド覚えるの面倒くさい

という理由で今回の実装にしました。

あと、ghq + gem_srcの実装も方向も検討しましたが
http://qiita.com/yuku_t/items/78107016af9eb78d5804
この記事見てgem_srcはやめました

参考にした記事

http://qiita.com/yuku_t/items/78107016af9eb78d5804
http://qiita.com/hoshino/items/d2f7fe223d0b37214408

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
1