10
9

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.

zshでbundle execを補完する

Posted at

準備

以下のコマンドで実行ファイルのインストール先を指定する。

zsh
$ bundle install --path=vendor/bundler --binstubs=vendor/bin

設定

  • rakeのための補完関数を定義
  • bundle execを実行するためのbeコマンドを作成
  • bundle exec(be)のための補完関数を定義
.zshrc
_rake_refresh () {
    if [[ ! -f .rake_tasks ]]; then
        return 0;
    else
        return $([[ Rakefile -nt .rake_tasks ]])
    fi
}

_rake () {
    if [[ -f Rakefile ]]; then
        if _rake_refresh; then
            bundle exec rake --silent --all --tasks | cut -d " " -f 2 | sed 's/:/\\\:/g' | sed 's/\[/\\[/g' | sed 's/\]/\\]/g' > .rake_tasks
        fi
        _values "rake" $(<.rake_tasks)
    fi
}

be () {
    bundle exec $*
}

_be () {
    if [[ -d vendor/bin ]]; then
        _arguments '*: :->'
        if [[ $CURRENT == 2 ]]; then
            _values "bundle exec" `\ls -1 vendor/bin`
        elif [[ $CURRENT == 3 && $line[1] == "rake" ]]; then
            _rake
        else
            _files
        fi
    fi
}

compdef _be be

参考

zshでbundle exec(とrake)を補完 - 12FF5B8

10
9
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
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?