-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a function to locate directories #2
Conversation
a76d442
to
c90013f
Compare
functions/fzy_select_directory.fish
Outdated
set -l use_db "yes" | ||
if command git rev-parse --show-toplevel >/dev/null ^/dev/null | ||
set use_db "no" | ||
else if command hg root >/dev/null ^/dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t think there should be a check like
if which hg >/dev/null ^/dev/null and command hg root >/dev/null ^/dev/null
I'm not sure about logic after that, but it should check for hg first.
not checking git is fine, because it should be there to run fisherman in the first place.
otherwise I'm getting this trying to run without mercurial installed.
ya@reaper ~> fzy_select_directory
fish: Unknown command 'hg'
~/.config/fish/functions/fzy_select_directory.fish (line 4):
else if command hg root >/dev/null ^/dev/null
^
in function “__fzy_get_directories”
called on line 57 of file ~/.config/fish/functions/fzy_select_directory.fish
in function “fzy_select_directory”
called on standard input
>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
functions/fzy_select_directory.fish
Outdated
|
||
function fzy_select_directory | ||
__fzy_get_directories | fzy | read -l foo | ||
cd $foo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this cd here will put me back into ~ if I exit fzy search without selecting a directory (empty $foo). need to exit to cwd if $foo is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
key_bindings.fish
Outdated
@@ -1,3 +1,4 @@ | |||
function fish_user_key_bindings | |||
bind \cr 'fzy_select_history (commandline -b)' | |||
bind \ec 'fzy_select_directory' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bind \cf
like fzf does looks reasonable. not sure if it will ever clash with anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used C-f
functions/fzy_select_directory.fish
Outdated
end | ||
end | ||
|
||
if not which locate >/dev/null ^/dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think using locate is a good idea.
I have directories sitting somewhere not indexed by locate, thus function with use_db=yes yields empty results.
need to check if this particular directory is present in the locate index (not sure if it's the right thing to do) or ditch locate completely.
or maybe create a setting to enable it unconditionally for people who have everything indexed.
another no-go for locate is that it's not always up to date and will return false results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added FZY_ENABLE_DB
for allowing the use of locate
c90013f
to
b1aa28b
Compare
It uses `fd`, `locate` or `find` as appropiate. As locate database might have stale results, it's use must be enabled through `FZY_ENABLE_DB = "yes"` This function is bound to C-f
b1aa28b
to
5ef3eae
Compare
It really is a hack over locate and may lead to stale results. `fd` does fine when running on $HOME.
68dda01
to
b69e4cb
Compare
hey, it's much cleaner and better with latest commits. let me test some edge cases and I'll merge it a bit later. |
Hey give I can list "all" files on my home in 0.5s with |
I heard a lot of good things about fd, will give it a try sometime. thanks! I've been trying to optimize the find to be somewhat faster and here is what I came up with.
some points
even If I do cd / and hit ctrl+f it gives me results in a reasonable time (less than 3 second) My tests may not reflect true picture, because my storage is ridiculously fast (nvme drives with 3.5 GB/sec read speed) so I need something or someone else to test it before I push. I also see really good results with fun fact:if you type any dir name into fzy prompt, even if it's not in the results, fish will cd into that dir on hitting Return, which is great! ctrl+f is now my favourite keybindng, how did I live before this? it's so fast and convenient. |
I just tried that on my root and noticed that it goes through remote mounts, it needs the Also, it'll probably be much better to skip odd filesystems like proc, sysfs and others mentioned on |
tried fd, it's good ) a bit slower than my find line, but insignificantly so. have no problems with it on /. on the find function: another argument against -fstype is that it significantly slows down find. it runs several hundred times slower that way. -mount skips mountpoints but not /proc or /sys, some people have a LOT of mounts. maybe requiring an additional input from a user is a sane option. I'd really like to make it fast, because typical usage is just CDing withing ~ and slowing it down for some those edge cases makes me sad. another possible problem like you mentioned is nfs/cifs/something else, slow as a turtle. will test that new find line for a while, possibly with slow storage. |
what do you think of this? pretty simple, works for /proc and /sys, only searches / mountpoint in single edge case, and still fast for regular lookups. function __fzy_get_directory_list -d 'Get a list of directories using fd or find'
if which fd >/dev/null ^/dev/null
command fd . -t d
else if test "$PWD" = '/'
command find / -mount -name ".*" -prune -o -type d -print ^/dev/null
else
command find * -name ".*" -prune -o -type d -print ^/dev/null
end
end |
Yes, it makes sense to special-case for unusual places to let the default perform well on the common ones, although maybe we want to do that when outside I asked on |
It uses
cd
,locate
andfind
as appropiate.I'm still missing the binding, but it's not clear to me which one would be best, maybe we should just copy what fisherman/fzf does. What do you think?