Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
Created tiup_completion.bash to support tiup components
Browse files Browse the repository at this point in the history
make bash-autocompletion works for tiup components(ie. cluster, br).
Current TiUP native bash-autocompletion does not support them

Refer pingcap/tiup#606

- `cluster` and `br` compoments supported, others may be coming

- Usage

```
$ source /path/to/tiup_completion.bash
$ tiup <TAB>
bench           cdc             client          completion      dm              env             help            list            pd-recover      status          tidb            uninstall
br              clean           cluster         ctl             dmctl           errdoc          install         mirror          playground      telemetry       tidb-lightning  update
$ tiup c<TAB>
cdc         clean       client      cluster     completion  ctl
$ tiup cluster <TAB>
audit        clean        destroy      display      enable       import       patch        reload       replay       scale-in     start        template
check        deploy       disable      edit-config  help         list         prune        rename       restart      scale-out    stop         upgrade
```

Thanks to
https://stackoverflow.com/questions/17879322/how-do-i-autocomplete-nested-multi-level-subcommands
  • Loading branch information
yahonda committed Aug 27, 2021
1 parent 9fff865 commit 636f5ee
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tiup_completion.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

_tiup()
{
local cur prev

cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}


case ${COMP_CWORD} in
1)
COMPREPLY=( $(compgen -W "bench br cdc client cluster ctl dm dmctl errdoc pd-recover playground tidb tidb-lightning \
clean completion env help install list mirror status telemetry uninstall update" -- $cur) )
;;
2)
case ${prev} in
cluster)
COMPREPLY=($(compgen -W "check deploy start stop restart scale-in scale-out destroy clean upgrade display prune \
list audit import edit-config reload patch rename enable disable replay template help" -- $cur) )
;;
br)
COMPREPLY=($(compgen -W "backup help restore" -- $cur) )
;;
esac
;;
3)
COMPREPLY=()
;;
esac
}

complete -F _tiup tiup

0 comments on commit 636f5ee

Please sign in to comment.