sxyazi / yazi

💥 Blazing fast terminal file manager written in Rust, based on async I/O.
https://yazi-rs.github.io
MIT License
11.42k stars 266 forks source link

Add the `--hovered` option for the `rename` and `remove` command #1226

Closed hankertrix closed 3 days ago

hankertrix commented 3 days ago

Please describe the problem you're trying to solve

With cross-directory selection, I often forget that I still have items selected before running the rename and remove commands, which can end in disaster, especially for the remove command.

Would you be willing to contribute this feature?

Describe the solution you'd like

The --hovered option to be added for both the rename and remove commands, similar to the open command.

Additional context

Forgetting to unselect files:

image

Expecting to delete the currently hovered file:

image

Accidentally delete the files that were selected in another directory:

image image

sxyazi commented 3 days ago

Try:

{ on = [ "h" ], run = [ "leave", "escape --select" ] },
{ on = [ "l" ], run = [ "enter", , "escape --select" ] },

Doc of escape command: https://yazi-rs.github.io/docs/configuration/keymap#manager.escape

hankertrix commented 3 days ago

Thank you for the blazingly fast response!

However, this wouldn't really work for my use case as I would like to be able to use cross-directory selection, but not shoot myself in the foot when I forget to deselect after selecting in another directory when I use the rename and remove commands.

Ideally, I would like to create a plugin that will only run the remove and rename commands on the selected files only when the currently hovered file is selected, like the plugin in this issue for the open command.

Unless I'm missing something, I'd be willing to implement this feature as it seems trivial.

sxyazi commented 3 days ago

Ideally, I would like to create a plugin that will only run the remove and rename commands on the selected files only when the currently hovered file is selected, like the plugin in https://github.com/sxyazi/yazi/issues/807#issuecomment-1994973336 for the open command

It's possible. Basically, you just need to bind your remove and rename keys to your custom plugin. You can implement both in the same plugin; just differentiate them with parameters:

{ on = [ "d" ], run = [ "plugin --sync your-plugin --args=remove" ] },
{ on = [ "r" ], run = [ "plugin --sync your-plugin --args=rename" ] },

Then, in your plugin, when the conditions are met, use ya.manager_emit() to emit them (remove or rename command).

Doc of ya.manager_emit(): https://yazi-rs.github.io/docs/plugins/utils/#ya.manager_emit

hankertrix commented 3 days ago

I see, that's helpful.

The issue is that the remove and rename commands don't have the option to operate only on the hovered file like the open command does. Emitting the rename or remove commands will end up operating on all of the selected files instead of just the hovered file.

mskvsk commented 3 days ago

I had this issue as well.

I like how it is solved in nnn. If you have some selection and try to do rename/open/delete on a file outside of the selection the file manager specifically asks what should be the object of the operation, the hover or the selection.

hankertrix commented 2 days ago

the file manager specifically asks what should be the object of the operation, the hover or the selection.

Do you have a screenshot or maybe a video of the prompt?

hankertrix commented 19 hours ago

@mskvsk I implemented the prompt in my plugin, but you have to be on the latest Git version of Yazi for the prompt to work on the remove and rename commands.

Check it out here: https://github.com/hankertrix/augment-command.yazi