junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
61.95k stars 2.34k forks source link

Action to clear selections if there are any else exit fzf. (Feature request) #3805

Closed smashgen closed 3 weeks ago

smashgen commented 1 month ago

Checklist

Output of fzf --version

0.50 (devel)

OS

Shell

Problem / Steps to reproduce

I checked the man page and I don't think there is an action that already does this. I think it would be useful to have an action that clears selections if there are any else exit fzf, similar to the cancel action.

LangLangBart commented 1 month ago

The transform[^1] action enables the user to execute an action conditionally.


Example

The fzf tool sets the environment variable FZF_SELECT_COUNT[^2]. If no selections are present, the operation is aborted. Otherwise, it deselects the matches upon pressing ⌃ Control + A.

look foo | fzf --multi \
  --bind 'load:select-all' \
  --bind 'ctrl-a:transform:((FZF_SELECT_COUNT)) &&
    echo "deselect-all" ||
    echo "abort"'

[^1]: changelog 0.45.0 [^2]: changelog 0.46.0