Created
June 18, 2018 16:00
-
-
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
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
__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