From 1707b8cdba42492a88b3fc43c15c20d219c5ce2b Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 25 Dec 2023 23:43:46 +0900 Subject: Add 'transform' action to conditionally perform a series of actions 'transform' action runs an external command that prints a series of actions to perform. # Disallow selecting an empty line echo -e "1. Hello\n2. Goodbye\n\n3. Exit" | fzf --reverse --header 'Select one' \ --bind 'enter:transform:[[ -n {} ]] && echo accept || echo "change-header:Invalid selection"' # Move cursor past the empty line echo -e "1. Hello\n2. Goodbye\n\n3. Exit" | fzf --reverse --header 'Select one' \ --bind 'enter:transform:[[ -n {} ]] && echo accept || echo "change-header:Invalid selection"' \ --bind 'focus:transform:[[ -n {} ]] && exit; [[ {fzf:action} =~ up$ ]] && echo up || echo down' Close #3368 Close #2980 --- man/man1/fzf.1 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'man/man1/fzf.1') diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index c4fe788c..20e7e17d 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -574,10 +574,6 @@ e.g. When using a field index expression, leading and trailing whitespace is stripped from the replacement string. To preserve the whitespace, use the \fBs\fR flag. -Also, \fB{q}\fR is replaced to the current query string, and \fB{n}\fR is -replaced to zero-based ordinal index of the line. Use \fB{+n}\fR if you want -all index numbers when multiple lines are selected. - A placeholder expression with \fBf\fR flag is replaced to the path of a temporary file that holds the evaluated list. This is useful when you multi-select a large number of items and the length of the evaluated string may @@ -589,6 +585,15 @@ e.g. seq 100000 | fzf --multi --bind ctrl-a:select-all \\ --preview "awk '{sum+=\\$1} END {print sum}' {+f}"\fR +Also, + +* \fB{q}\fR (or \fB{fzf:query}\fR) is replaced to the current query string +.br +* \fB{n}\fR is replaced to the zero-based ordinal index of the current item. + Use \fB{+n}\fR if you want all index numbers when multiple lines are selected. +.br +* \fB{fzf:action}\fR is replaced to to the name of the last action performed + Note that you can escape a placeholder pattern by prepending a backslash. Preview window will be updated even when there is no match for the current -- cgit v1.2.3