junegunn / fzf

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

[Feature Request] add `toggle+to+top` and `toggle+to+bottom` actions #3753

Closed sitaktif closed 2 months ago

sitaktif commented 2 months ago

Checklist

Output of fzf --version

0.46.1 (brew)

Problem / Steps to reproduce

It would be great to have "toogle to top" and "toggle to bottom" actions.

Current workaround is to keep the tab key pressed to toggle+down to the bottom, but the problem is that the last item will keep toggling very quickly and there's a 50% chance for the last item to be selected upon releasing the tab key.

Having a toggle+to+bottom action would allow users to bind a key (say shift-end) and toggle all the items from the current cursor position to the last item:

1/ Move the cursor to a specific location.

[ ] one
[ ] two
[ ] three  <-- cursor
[ ] four
[ ] five

2/ Press the key binding for toggle+to+bottom.

3/ Desired result:

[ ] one
[ ] two
[x] three
[x] four
[x] five  <-- cursor
junegunn commented 2 months ago

See 2665580120ba1c408016d2b542af9a4229e627ad

I figured adding $FZF_POS variable and using transform action to implement the desired behavior would be much more flexible and versatile than adding dedicated actions.

# Toggle selection to the top or to the bottom
seq 30 | fzf --multi --bind 'load:pos(10)' \
  --bind 'shift-up:transform:for _ in $(seq $FZF_POS $FZF_MATCH_COUNT); do echo -n +toggle+up; done' \
  --bind 'shift-down:transform:for _ in $(seq 1 $FZF_POS); do echo -n +toggle+down; done'

You can replace toggle+up with select+up or deselect+up, etc.

sitaktif commented 2 months ago

Nice, also TIL about transform. Cool stuff, thanks!