Created
January 29, 2026 22:27
-
-
Save ponimas/bb868a65ea119b6b1c9f2ea5e1362437 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| declare -g _PREVIOUS_COMMAND="" | |
| # Only setup if vterm_cmd is available | |
| if (( ${+functions[vterm_cmd]} )); then | |
| _update-modeline() { | |
| # Get the current zle buffer (what user typed) | |
| local buffer=$BUFFER | |
| local cmd_name="${buffer%% *}" | |
| [[ $_PREVIOUS_COMMAND == $cmd_name ]] && return || _PREVIOUS_COMMAND=$cmd_name | |
| # Check if user is typing specific commands | |
| case $cmd_name in | |
| # Show kubernetes context while typing k8s commands | |
| kubectl|zkubectl|k9s) | |
| # kubectl is slow https://github.com/kubernetes/kubernetes/issues/92382 | |
| # local context = $(kubectl config current-context 2>/dev/null) | |
| local context=$(awk '/^current-context:/{print $2;exit;}' <~/.kube/config) | |
| vterm_cmd modeline "☸ $context" | |
| ;; | |
| *) | |
| vterm_cmd modeline " " | |
| ;; | |
| esac | |
| } | |
| zle -N zle-line-pre-redraw _update-modeline | |
| add-zsh-hook -Uz precmd (){ | |
| _PREVIOUS_COMMAND="" | |
| vterm_cmd modeline " " | |
| } | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment