Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(autocomplete): adding autocomplete in README.md #27

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,21 @@ pod "coredns-78fcd69978-xwdt4" deleted

## Shell completion
You can read more the [issue](https://github.com/rumstead/kubectl-safe/issues/17)
### ZSH
Add the below script anywhere in your path with the executable bit set.
```shell
alias ks="kubectl safe"
functions[_kubectl-og]=$functions[_kubectl]

_kubectl() {
words[$words[(i)safe]]=()
_kubectl-og "$words[*]"
}
#!/usr/bin/env bash

# If we are completing a flag, use Cobra's builtin completion system.
# To know if we are completing a flag we need the last argument starts with a `-` and does not contain an `=`
args=("$@")
lastArg=${args[((${#args[@]}-1))]}
if [[ "$lastArg" == -* ]]; then
if [[ "$lastArg" != *=* ]]; then
kubectl safe __complete "$@"
fi
else
kubectl __complete "$@"
fi
```

## Configuration
Expand Down
Loading