You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have encounter the use case in which I would like to remove 1 or more items in the list displayed in fzf.
For simplicity take the following example:
printf'top\nmiddle\nbottom'| fzf --bind 'ctrl-a:execute(operation that makes "bottom" invalid for selection)'
Where the options top, middle and bottom are all valid options. However if you press ctrl-a to run some extra processing, then the bottom option stops being valid and should not be selected anymore.
My current solution for this is to add a reload action and filtering out the invalid option(s). However depending on the case reloading and filtering could be expensive/slow or add a lot of extra complexity. My assumption is that removing/filtering out options in fzf is probably faster and easier as the search already does that when fuzzy matching to narrow options.
The proposed feature is to include a pop action (name used for example) that could be used to remove items from the list.
Without arguments (pop) e.g. --bind 'ctrl-a:execute(foo {1})+pop+execute(something {+f})
When multiple entries are selected, they all get removed from the list.
When there is no selection (e.g. --no-multi), currently focused item is removed.
Template values ({1}, {n}, {+f}, etc.) should remain unchanged from the start of the --bind flag until the last action in the same --bind flag even if a pop action was used.
With arguments (pop(N)) e.g. --bind 'ctrl-a:execute(foo {1})+pop(5)+execute(something {+f})
Argument N represents a number, range of numbers 1..2 or space separated list 1 2 3 4..6 that represent the index of the entries to remove.
Templates that represent indexes are valid {n} and {+n}
This is just a high level description of how the feature could work but it is open for discussion if the feature is considered.
Thanks.
The text was updated successfully, but these errors were encountered:
While I agree that this can be useful, it's not trivial to implement. fzf maintains the items as a list of fixed-sized immutable chunks for better performance. Removing something in an immutable chunk affects the core premises of counting, matching, caching, etc. Adding a flag to each item would be another option to implement it, but it's also not without a cost (e.g. increased memory footprint, extra locking).
I'll leave this open and think about it over time.
While not ideal, there can be several strategies to deal with such situations. transform is one option.
(echo yes;echo no) | fzf --bind 'ctrl-a:transform: if [[ {} = yes ]]; then printf "execute:echo %s; read" {} else printf "change-header:ctrl-a not allowed for %s" {} fi'
I see, would changing the strategy from removing from the list to permanently hiding (until a reaload happens) be more feasible? I imagine there is some logic to hide entries that is already working with the fuzzy matching algorithm. The list would remain the same and be immutable but certain indexes can be marked to remain hidden and unselectable.
Also, thanks for the transform suggestion. I'll see if I can apply it in the meanwhile.
Checklist
man fzf
)Output of
fzf --version
0.57.0 (0476a65)
OS
Shell
Problem / Steps to reproduce
I have encounter the use case in which I would like to remove 1 or more items in the list displayed in fzf.
For simplicity take the following example:
Where the options
top
,middle
andbottom
are all valid options. However if you pressctrl-a
to run some extra processing, then thebottom
option stops being valid and should not be selected anymore.My current solution for this is to add a reload action and filtering out the invalid option(s). However depending on the case reloading and filtering could be expensive/slow or add a lot of extra complexity. My assumption is that removing/filtering out options in fzf is probably faster and easier as the search already does that when fuzzy matching to narrow options.
The proposed feature is to include a
pop
action (name used for example) that could be used to remove items from the list.pop
) e.g.--bind 'ctrl-a:execute(foo {1})+pop+execute(something {+f})
{1}
,{n}
,{+f}
, etc.) should remain unchanged from the start of the --bind flag until the last action in the same --bind flag even if apop
action was used.pop(N)
) e.g.--bind 'ctrl-a:execute(foo {1})+pop(5)+execute(something {+f})
N
represents a number, range of numbers1..2
or space separated list1 2 3 4..6
that represent the index of the entries to remove.{n}
and{+n}
This is just a high level description of how the feature could work but it is open for discussion if the feature is considered.
Thanks.
The text was updated successfully, but these errors were encountered: