yazi icon indicating copy to clipboard operation
yazi copied to clipboard

find: automatically open/enter when there is one match

Open ufUNnxagpM opened this issue 10 months ago • 4 comments

Please describe the problem you're trying to solve

Similar to the find command in ranger, if there's only a single match in the results the matched file or directory will automatically be entered/opened. This saves pressing the enter key two times.

Would you be willing to contribute this feature?

  • [ ] Yes, I'll give it a shot

Describe the solution you'd like

A new argument for find command that allows automatically executing another command, such as smart-enter, when there is one match remaining. The user is also put back into normal mode after.

The config might look something like the following

keymap = [
  { on = [ "f" ], run = ["find --smart --exec-on-single-match", "plugin --sync smart-enter"],  desc = "Find next file, and automatically enter if there's a singular match" },
]

Additional context

No response

ufUNnxagpM avatar Apr 15 '24 04:04 ufUNnxagpM

This is not feasible. find completes immediately after execution and immediately executes the plugin command following it.

It simply opens an input and does not block to wait for user input. In fact, all commands in Yazi are asynchronous, so state dependencies between such commands are not a reasonable design.

sxyazi avatar Apr 15 '24 07:04 sxyazi

This is not feasible. find completes immediately after execution and immediately executes the plugin command following it.

It simply opens an input and does not block to wait for user input. In fact, all commands in Yazi are asynchronous, so state dependencies between such commands are not a reasonable design.

Thanks for the input. I think that's reasonable, especially if the find command only finds the next match instead of every match. I've thought of the following alternatives as well

  1. When running find and in the [input] keymap, allow use of the enter or smart-enter command like { on = [ "<Enter>" ], run = ["close", "enter"], desc = "Submit the selection" } to open the first match. This reduces the enter keypresses by 1.
  2. Add a --max-depth-1 flag to jump, specifically for fzf. This reduces the enter keypresses by 1.
  3. Implement another command ex. find_enter that will search the entire directory and auto open/navigate if there's one match. Will async be a problem with this as well? I'm also not sure if it's possible to 'interrupt' the user out of the input mode

ufUNnxagpM avatar Apr 16 '24 02:04 ufUNnxagpM

This might make more sense to implement as a plugin. Going to close for now.

ufUNnxagpM avatar Apr 22 '24 03:04 ufUNnxagpM

Sorry for the late reply, this is a reasonable need, but I need some time to think about how to better implement it, reopening

sxyazi avatar Apr 22 '24 03:04 sxyazi

Hi, I made a plugin for it that extends the existing filter - it will automatically enter the only directory, and I've also added other enhancements, like supporting continuous filtering and automatically opening the hovered file on submitting:

https://github.com/sxyazi/yazi/assets/17523360/0007e5e5-ed9e-4104-ad13-0678b73af1f1

Feel free to use it: https://github.com/yazi-rs/plugins/tree/main/smart-filter.yazi

sxyazi avatar Jun 14 '24 06:06 sxyazi

I'm going to lock this issue because it has been closed for 30 days. ⏳ This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Jul 15 '24 03:07 github-actions[bot]