Add basic bash completion

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2017-04-04 12:05:28 -07:00
parent ad4b22b8c3
commit 17b32b1f64
No known key found for this signature in database
GPG Key ID: 3300B90BF29C804E
3 changed files with 31 additions and 4 deletions

View File

@ -31,11 +31,11 @@ Context "dublin" set.
Aliased "gke_ahmetb_europe-west1-b_dublin" as "dublin".
```
## Help wanted
[**Set up `bash` completion &rarr;**](completion/README.md)
- [ ] bash completion
- [ ] zsh completion
- [ ] homebrew formula/tap
### Help wanted
[ ] homebrew formula/tap
-----

19
completion/README.md Normal file
View File

@ -0,0 +1,19 @@
kubectx provides shell completion scripts to complete context names, making it
even faster to switch between contexts easily.
## Bash setup
Copy the `kubectx.bash` file to your HOME directory:
cp kubectx.bash ~/.kubectx.bash
And source it in your `~/.bashrc` file by adding the line:
[ -f ~/.kubectx.bash ] && source ~/.kubectx.bash
Start a new shell, type `kubectx`, then hit <kbd>Tab</kbd> to see the existing
contexts.
You can Add `TAB: menu-complete` to your `~/.inputrc` to cycle through the
options with <kbd>Tab</kbd>.

8
completion/kubectx.bash Normal file
View File

@ -0,0 +1,8 @@
_kube_contexts()
{
local curr_arg;
curr_arg=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "- $(kubectl config get-contexts | awk '{print $2}' | tail -n +2)" -- $curr_arg ) );
}
complete -F _kube_contexts kubectx