junegunn / fzf

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

[question] Action to toggle multi selection #3754

Closed DanSM-5 closed 2 months ago

DanSM-5 commented 2 months ago

Checklist

Output of fzf --version

0.50.0 (0.50.0)

OS

Shell

Problem / Steps to reproduce

Is there an action that toggles multi to allow you to select multiple options or restrict to a single option through a binding?

I couldn't find any toggle-multi action or a select/deselect action that would do something similar.

junegunn commented 2 months ago

No. Do you have a use case?

DanSM-5 commented 2 months ago

Yes. I have some scripts that do a multi purpose selection but some make sense to restrict the selection to a single item.

A simple example from one of my scripts

getsources |
  fzf --multi \
        --prompt 'Projects> ' \
        --multi \
        --bind 'ctrl-f:change-prompt(Files> )+reload(fd --type file . {})+unbind(ctrl-f)' \
        --bind 'ctrl-p:change-prompt(Projects> )+reload(getsources)+rebind(ctrl-f)'

I'm expecting either multiple files or a single directory. At the moment I added a check for the first item so if I accidentally select multiple directories, it just picks the first one and ignores the rest to prevent errors. It would be nice though if I could change the multi state as an action when picking directories so I can avoid validation logic. I imagine this can be useful for other multi purpose selection.

junegunn commented 2 months ago

Yeah, in that case, change-multi(LIMIT) would make sense.

toggle-multi will not be very useful.

DanSM-5 commented 2 months ago

I agree, if you can set N number of items, it would be better.

junegunn commented 2 months ago

Please note that change-multi will clear previous selections. I couldn't think of any use case where you would want to keep the previous selections, so I just decided to keep it simple.

DanSM-5 commented 2 months ago

I think that works fine. Thanks!