diff --git a/functions/_tide_item_kubectl.fish b/functions/_tide_item_kubectl.fish index 4532371..52a7f1f 100644 --- a/functions/_tide_item_kubectl.fish +++ b/functions/_tide_item_kubectl.fish @@ -18,7 +18,7 @@ function _tide_item_kubectl # exist, or the file didn't parse as expected -- let kubectl itself # figure it out. kubectl config view --minify --output 'jsonpath={.current-context}/{..namespace}' 2>/dev/null | read -l context && - _tide_print_item kubectl $tide_kubectl_icon' ' (string replace -r '/(|default)$' '' $context) + _tide_print_item kubectl $tide_kubectl_icon' ' (string replace -r '/(|default)$' '' -- $context) return end diff --git a/tests/_tide_item_kubectl.test.fish b/tests/_tide_item_kubectl.test.fish index f45c372..f36f845 100644 --- a/tests/_tide_item_kubectl.test.fish +++ b/tests/_tide_item_kubectl.test.fish @@ -17,6 +17,11 @@ _kubectl # CHECK: ⎈ curr-context mock kubectl "config view --minify --output" "echo curr-context/" _kubectl # CHECK: ⎈ curr-context +# regression: a context name starting with "-" must not be read as an +# option by the `string replace` that strips the trailing "/default" +mock kubectl "config view --minify --output" "echo -curr-context/default" +_kubectl # CHECK: ⎈ -curr-context + mock kubectl "config view --minify --output" "echo curr-context/curr-namespace" _kubectl # CHECK: ⎈ curr-context/curr-namespace