bazelisk icon indicating copy to clipboard operation
bazelisk copied to clipboard

Support bash autocomplete

Open evie404 opened this issue 6 years ago • 17 comments

Since bazelisk downloads entire binaries, autocomplete scripts are not accessible. bazelisk could potentially also download the autocomplete scripts to a predetermined location to make it easier invoke.

evie404 avatar Feb 12 '19 00:02 evie404

+1, this will be excellent to have.

jin avatar Mar 29 '19 16:03 jin

I suppose you can do this manually with instructions from https://docs.bazel.build/versions/master/completion.html#bash

$ bazel build //scripts:bazel-complete.bash
$ cp bazel-bin/scripts/bazel-complete.bash /etc/bash_completion.d/bazelisk

# new shell
$ bazelisk <TAB>
analyze                                                 --nodeep_execroot 
analyze-profile                                         --noexoblaze 
aquery                                                  --noexpand_configs_in_place 
--batch                                                 --noexperimental_oom_more_eagerly 
--batch_cpu_scheduling                                  --noidle_server_tasks 
--blazerc=                                              --noignore_all_rc_files 
..

jin avatar Mar 29 '19 16:03 jin

yeah that's what i ended up doing... I was hoping something like a bundled bash completion script that bazelisk could provide, but it's not super blocking

evie404 avatar Mar 29 '19 20:03 evie404

I would love to have this myself, but currently don't have time to implement this - if someone wants to contribute a PR, I would be very happy to review it.

philwo avatar Jun 19 '19 06:06 philwo

I'll take a stab at this when I have time over the next few days.

sudoforge avatar Mar 19 '20 19:03 sudoforge

@sudoforge Thanks! If you could find a solution that also works with zsh completions, I'd be extra grateful 😊 (I was a long-time bash user, but since macOS Catalina switched to zsh by default, I gave it a try and stuck with it.)

philwo avatar Mar 20 '20 08:03 philwo

I'll be looking to add completion for all shells that Bazel supports -- off the top of my head, I think that's just Bash and ZSH.

sudoforge avatar Mar 20 '20 14:03 sudoforge

+1 would be super useful to have

finn-ball avatar Mar 30 '20 11:03 finn-ball

FWIW this is done now for zsh on Homebrew installs of bazelisk: https://github.com/bazelbuild/homebrew-tap/pull/89

gibfahn avatar May 27 '20 12:05 gibfahn

I've got it working on my mac using zsh but it's painfully slow. Are others experiencing the same?

UebelAndre avatar Apr 02 '21 21:04 UebelAndre

I've got it working on my mac using zsh but it's painfully slow. Are others experiencing the same?

Having done some comparisons between bazel and bazelisk using zsh completion on my mac, bazelisk is orders of magnitude slower.

UebelAndre avatar Jun 16 '21 00:06 UebelAndre

Having done some comparisons between bazel and bazelisk using zsh completion on my mac, bazelisk is orders of magnitude slower.

I wonder if https://github.com/bazelbuild/bazelisk/pull/248 would improve this

UebelAndre avatar Jul 02 '21 05:07 UebelAndre

I've given some thought to this and will be sending a PR out in the next few days with a proposed solution.

... two years later. Oh, life, how structured you are. :)

sudoforge avatar Mar 12 '22 01:03 sudoforge

Any update here? I'd be glad to help if I can.

rpwoodbu avatar Jul 15 '22 22:07 rpwoodbu

@sudoforge Is this still something you're planning to open?

andrewring avatar May 01 '23 17:05 andrewring

Here's the workaround I'm using in case this is useful to anybody else.

curl -fsSL https://raw.githubusercontent.com/bazelbuild/bazel/$(cat .bazelversion)/scripts/bazel-complete-header.bash >> ~/.bashrc
curl -fsSL https://raw.githubusercontent.com/bazelbuild/bazel/$(cat .bazelversion)/scripts/bazel-complete-template.bash >> ~/.bashrc
bazel help completion >> ~/.bashrc

ashwin153 avatar Aug 28 '23 20:08 ashwin153

I was looking at this briefly, and my assumption as to what needs to be done:

  • Update DownloadRelease to also fetch the auto-complete scripts
  • To get the auto-complete scripts, the source needs to be downloaded (e.g. https://releases.bazel.build/6.0.0/release/bazel_6.0.0.tar.gz), and for simplicity probably just extract the entire "scripts/" directory (which includes bazel-complete-header.bash and such, and other auto-completes).
  • Make that scripts/ sub-directory available in a deterministic place, so switching bazel versions also switches the underlying scripts

Seem reasonable to others?

kylepl avatar Mar 25 '24 14:03 kylepl