Skip to content

Conditional Behavior on Selecting Item (on "Enter") #4446

Answered by LangLangBart
norsemangrey asked this question in Q&A
Discussion options

You must be logged in to vote

I'm trying to make the behavior of hitting the Enter on an item in the list conditional

The transform action was introduced in version 0.45.0. It allows the user to evaluate a
condition and then perform either action A or action B, depending on the result.

# demo
# 1. list is loaded up on starting
# 2. if the remainder is non-zero (FZF_POS is odd) on pressing Enter => `accept`
# 3. if the remainder is zero (FZF_POS is even) => `preview(...`
FZF_DEFAULT_OPTS= fzf \
  --bind 'start:reload:seq 4' \
  --bind 'enter:transform:((FZF_POS % 2)) && echo "accept" || echo "preview:echo \{}"' \
  --with-shell 'bash -c'

EDIT: Escaped {}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@junegunn
Comment options

@LangLangBart
Comment options

Answer selected by junegunn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants