Last active
April 30, 2024 22:48
-
-
Save kunalb/abfe5757e89ffba1cf3959c9543d9ac0 to your computer and use it in GitHub Desktop.
zsh + tmux + fzf + rg - autocomplete words in command
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
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