Skip to content

Commit 8206746

Browse files
committed
[completion] _fzf_complete_COMMAND_post for post processing
e.g. _fzf_complete_foo() { _fzf_complete "--multi --reverse --header-lines=3" "$@" < <( ls -al ) } _fzf_complete_foo_post() { awk '{print $NF}' } [ -n "$BASH" ] && complete -F _fzf_complete_foo -o default -o bashdefault foo
1 parent ce9c51d commit 8206746

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

shell/completion.bash

+4-11
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,10 @@ __fzf_generic_path_completion() {
156156
fi
157157
}
158158
159-
_fzf_feed_fifo() (
160-
rm -f "$fifo"
161-
mkfifo "$fifo"
162-
cat <&0 > "$fifo" &
163-
)
164-
165159
_fzf_complete() {
166-
local fifo cur selected trigger cmd fzf
167-
fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$"
160+
local cur selected trigger cmd fzf post
161+
post="$(caller 0 | awk '{print $2}')_post"
162+
type -t $post > /dev/null 2>&1 || post=cat
168163
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
169164
170165
cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')
@@ -173,12 +168,10 @@ _fzf_complete() {
173168
if [[ ${cur} == *"$trigger" ]]; then
174169
cur=${cur:0:${#cur}-${#trigger}}
175170
176-
_fzf_feed_fifo "$fifo"
177171
tput sc
178-
selected=$(eval "cat '$fifo' | $fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ')
172+
selected=$(cat | $fzf $FZF_COMPLETION_OPTS $1 -q "$cur" | $post | tr '\n' ' ')
179173
selected=${selected% } # Strip trailing space not to repeat "-o nospace"
180174
tput rc
181-
rm -f "$fifo"
182175
183176
if [ -n "$selected" ]; then
184177
COMPREPLY=("$selected")

shell/completion.zsh

+5-11
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,20 @@ _fzf_dir_completion() {
7979
"" "/" ""
8080
}
8181
82-
_fzf_feed_fifo() (
83-
rm -f "$fifo"
84-
mkfifo "$fifo"
85-
cat <&0 > "$fifo" &
86-
)
87-
8882
_fzf_complete() {
89-
local fifo fzf_opts lbuf fzf matches
90-
fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$"
83+
local fzf_opts lbuf fzf matches post
9184
fzf_opts=$1
9285
lbuf=$2
86+
post="${funcstack[2]}_post"
87+
type $post > /dev/null 2>&1 || post=cat
88+
9389
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
9490
95-
_fzf_feed_fifo "$fifo"
96-
matches=$(cat "$fifo" | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "${(Q)prefix}" | tr '\n' ' ')
91+
matches=$(cat | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "${(Q)prefix}" | $post | tr '\n' ' ')
9792
if [ -n "$matches" ]; then
9893
LBUFFER="$lbuf$matches"
9994
fi
10095
zle redisplay
101-
rm -f "$fifo"
10296
}
10397
10498
_fzf_complete_telnet() {

0 commit comments

Comments
 (0)