Created
July 20, 2022 06:58
-
-
Save refnode/9c9e9ec4e2fdc9db9020bb7af5426226 to your computer and use it in GitHub Desktop.
zsh-zle-fzf-kubernetes-widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# small basic example to fetch all pods from k8s and fetch the pod definition into your vim | |
# alternative use 'bat' as cat replacement for great yaml syntax highlighting | |
fzf-kubectl-get-pods-widget() { | |
local selected namespace pod | |
local cmd="kubectl get pods -A" | |
local selected=( $(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m)) | |
local ret=$? | |
if [ -n "$selected" ]; then | |
namespace=$selected[1] | |
pod=$selected[2] | |
zle push-line # Clear buffer. Auto-restored on next prompt. | |
BUFFER="kubectl get pod -n $namespace $pod --output=yaml | nvim -c 'set filetype=yaml' -" | |
zle accept-line | |
fi | |
unset selected namespace pod | |
zle reset-prompt | |
return $ret | |
} | |
# declare the function as a new widget | |
zle -N fzf-kubectl-get-pods-widget | |
# and bind the vi insert mode keymap as '<leader>kgp' (space as "leader") to this widget | |
bindkey -M viins ' kgp' fzf-kubectl-get-pods-widget |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment