Conditional Behavior on Selecting Item (on "Enter") #4446
-
I'm trying to make the behavior of hitting the Enter on an item in the list conditional, so that in one case nothing will happen except that the preview will be updated with some additional text, and in the other case the behavior should be as normal when hitting the "Enter" key (i.e. exit fzf and insert the section). However, I am not able to make it work, with the below attempt FZF exits in both cases. Is it even possible? Appreciate any tips to get in the right direction =)
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The # 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 |
Beta Was this translation helpful? Give feedback.
The
transform
action was introduced in version 0.45.0. It allows the user to evaluate acondition and then perform either action A or action B, depending on the result.
EDIT: Escaped
{}