Skip to content

Instantly share code, notes, and snippets.

@yyogo
Created June 18, 2018 16:00
Show Gist options
  • Save yyogo/781b2cf8a6e616774969508039721022 to your computer and use it in GitHub Desktop.
Save yyogo/781b2cf8a6e616774969508039721022 to your computer and use it in GitHub Desktop.
fzf completion widget for zsh which completes words from the currently displayed tmux panes
__get_tmux_pane_contents() {
local cmd='for pane in `tmux list-panes -F "#{pane_id}"`; do tmux capture-pane -p -t $pane; done'
for word in `eval "$cmd"`; do
if [ ${#word} -ge ${FZF_MIN_WORD_LENGTH:-4} ]; then
echo "$word"
fi
done | awk '{ print length, $0 }' | sort -rn | cut -d' ' -f2- | uniq
}
__tmux_pane_sel() {
setopt localoptions pipefail 2> /dev/null
__get_tmux_pane_contents | FZF_DEFAUL_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS" $(__fzfcmd) -m "$@"
local ret=$?
echo
return $ret
}
fzf-complete-pane-widget() {
LBUFFER="${LBUFFER}$(__tmux_pane_sel)"
local ret="$?"
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
zle -N fzf-complete-pane-widget
bindkey '^X^A' fzf-complete-pane-widget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment