diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2016-01-29 01:28:51 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2016-01-29 01:31:04 +0900 |
commit | 82067463b8263692147d80b6fc909f1d98693d88 (patch) | |
tree | 2abbd3e9cedda550a925c68331be418c0c1d8f95 /shell | |
parent | ce9c51d3997ca0fa4ac9ac77c5df94a0f82bfd80 (diff) |
[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
Diffstat (limited to 'shell')
-rw-r--r-- | shell/completion.bash | 15 | ||||
-rw-r--r-- | shell/completion.zsh | 16 |
2 files changed, 9 insertions, 22 deletions
diff --git a/shell/completion.bash b/shell/completion.bash index 9d84ce52..35b49a1e 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -156,15 +156,10 @@ __fzf_generic_path_completion() { fi } -_fzf_feed_fifo() ( - rm -f "$fifo" - mkfifo "$fifo" - cat <&0 > "$fifo" & -) - _fzf_complete() { - local fifo cur selected trigger cmd fzf - fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$" + local cur selected trigger cmd fzf post + post="$(caller 0 | awk '{print $2}')_post" + type -t $post > /dev/null 2>&1 || post=cat [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf" cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g') @@ -173,12 +168,10 @@ _fzf_complete() { if [[ ${cur} == *"$trigger" ]]; then cur=${cur:0:${#cur}-${#trigger}} - _fzf_feed_fifo "$fifo" tput sc - selected=$(eval "cat '$fifo' | $fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ') + selected=$(cat | $fzf $FZF_COMPLETION_OPTS $1 -q "$cur" | $post | tr '\n' ' ') selected=${selected% } # Strip trailing space not to repeat "-o nospace" tput rc - rm -f "$fifo" if [ -n "$selected" ]; then COMPREPLY=("$selected") diff --git a/shell/completion.zsh b/shell/completion.zsh index c7dee7ab..a1e1e079 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -79,26 +79,20 @@ _fzf_dir_completion() { "" "/" "" } -_fzf_feed_fifo() ( - rm -f "$fifo" - mkfifo "$fifo" - cat <&0 > "$fifo" & -) - _fzf_complete() { - local fifo fzf_opts lbuf fzf matches - fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$" + local fzf_opts lbuf fzf matches post fzf_opts=$1 lbuf=$2 + post="${funcstack[2]}_post" + type $post > /dev/null 2>&1 || post=cat + [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf" - _fzf_feed_fifo "$fifo" - matches=$(cat "$fifo" | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "${(Q)prefix}" | tr '\n' ' ') + matches=$(cat | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "${(Q)prefix}" | $post | tr '\n' ' ') if [ -n "$matches" ]; then LBUFFER="$lbuf$matches" fi zle redisplay - rm -f "$fifo" } _fzf_complete_telnet() { |