junegunn / fzf

:cherry_blossom: A command-line fuzzy finder

Home Page:https://junegunn.github.io/fzf/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

sitaktif opened this issue · comments

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues

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

See 2665580

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.

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