Home > Net >  How to use compilations when prefixing a command with bundle exec?
How to use compilations when prefixing a command with bundle exec?

Time:09-22

When I try to run a command like cap with bundle exec cap my compleitions for cap tasks do not work. Instead I get a directory listing:

> bundle exec cap -T
app/             config.ru  Gemfile.lock  package-lock.json  reference/             yarn.lock
babel.config.js  config/    Guardfile     postcss.config.js  spec/
bin/             db/        lib/          public/            ted_app_meta_data.yml
build/           doc/       log/          Rakefile           tmp/
Capfile          Gemfile    package.json  README.md          vendor/
> cap -T 
airbrake:deploy                         (Capistrano task)  deploy:finishing_rollback        (Capistrano task)  deploy:updating                                                                 (Capistrano task)  git:ini-1.3.8                    (Capistrano task)  unicorn:graceful_restart                 (Capistrano task)

It seems like fish can distinguish prefixing a command with sudo

> sudo cap
airbrake:deploy                         (Capistrano task)  deploy:finishing_rollback

So my question is, how do I get the behavior of bundle exec to mirror sudo for the purpose of summoning completions with Tab?

CodePudding user response:

You can see how sudo does it here. It adds a completion which strips sudo and sudo-specific options from the command line, and then reinvokes complete -C to generate completions for this subcommand.

One way to get this working with bundle would be:

  1. Start with that sudo.fish file, copying it into ~/.config/fish/completions/bundle.fish.
  2. Edit that file to replace references to sudo with bundle.
  3. Remove sudo-specific arguments and add any you want for bundle.

The sudo.fish file is probably already installed at /usr/local/share/fish/completions/sudo.fish or you may download it from GitHub.

The docs on writing your own completions are a good reference.

  • Related