feat: search for files or string in the specified directory#134
feat: search for files or string in the specified directory#134suitablebeard wants to merge 1 commit into
Conversation
Now you can fuzzy search in a different directory. Otherwise you would need to cd into it.
|
Actually I just noticed that I was mistaken about simplification solving the slash-at-end issue I mentioned. I believe the simplest way to fix it is with here's how I think the ParsePath function should look like: export def ParsePath(path: string): string
return path
->expand()
->simplify()
->substitute('\\\|\/$', '', '')
enddef |
|
Another correction, the regex pattern should be |
|
|
||
| command! -nargs=? FuzzyGrep launcher.Start('grep', { prompt_text: <q-args> }) | ||
| command! -nargs=? FuzzyGrepRoot launcher.Start('grep', { cwd: helpers.GetRootDir(), prompt_text: <q-args> }) | ||
| command! -nargs=1 FuzzyGrepDir launcher.Start('grep', { cwd: <q-args> }) |
There was a problem hiding this comment.
You probably want -complete=dir here too
|
Hi, Thanks for the PR, it made me realise there was a bug in the relative path handling of grep results. That code originated from a time before it was possible to pass the working directory as an arg, and didn't allow for arbitrary paths (only worked for ancestors, like one generated by :FuzzyGrepRoot). This is now fixed in I'm not sure about adding these commands to the plugin, I think what's probably lacking here is documentation showing how easy it is to add custom commands, custom selectors, and even fully fledged extensions to Fuzzbox. For example, something like this in your command! FuzzyFindNotes call fuzzbox#Launch('grep', #{ cwd: '/my/notes/dir', title: 'Find Notes' })
command! FuzzyGrepNotes call fuzzbox#Launch('files', #{ cwd: '/my/notes/dir', title: 'Grep Notes' })
|
Now you can fuzzy search in a different directory.
I find it very useful when I either want to take notes of something or find a note a have while not having to either start vim from the terminal in my notes folder or :cd into it. With the new commands, I can easily create a mapping for it similar to this one:
Now regarding the code itself, I made a ParsePath helper function to both expand and simplify the path given. I thought it was needed after noticing two things:
getcwd()which gives the full path of the cwd;For point 1, the path given has to be expanded. And for point 2, it has to be simplified so that it'll accept a path with as many slashes a user might give.
Still about the helper, I wasn't sure where to place it since there were both 'internal/helpers.vim' and 'builtin/help.vim' and I didn't really understand the difference.
About the commands :FuzzyFilesDir and :FuzzyGrepDir , I chose to let them have only one argument (the path) since I thought the implementation would be easier.
Also updated the README.