Skip to content

Instantly share code, notes, and snippets.

@fqxp
Created September 4, 2020 10:17
Show Gist options
  • Save fqxp/d51dbf73dc1e8f09b6dca164fff14700 to your computer and use it in GitHub Desktop.
Save fqxp/d51dbf73dc1e8f09b6dca164fff14700 to your computer and use it in GitHub Desktop.
Zsh completion for words from all tmux panes using FZF
_complete_tmux_pane_words() {
local -a w
if [[ -z "$TMUX_PANE" ]]; then
_message "not running inside tmux!"
return 1
fi
_tmux_capture_pane() {
tmux capture-pane -J -p $@ |
sed -e 'p;s/[^a-zA-Z0-9_]/ /g' |
tr -s '[:space:]' '\n' |
grep -o "\w.*\w"
}
local i
for i in $(tmux list-panes -a -F '#D') ; do
w+=$(_tmux_capture_pane -t "$i")
done
w=$(echo -n "$w" | sort | uniq)
local selected=$(echo ${w} | fzf --height='25%' --reverse --prompt="tmux> ")
LBUFFER="${LBUFFER}${selected}"
zle reset-prompt
return 0
}
zle -N complete-fzf-pane-words _complete_tmux_pane_words
bindkey ^x^x complete-fzf-pane-words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment