summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-04-22 12:02:28 +0300
committerPaul Buetow <paul@buetow.org>2025-04-22 12:02:28 +0300
commitb2644da5f869d0b3fc6de736fcdac4dd9c831682 (patch)
tree828ef8e7778b156322d45ee7056885738df9d549
parent801261a6109da76d46e0a95dc805a1ab6fb90cdc (diff)
add k8s fish
-rw-r--r--dotfiles/fish/conf.d/k8s.fish67
1 files changed, 67 insertions, 0 deletions
diff --git a/dotfiles/fish/conf.d/k8s.fish b/dotfiles/fish/conf.d/k8s.fish
new file mode 100644
index 0000000..c5dab1c
--- /dev/null
+++ b/dotfiles/fish/conf.d/k8s.fish
@@ -0,0 +1,67 @@
+if command -q -v kubectl >/dev/null
+ kubectl completion fish | source
+end
+
+# Check if the directory $HOME/.krew exists and update PATH
+if test -d $HOME/.krew
+ set -x PATH (set -q KREW_ROOT; and echo $KREW_ROOT; or echo $HOME/.krew)/bin $PATH
+end
+
+function kpod
+ set pattern "."
+ if test -n "$argv[1]"
+ set pattern "$argv[1]"
+ end
+ set -x POD (kubectl get pods | grep "$pattern" | sort -R | head -n 1 | cut -d' ' -f1)
+ echo "Pod is $POD"
+end
+
+function klogsf
+ if test -z "$POD" -o -n "$argv[1]"
+ kpod $argv
+ end
+ kubectl logs -f $POD
+end
+
+function klogs
+ if test -z "$POD" -o -n "$argv[1]"
+ kpod $argv
+ end
+ kubectl logs $POD
+end
+
+function kbash
+ if test -z "$POD" -o -n "$argv[1]"
+ kpod $argv
+ end
+ kubectl exec -it $POD -- /bin/bash
+end
+
+function kdesc
+ if test -z "$POD" -o -n "$argv[1]"
+ kpod $argv
+ end
+ kubectl describe pod $POD
+end
+
+function kedit
+ if test -z "$POD" -o -n "$argv[1]"
+ kpod $argv
+ end
+ kubectl edit pod $POD
+end
+
+function k8s::kubectl::config::contexts
+ kubectl config get-contexts | sed '1d; /\*/d' | awk '{ print $1 }' | sort
+end
+alias kcontexts="k8s::kubectl::config::contexts"
+
+function k8s::kubectl::config::use_context
+ kubectl config use-context (kubectl config get-contexts | sed '1d; /\*/d' | awk '{ print $1 }' | sort | fzf)
+end
+alias kcontext="k8s::kubectl::config::use_context"
+
+function k8s::kubectl::config::set_namespace
+ kubectl config set-context --current --namespace=(kubectl get ns | sed 1d | awk '{ print $1 }' | sort | fzf)
+end
+alias knamespace="k8s::kubectl::config::set_namespace"