Skip to content

Instantly share code, notes, and snippets.

@kunalb
Last active April 30, 2024 22:48
Show Gist options
  • Save kunalb/abfe5757e89ffba1cf3959c9543d9ac0 to your computer and use it in GitHub Desktop.
Save kunalb/abfe5757e89ffba1cf3959c9543d9ac0 to your computer and use it in GitHub Desktop.
zsh + tmux + fzf + rg - autocomplete words in command
function _print_all_panes() {
for pane_id in $(tmux list-panes -F '#{pane_id}'); do
tmux capture-pane -p -J -S 0 -E - -t "$pane_id" | tr ' ' '\n' | sort -u | rg '[a-zA-Z0-9]+'
done
}
_tmux_pane_words() {
local current_word="${LBUFFER##* }"
local new_rbuffer="${RBUFFER/#[^ ]##/}"
local prompt="${LBUFFER% *} ␣ $new_rbuffer "
local selected_word=$(_print_all_panes | fzf --query="$current_word" --prompt="$prompt" --height=20 --layout=reverse --no-sort --print-query | tail -n1)
local new_lbuffer="${LBUFFER% *} $selected_word"
BUFFER="$new_lbuffer$new_rbuffer"
CURSOR="${#${new_lbuffer}}"
zle redisplay
}
zle -N _tmux_pane_words
bindkey '^U' _tmux_pane_words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment