Automatically generated shell autocomplete for bosh-cli (bash, zsh, fish, powershell):
- Utilizes Cobra for autocompletion, loading the Cobra command tree from
bosh-cli
via reflection. - Session is compatible with
bosh-cli
(it uses environment variables and flags in the same manner). - Offers cacheable suggestions for deployment names and other parameters, as querying the
Bosh Director API
can be time-consuming and the results don't update frequently.
Cobra is used in many Go projects such as Kubernetes, Hugo, and GitHub CLI to name a few. This list contains a more extensive list of projects using Cobra.
Check out this solution and consider voting for it to be merged into the main bosh-cli repo
- Add these lines to
.bashrc
:bosh_switch() { if [ "$1" == "completion" ] || [ "$1" == "__complete" ]; then \bosh-cli-completion "$@" else \bosh "$@" fi } source <(\bosh-cli-completion completion bash) alias bosh=bosh_switch alias b=bosh_switch complete -o default -F __start_bosh b
- Restart shell
- Type
bosh -d
andTAB key
- Wait a moment to give time to query the Bosh Director API, the response will be cached for 15s.
- Type
TAB key
again. - For example:
b -d cf ssh <TAB> api log-api api/eb477fea-77dd-4833-bb62-e9025595f020 log-api/22074b77-5a65-47c4-add5-fab4f8165b2c api/c03f3d40-e878-42d4-85d7-1aeeac2bc96a log-api/1b7b4364-0cb5-48b0-bb76-9f96ace90d28 ...
bosh-cli-completion completion -help
Generate the autocompletion script for bosh for the specified shell. See each sub-command's help for details on how to use the generated script.
bosh-cli-completion completion [shell]
Available Shells:
bash
Generate the autocompletion script for bashfish
Generate the autocompletion script for fishpowershell
Generate the autocompletion script for powershellzsh
Generate the autocompletion script for zsh
bosh-cli-completion completion bash/fish/powershell/zsh --help
go test bosh-cli-completion/cmd/completion
./build.sh
- Add these environment variables:
export BOSH_LOG_LEVEL=debug export BOSH_LOG_PATH=~/.bosh/log/bosh-cli-debug.log
- Restart shell
- Watch logs
tail -f ~/.bosh/log/bosh-cli-debug.log
- Type
bosh -d
andTAB key