Enable auto-completion for Solana CLI

If you are using the command-line tool for Solana blockchain, you may be tired from remembering and typing its subcommands and options. How to get auto-completion for it?

Thank to great Rust libraries, Solana CLI automatically has a feature to generate auto-completion scripts. It is just that the feature is not mentioned in documentation yet. To generate this script for your shell, just run:

$ solana completion -s <your-shell>

For example, I use Zsh shell, so my command is:

$ solana completion -s zsh

The script content is returned via standard output, you need to save to some file and config your shell to "source" it. How to do is different from shell to shell. Following is my example with Zsh.

In my setup, (and just my personal taste), I have a folder ~/.local/share/zsh_extras/zfunc to contain auto-completion scripts for various tools. The folder is declared to Zsh as specified in .zshrc:

fpath=(~/.local/share/zsh_extras/zfunc $fpath)

To enable auto-completion for Solana CLI, I just need to dump the script to this folder:

$ solana completion -s zsh > ~/.local/share/zsh_extras/zfunc/_solana

Done. Now open new Terminal window, the solana command can be auto-complete.