Autocomplete for Bench and how to use it

A fellow community member added functionality to use autocomplete on bash / zsh in this PR Autocompletion for bench (zsh and bash) by adityahase · Pull Request #705 · frappe/bench · GitHub <3

However, it doesn’t explain how to use this. I made this post for people who aren’t well versed in the terminal.

It’s pretty straightforward.

  • Update your bench repository to the latest by running bench update or manually pulling the repo
  • There will be a file called completion.sh in that folder now. Make note of it’s path
  • Open your .zshrc or .bashrc file which will be in your home directory and add the line :
    • source <path to completion.sh file>
  • Run source ~/.zshrc or ~/.bashrc to load the new config (This is just to load this config in the existing terminal, creating a new one will automatically load the config)
  • Enjoy auto-complete!

Autocomple works for all commands and it will also auto-populate sites if you’re in the bench folder.

9 Likes

I have posted a single line explanation here I thought these steps were trivial, So didn’t include any instructions.

It is too slow as of now though. It actually executes the python script (in this case bench itself) upon setting a magic environment variable to generate suggestions.

I’ve observed how other command line utilities do this, e.g. git. It’s a little painful to write and update a shell script for completions (instead of a click hack) which is somewhat necessary to improve the speed.

I’ll (probably) soon provide you with a faster completion method.

3 Likes