From b6d49d3d8c766931fb662d0eb3582c4551938381 Mon Sep 17 00:00:00 2001 From: Luna Komorebi Date: Wed, 8 Nov 2023 01:25:32 +0100 Subject: [PATCH] Add lazy loading for kubectl auto-completion --- .zsh/autocompletion.zsh | 5 ----- .zsh/lazy.sh | 19 +++++++++++++++++++ .zshrc | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) delete mode 100644 .zsh/autocompletion.zsh create mode 100644 .zsh/lazy.sh diff --git a/.zsh/autocompletion.zsh b/.zsh/autocompletion.zsh deleted file mode 100644 index 1562b03..0000000 --- a/.zsh/autocompletion.zsh +++ /dev/null @@ -1,5 +0,0 @@ -autoload -Uz compinit && compinit - -if type "kubectl" > /dev/null; then - source <(kubectl completion zsh) -fi \ No newline at end of file diff --git a/.zsh/lazy.sh b/.zsh/lazy.sh new file mode 100644 index 0000000..5166a1f --- /dev/null +++ b/.zsh/lazy.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env zsh + +# Check if 'kubectl' is a command in $PATH +if [ $commands[kubectl] ]; then + + # Placeholder 'kubectl' shell function: + # Will only be executed on the first call to 'kubectl' + kubectl() { + + # Remove this function, subsequent calls will execute 'kubectl' directly + unfunction "$0" + + # Load auto-completion + source <(kubectl completion zsh) + + # Execute 'kubectl' binary + $0 "$@" + } +fi diff --git a/.zshrc b/.zshrc index 3eaf37c..7670cbe 100644 --- a/.zshrc +++ b/.zshrc @@ -1,3 +1,5 @@ +DISABLE_AUTO_UPDATE=true + iscmd() { command -v "$1" > /dev/null }