From 1c6f5161425d6517c3fc3041efddd3da82171840 Mon Sep 17 00:00:00 2001 From: xero Date: Wed, 5 Jul 2023 09:52:33 -0400 Subject: [PATCH] feat(tmux): add support for fzf-tmux in interactive mode --- README.md | 5 +++-- kubectx | 4 +++- kubens | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6b9e29b..d3755ec 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,8 @@ Active namespace is "default". If you have [`fzf`](https://github.com/junegunn/fzf) installed, you can also **interactively** select a context or cluster, or fuzzy-search by typing a few -characters. To learn more, read [interactive mode →](#interactive-mode) +characters. To learn more, read [interactive mode →](#interactive-mode). +Additionally, if you are running under [`TMUX`](https://github.com/tmux/tmux), `fzf-tmux` will be used. Both `kubectx` and `kubens` support Tab completion on bash/zsh/fish shells to help with long context names. You don't have to remember full context @@ -196,7 +197,7 @@ Depending on your setup, you might or might not need to call `compinit` or `autoload -U compinit && compinit` in your `~/.zshrc` after you load the Plugins file. If you use [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh), load the completions before you load `oh-my-zsh` because `oh-my-zsh` will call -`compinit`. +`compinit`. #### Completion scripts for plain `zsh` diff --git a/kubectx b/kubectx index 12ea40c..d7bf945 100755 --- a/kubectx +++ b/kubectx @@ -113,9 +113,11 @@ switch_context() { choose_context_interactive() { local choice + local FZF='fzf' + [[ -n "${TMUX-}" ]] && FZF="fzf-tmux" choice="$(_KUBECTX_FORCE_COLOR=1 \ FZF_DEFAULT_COMMAND="${SELF_CMD}" \ - fzf --ansi --no-preview || true)" + ${FZF} --ansi --no-preview || true)" if [[ -z "${choice}" ]]; then echo 2>&1 "error: you did not choose any of the options" exit 1 diff --git a/kubens b/kubens index 8d5df32..199d119 100755 --- a/kubens +++ b/kubens @@ -114,9 +114,11 @@ choose_namespace_interactive() { fi local choice + local FZF='fzf' + [[ -n "${TMUX-}" ]] && FZF="fzf-tmux" choice="$(_KUBECTX_FORCE_COLOR=1 \ FZF_DEFAULT_COMMAND="${SELF_CMD}" \ - fzf --ansi --no-preview || true)" + ${FZF} --ansi --no-preview || true)" if [[ -z "${choice}" ]]; then echo 2>&1 "error: you did not choose any of the options" exit 1