From a4f3d09704364b6c1c496fa465cc4dc594f44159 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 14 Apr 2015 00:59:45 +0900 Subject: [PATCH] Fuzzy completion using fzf-tmux --- README.md | 3 +++ shell/completion.bash | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6f39e886..7b1bb4c5 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,9 @@ export FZF_COMPLETION_TRIGGER='~~' # Options to fzf command export FZF_COMPLETION_OPTS='+c -x' + +# Not to use tmux pane +export FZF_COMPLETION_TMUX=0 ``` Usage as Vim plugin diff --git a/shell/completion.bash b/shell/completion.bash index e609d2be..1a4426e7 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -6,6 +6,7 @@ # /_/ /___/_/-completion.bash # # - $FZF_COMPLETION_TRIGGER (default: '**') +# - $FZF_COMPLETION_TMUX (default: 1) # - $FZF_COMPLETION_OPTS (default: empty) _fzf_orig_completion_filter() { @@ -65,7 +66,8 @@ _fzf_handle_dynamic_completion() { } _fzf_path_completion() { - local cur base dir leftover matches trigger cmd + local cur base dir leftover matches trigger cmd fzf + [ ${FZF_COMPLETION_TMUX:-1} -eq 1 ] && fzf="fzf-tmux" || fzf="fzf" cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g') COMPREPLY=() trigger=${FZF_COMPLETION_TRIGGER:-**} @@ -81,7 +83,7 @@ _fzf_path_completion() { leftover=${leftover/#\/} [ "$dir" = './' ] && dir='' tput sc - matches=$(find -L "$dir"* $1 2> /dev/null | fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do + matches=$(find -L "$dir"* $1 2> /dev/null | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do printf "%q$3 " "$item" done) matches=${matches% } @@ -105,7 +107,8 @@ _fzf_path_completion() { } _fzf_list_completion() { - local cur selected trigger cmd src + local cur selected trigger cmd src fzf + [ ${FZF_COMPLETION_TMUX:-1} -eq 1 ] && fzf="fzf-tmux" || fzf="fzf" read -r src cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g') trigger=${FZF_COMPLETION_TRIGGER:-**} @@ -114,7 +117,7 @@ _fzf_list_completion() { cur=${cur:0:${#cur}-${#trigger}} tput sc - selected=$(eval "$src | fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ') + selected=$(eval "$src | $fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ') selected=${selected% } tput rc @@ -149,9 +152,10 @@ _fzf_dir_completion() { _fzf_kill_completion() { [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1 - local selected + local selected fzf + [ ${FZF_COMPLETION_TMUX:-1} -eq 1 ] && fzf="fzf-tmux" || fzf="fzf" tput sc - selected=$(ps -ef | sed 1d | fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ') + selected=$(ps -ef | sed 1d | $fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ') tput rc if [ -n "$selected" ]; then