Closed ghost closed 4 years ago
Hey @user-b,
You won't have the quick navigation with hjkl but it's possible to get a hierarchical overview of your folder via the preview window.
Here is a quick script that can do that : https://gist.github.com/FractalWire/c1305be8fb1a9c37351188cfca4e33c1
(You'll need fd for it to work properly, but you could use find
as well)
Put that in your $PATH and then use cd $(fexp)
to quickly move down your folder. Going up is less convenient and could probably be improved but that might gives you some ideas.
You can also alias that for quick access alias cde='cd $(fexp)'
I used tree
for the hierarchical overview, but ls
would be fine as well if you prefer only one depth of details. Anyway, feel free to tailor that script to your need.
Thank you, I'll totally look at it.
I also encountered inquirer.js with a nice tree mode:
https://github.com/anc95/inquirer-file-tree-selection
Using js for this does not feels quite right, and I don't really know if it could work with fzf like that. But a seamless combination of Fzf + a really good tree browser sounds like heaven. Maybe next year I'll try to code it.
Well, nothing wrong using js in the terminal nowaday. It has become versatile enough IMO.
But, I realized the --bind
option could allow some lateral moves with fzf
.
Here is a new version of my previous script: https://gist.github.com/FractalWire/639ce7835fb91a32f774780e11c55475
You can move with ctrl+j
/ctrl+l
and can select the current folder with ctrl+enter
.
While enter
will open the folder currently highlighted and escape abort the whole process and put you back in your starting folder.
Excelent, thank you! I translated your script to fish, and also added functionality. Now it's possible to move between "dir" mode (hjkl-tree-like) and "file" mode (fuzzy). It's also possible to do cd from the widget or just insert the resulting dir/file in the current command line buffer as a parameter of any other program, just like with fzf-file-widget. But this is a lot better than fzf-file-widget and fzf-cd-widget I think.
Both your code and mine have a bug, it's not possible to fire any --bind command after entering on empty folders or when fd's depth param goes to 0 (in my code). Any idea why?
I tried to paste the code here but the code tag does not handle it well. But if you don't mind, I'd like to continue developing it. I can put a link to your code in the readme to give your credit for your work.
nice :+1:
But if you don't mind, I'd like to continue developing it.
Sure. Feel free to do so ! I might put a repo as well, but in bash as I'm not used to fish.
Both your code and mine have a bug, it's not possible to fire any --bind command after entering on empty folders or when fd's depth param goes to 0 (in my code). Any idea why?
Might be a bug.
Trying that :
bla=$(echo -n '' | fzf --bind 'ctrl-h:abort+execute(echo "bla")'); echo $bla
will output nothing if you press ctrl+h
but that:
bla=$(echo -n 'bla' | fzf --bind 'ctrl-h:abort+execute(echo "bla")'); echo $bla
will output 'bla' as expected.
It probably has to do with the fact fzf treats empty match differently (the exit code is 1 in that case).
I actually fixed that in my latest version, here
First I switch from --bind
to --expect
option. This option will output some special key combination before the actual fzf output.
So, no need to have this ACTION= parsing
, which was a bit dirty. And this have not the same issue as execute, it will output the key combination even if the match is empty:
bla=$(echo -n '' | fzf --bind 'ctrl-h:abort+execute(echo "bla")' --expect=ctrl-h); echo $bla
Another trick I first used was to add .
and ..
folder before any other results. Something like that :
(echo -e '.\n..'; fd -t d --color=always) | fzf
That way, it's actually never empty.
The final improvement of my script was to be able to expand/retract the tree view on the right. It's not perfect as I need to keep the query value as the previous fzf output between loop turn to keep context (if that makes sense, you'll understand if you try it).
I didn't successfully ran your code unfortunately. Not sure if there is something I need to configure in fish (I never used that shell before). I tried with the command fish fe.fish
but no output, not even error...
Excelent, your improvements sounds great. I'll copy that.
My code is a function meant to be put in fish's config file (~/.config/fish/config.fish here). You should load a new term (calling fish from bash) after saving the file. The function fish_user_key_bindings should be automatically evaluated by fish making fe() available through Ctrl+y (right next to Ctrl+r and Ctrl+t, wich are other fzf binds). Otherwise you can call fe like any other program but then the "INSERT" case works like regular echo instead.
Btw, fish is a big improvement over bash, unless you have it heavily tweaked (if possible). It takes some time to incorporate all of fish's features but then bash becomes quite difficult to use. Sadly the syntax are diferent.
Hello. I just discovered fzf and now I'm in the process of establishing my new standard way of adressing file browsing.
Until now I was using ranger for general file browsing but now by taking advantage of the --bind parameter of fzf, fzf alone becomes more of a replacement for any other file browsing program. But of course a more standard way of visiting directories is still necessary to complement a fuzzy finder. The problem is, after using ranger for a while, the old good
cd
,../../
and autocomplete commands seems a little bit outdated and keeping ranger as a host for fzf does not "feels" quite good.I think the perfect solution (from my point of view) is maybe too radical and most likely outside the scope of this fuzzy finder but still (in my opinion) relevant for the operations most users do use fuzzy finders (File browsing and cd..).
The "perfect" (just thinking..) approach could be to mix the fzf-file-widget and fzf-cd-widget in a way that quickly calling and switching from there to a similar minimalistic but ranger-like (hierarchical and hjkl) way of navigating directories should be possible. This should be done in a way that you could not only call the "fzf-something-widget" function with any of the modes (tree/fuzzy) but also you should be able to switch between them. So in the middle of a fuzzy search you could move to another dir in tree mode and go back to the same fuzzy search whithin the newly accesed folder. Maybe, (Ideally I think) the "fzf-cd-widget" functionality should be available through a shortcut in a single "fzf-something-widget" function/program.
In my opinion such a tree mode could look a bit like emacs neotree or vim's nerd-tree. Some of the other functionalities of ranger like "go to somewhere", bookmarks, etc could be quite helpful.
This way most if not all the file browsing operations are covered by a single (in my opinion!) optimal way. Any other file browser program becomes quite unnecesary as doing file browsing directly in the command line enables the execution of any command beyond those pre-configured with the --bind parameter. So this new tree mode could remain quite fast and minimalistic while still powerful.
Now, I just looked at the "fzf-file-widget" function and honestly, I do not understand very much of it. So this issue is more of a open question, for existing tools, ideas, rebuttals, tips on how such a functionality could be implemented or just to awaken interest of other developers on a better position to address something like this. Maybe I'm exagerating or totally wrong, but I think this way of doing file browsing is a very little but natural next step. Sadly I'm already facing RSI problems and working on a demanding project so I don't see myself trying to code this idea right now. But any thoughts are really welcomed. Thank you!
PD: Many thanks also for fzf and sorry for any misuses of the english language.