junegunn / fzf

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

Pin selected items to top #2514

Open sujay1844 opened 3 years ago

sujay1844 commented 3 years ago

Info

Problem / Steps to reproduce

When I do the above steps, the first selected item doesn't appear in the list. One of the ways I consider using fzf is for deleting mulitple files. That works great if the two/more files have similar names. I want fzf to pin selected items to the top of the list if it doesn't match with the search term. If you do this, the item may disappear from the original list. The solution is to duplicate an entry at the top when it's selected. I have no idea how you guys will pull this off. Hopefully, it's not much effort.

Regards

mmahmoudian commented 1 year ago

Would be nice to have this as a togglable CLI flag (e.g --pin-selection). Additionally it would be amazing to use the preview pane to show the list of selected items if the preview is not already in use. This way even in places with few lines, user can still have the selected items in the view if they want to. I suggest if this is implemented, it be activated via another flag (e.g --multiple-in-preview).

rbusfield commented 4 months ago

This solution will take a custom list (ls -1), provide a multi-select, and a toggle between selection list and file object 'stat' preview. MultiSelect list is preserved and sent to stdout.

The key to the transform is the [ ! {fzf:prompt} =~ MultiSelect ] and change-preview:cat \{+f} which will display the selction list.

ls -1 |  \
  fzf --multi --preview-window 'nohidden' \
  --header="Type search characters. Use CTRL-T to toggle stat details view, CTRL-C to Cancel" \
  --border \
  --border-label=" Multi File selector with stat preview" \
  --preview 'cat {+f}' \
  --preview-window 'top' \
  --prompt "MultiSelect preview [search list] " \
  --bind 'ctrl-t:transform:[[ ! {fzf:prompt} =~ MultiSelect ]] &&
        echo "change-prompt(MultiSelect List Preview [search list]: )+change-preview:cat \{+f}" ||
        echo "change-prompt(File stat info [search list]: )+change-preview:stat \{}"'