Skip to content

Commit

Permalink
"fuzzy-snippets": Improve UX when aborting fzf.
Browse files Browse the repository at this point in the history
  • Loading branch information
damiendart committed Jul 1, 2024
1 parent 8064b43 commit 6611c37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .vim/plugin/fuzzy-finders.vim
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ function! s:FuzzySnippets() abort

let l:output = join(a:input[1:], "\n")

if len(l:output) == 0
return
endif

if a:input[0] ==? 'ctrl-y'
call setreg('"', l:output)

Expand Down
16 changes: 16 additions & 0 deletions bin/fuzzy-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ if [ "$VIM_MODE" = 1 ]; then
FZF_LABEL='ENTER: insert ╱ CTRL+Y: yank ╱ F1: help'
fi

set +e

# CTRL+Z process suspension is suppressed as it doesn't work properly
# (see <https://github.com/junegunn/fzf/issues/2289>).
FZF_OUTPUT=$(\
Expand All @@ -157,6 +159,20 @@ FZF_OUTPUT=$(\
--scheme='path' \
--with-nth='-1' \
)
FZF_STATUS="$?"

if [ "$FZF_STATUS" != 0 ]; then
# Allow this script to exit cleanly if fzf exits with a return code of
# 130, signalling that it was aborted or interrupted by the user.
if [ "$FZF_STATUS" = 130 ]; then
exit
else
exit $FZF_STATUS
fi
fi

set -e

SELECTED_ACTION=$(echo "$FZF_OUTPUT" | head -1)
SELECTED_FILE=$(echo "$FZF_OUTPUT" | tail -1)

Expand Down

0 comments on commit 6611c37

Please sign in to comment.