Shortening the Kubectl prompt in Fish Tide
Quick notes for making a shorter Kubectl context prompt in Tide
Prompt items are controlled by these variables:
$ echo $tide_left_prompt_items
vi_mode pwd git
$ echo $tide_right_prompt_items
status cmd_duration context jobs direnv node python rustc java
php pulumi ruby go gcloud kubectl distrobox toolbox terraform
aws nix_shell crystal elixir zig time
You can find the functions in .config/fish/functions
with _tide_item_
prefix
The default kubectl function shows the full context. Working with Amazon EKS this is pretty long and I’m just interested in the last parts
~/.config/fish/functions/_tide_item_kubectl_short.fish
:
function _tide_item_kubectl_short
kubectl config view --minify --output 'jsonpath={.current-context}/{..namespace}' 2>/dev/null | read -l context
if test -n "$context"
# Remove everything up to and including the first slash
set short_context (string replace -r '^[^/]+/' '' $context)
set_color $tide_kubectl_color
_tide_print_item kubectl "$tide_kubectl_icon $short_context"
set_color normal
end
end
Update the function
source ~/.config/fish/functions/_tide_item_kubectl_short.fish
Replace the kubectl with kubectl_short in the config
set -U tide_right_prompt_items (string replace -r '\bkubectl\b' 'kubectl_short' $tide_right_prompt_items)
fish_prompt