Skip to content
Myr

Fuzzy completion using fzf-tmux

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 40180c1 · Browse files · 2 files+13 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−6 removed

  • other:+13 added−6 removed

2 files+13 added−6 removed

modified:shell/completion.bash+10 added-6 removed
4 unmodified lines
5# / __/ / /_/ __/6# /_/ /___/_/-completion.bash7#8# - $FZF_COMPLETION_TRIGGER (default: '**')9# - $FZF_COMPLETION_TMUX (default: 1)10# - $FZF_COMPLETION_OPTS (default: empty)1112_fzf_orig_completion_filter() {13 sed 's/.*-F *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\2=\1;/' |
51 unmodified lines
65 fi66}6768_fzf_path_completion() {68 local cur base dir leftover matches trigger cmd69 local cur base dir leftover matches trigger cmd fzf70 [ ${FZF_COMPLETION_TMUX:-1} -eq 1 ] && fzf="fzf-tmux" || fzf="fzf"71 cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')72 COMPREPLY=()73 trigger=${FZF_COMPLETION_TRIGGER:-**}74 cur="${COMP_WORDS[COMP_CWORD]}"
7 unmodified lines
82 leftover=${base/#"$dir"}83 leftover=${leftover/#\/}84 [ "$dir" = './' ] && dir=''85 tput sc84 matches=$(find -L "$dir"* $1 2> /dev/null | fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do86 matches=$(find -L "$dir"* $1 2> /dev/null | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do87 printf "%q$3 " "$item"88 done)89 matches=${matches% }90 if [ -n "$matches" ]; then
15 unmodified lines
106 fi107}108109_fzf_list_completion() {108 local cur selected trigger cmd src110 local cur selected trigger cmd src fzf111 [ ${FZF_COMPLETION_TMUX:-1} -eq 1 ] && fzf="fzf-tmux" || fzf="fzf"112 read -r src113 cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')114 trigger=${FZF_COMPLETION_TRIGGER:-**}115 cur="${COMP_WORDS[COMP_CWORD]}"116 if [[ ${cur} == *"$trigger" ]]; then117 cur=${cur:0:${#cur}-${#trigger}}118119 tput sc117 selected=$(eval "$src | fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ')120 selected=$(eval "$src | $fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ')121 selected=${selected% }122 tput rc123124 if [ -n "$selected" ]; then
26 unmodified lines
151152_fzf_kill_completion() {153 [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1154152 local selected155 local selected fzf156 [ ${FZF_COMPLETION_TMUX:-1} -eq 1 ] && fzf="fzf-tmux" || fzf="fzf"157 tput sc154 selected=$(ps -ef | sed 1d | fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ')158 selected=$(ps -ef | sed 1d | $fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ')159 tput rc160161 if [ -n "$selected" ]; then162 COMPREPLY=( "$selected" )
84 unmodified lines
modified:README.md+3 added
254 unmodified lines
255export FZF_COMPLETION_TRIGGER='~~'256257# Options to fzf command258export FZF_COMPLETION_OPTS='+c -x'259260# Not to use tmux pane261export FZF_COMPLETION_TMUX=0262```263264Usage as Vim plugin265-------------------
250 unmodified lines