rabite0 / hunter

The fastest file manager in the galaxy!
Do What The F*ck You Want To Public License
1.31k stars 64 forks source link

How to select a file or change a directory using fuzzy finders? #22

Closed alexherbo2 closed 5 years ago

alexherbo2 commented 5 years ago

What is the equivalent to the following lf commands, which use fzf and fd?

Example – Select a file:

cmd select-fuzzy ${{
  lf -remote "send $id select $(fd --type file | fzf)"
}}

map s select-fuzzy

Example – Change to a directory:

cmd cd-fuzzy ${{
  lf -remote "send $id cd $(fd --type directory | fzf)"
}}

map g cd-fuzzy
rabite0 commented 5 years ago

This runs fzf and lf selects the file/enter dir returned by it, if I understand that correctly?

So, you're asking for integration with fzf/other tools to select files/enter directorier? That should be fairly easy to do and sounds pretty useful actually.

Right now you can filter with Ctrl(F) and search for files with S and browse through matches with Alt-S. Also you can press "/" and enter a directory with autocompletion in the minibuffer at the bottom. All available keybindings are in the README.

Btw, lf seems nice, starts up quickly and never lags. Also looks very much like ranger itself.

alexherbo2 commented 5 years ago

Yep that’s it.

And yep it is close to ranger, except it has no tab but a client-server architecture to communicate between instances.

rabite0 commented 5 years ago

I'm currently working on this, but I'm wondering if separate commands for files/directories are really necessary. I was thinking about a single command that detects if the output is a file or directory and opens/selects it appropriately.

Also, right now I'm using the "enter" key to start the external process, although I might change this before I push this. It does kinda make sense though. I guess I could bind the second command to Alt(Enter), if it's desirable.

alexherbo2 commented 5 years ago

I think select is enough and better.

alexherbo2 commented 5 years ago

Return is to open files and directories – open files with the appropriate program and open directories by entering in the folder.

If you make the distinction as above, action on files will select, and directories select and open.

In addition, it will simplify the code because you opt-out the logic of files and directories.

So if I was you, I would start with a select command to see if that’s enough, and let the user with one key away to open the files and directories after the selection.

alexherbo2 commented 5 years ago

It would be nice to have a concept of multiple selections.

rabite0 commented 5 years ago

Well, currently Enter/Return does nothing, because it doesn't make sense to use it to open anything, since you can use either the usual movement-keys hjkl, etc. or the cursor-keys to do that. I don't think many people would use it that way.

I agree that selecting multiple files is a desirable feature. Will add that, too.

I pushed a branch called "select-prog" with the current state of things. You can define a program by adding "select_prog=" to ~/.config/hunter/config. Any issues you can find?

It probably fails if the program outputs multiple files/directories at once, I didn't consider that use-case.

EDIT: Ooops, didn't actually commit/push the changes. Anyway, implementing multi-selection now.

Also, don't bother testing, I forgot that the API I use doesn't enable input for the child process as it is, so you won't be able to test anything, except if you start something that just prints a path and exits. Will install fzf and see what it does. I guess it prints to stderr.

rabite0 commented 5 years ago

Ok, pushed another update for this. You can now select multiple files using an external command.

What works:

What doesn't work yet:

Open questions:

Anything else I'm missing? Other suggestions?

rabite0 commented 5 years ago

Ok, pushed another update. Except for the synchronous IO issue, this seems pretty usable and stable now. I'm probably not going to bother with the asynchronous IO stuff right now. I don't think it's going to be much a problem anyway, since fzf pulls all everything into the fs-cache when it runs, so it will still be pretty fast for the most part.

alexherbo2 commented 5 years ago

I’m not fond to opt-in select file or open directory.

rabite0 commented 5 years ago

Oh, now I see what you mean, fzf actually behaves differently when you pipe files into it!

I was a bit confused by the commands you wrote in the beginning, since I coulnd't even see any directories in fzf when I just ran it by itself. I should have tried them as you posted them.

You're right, I will split those two functions, that makes more sense.

rabite0 commented 5 years ago

Sooo.. this is more or less done, I merged the branch into master.

Selecting files and entering directories are now two separate features. I also changed the keybindings. External select is now Alt(space) and external cd is Alt(/). Since space is already select and "/" does this cd-prompt-thing, this is at least consistent and logical.

By default it uses "find -type f | fzf -m" for selecting files, and "find -type d | fzf for cd to directories. You can change this, of course.

BTW, if you compile hunter on your own you can also change the key bindings in the source code. You need to look into src/file_browser.rs. At the bottom is an "on_key" method. There you can change the keys if you like. Then commit with "commit -a". After that you can use git pull and it will merge the new changes into your local repo.