From 481941884cd0b51805c0d3abb7a48aebe6478c10 Mon Sep 17 00:00:00 2001 From: rumstead <37445536+rumstead@users.noreply.github.com> Date: Thu, 18 Apr 2024 12:07:35 -0400 Subject: [PATCH] docs(autocomplete): adding autocomplete in README.md Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3f31d26..efe27bc 100644 --- a/README.md +++ b/README.md @@ -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