Skip to content
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 option to use locate to list repos #9

Merged
merged 7 commits into from
Dec 11, 2021
Merged

Add option to use locate to list repos #9

merged 7 commits into from
Dec 11, 2021

Conversation

cljoly
Copy link
Owner

@cljoly cljoly commented Nov 2, 2021

  • refactor: isolate picker creation
  • feat: add cached_list
  • fix: change prompt for the various commands

@cljoly cljoly mentioned this pull request Nov 2, 2021
@cljoly cljoly force-pushed the locate branch 2 times, most recently from 6cda47e to a5c200b Compare November 2, 2021 07:49
@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

There is a bug in the construction of the repository list (we get the .git, not the repo itself).

@molleweide
Copy link
Contributor

on macos intel.

it seems that the list is not populated visually when using the cached command.

  1. Can I runt cached_list the first time or do I have to rund regular list first to populate the cache?

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

You should be able to run cached_list the first time. Have you populated the cache with sudo updatedb first though?

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

Also, does locate -r '/.git$' return anything for you?

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

I think I’ve fixed the issue with the trailing .git in entries (in 5ea1934).

Here is what I get with a freshly started neovim:

asciicast

I hope the screencast helps to show the behavior I think you should get.

@molleweide
Copy link
Contributor

You should be able to run cached_list the first time. Have you populated the cache with sudo updatedb first though?

returns command not found on macos

@molleweide
Copy link
Contributor

Also, does locate -r '/.git$' return anything for you?

returns on macos

locate -r '/.git$'
locate: illegal option -- r
usage: locate [-0Scims] [-l limit] [-d database] pattern ...

default database: `/var/db/locate.database' or $LOCATE_PATH

@molleweide
Copy link
Contributor

BUT my terminal is a bit messed up at the moment tho so I cant be hundred percent sure everything returns correctly.

@molleweide
Copy link
Contributor

What linux are you using?

@molleweide
Copy link
Contributor

i have been searching a bit and I don't know if I have come up with anything useful yet, but it seems that you need a different command for locate on macos.

@molleweide
Copy link
Contributor

You're preview looks good!

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

What linux are you using?

Mostly Arch linux.

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

You're preview looks good!

Thanks!

@molleweide
Copy link
Contributor

What linux are you using?

Mostly Arch linux.

cool, my goal is to migrate to that in the future.

@molleweide
Copy link
Contributor

i find this thread on how to use locate on macos:
https://www.codeproject.com/Tips/5282703/Using-locate-databases-on-MacOS-Unix
BUT
there is also this saying that locate is not supported on mac and you should instead use a command called mdfind.
https://stackoverflow.com/questions/59881380/command-locate-in-mac-terminal.
https://metaredux.com/posts/2019/12/22/mdfind.html

I'm just posting here for reference. I have to look into this and see if you can create some kind of OS conditional.

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

i have been searching a bit and I don't know if I have come up with anything useful yet, but it seems that you need a different command for locate on macos.

Yeah, I’ve found mdfind that seems to use spotlight’s cache (which is great), but it looks like it does not support hidden files (and I’m looking for .git to find the repos).

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

Our posts crossed it seems :)

@molleweide
Copy link
Contributor

Hmmm that's a bummer

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

Looks like you can get locate installed on macos with brew: https://egeek.me/2020/04/18/enabling-locate-on-osx/

@molleweide
Copy link
Contributor

molleweide commented Nov 2, 2021

Looks like you can get locate installed on macos with brew: https://egeek.me/2020/04/18/enabling-locate-on-osx/

Wow I'll try that later today. It is wierd also because I get some indication it seems that some kind of locate exists on my machine but it doesn't have the -r flag. Hopefully it works without any mods with this brew package.

---- currently ----

If I run locate I get this but I cant do man locate (this not with the brew packacge. this is from before).

%> locate
usage: locate [-0Scims] [-l limit] [-d database] pattern ...

default database: `/var/db/locate.database' or $LOCATE_PATH

and I can use it to search but I don't know how to get help on it, i mean, eg. --help doesn't work, and it is not under man locate

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

Yeah, I suspect the version of locate that you have installed currently does not support the -r but the findutils version should.

@molleweide
Copy link
Contributor

allright, so now I have installed it and aliased it like so:

  alias locate="glocate -d $HOME/locatedb"

Should trepo pick up on this or do I have to change anything in the source you think?

@molleweide
Copy link
Contributor

oh nvm now I think I understand how to add it.

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

You would need the “more arguments” thing (not implemented yet) for the -d $HOME/locatedb bit, but glocate should work if passed to bin.

You should be able to test just by changing the command here

@molleweide
Copy link
Contributor

You would need the “more arguments” thing (not implemented yet) for the -d $HOME/locatedb bit, but glocate should work if passed to bin.

You should be able to test just by changing the command here

cool yeah I've tried that now and it does not work at first try.
ima take a pause now and come back later. but searching
the db in the terminal works.

@cljoly
Copy link
Owner Author

cljoly commented Nov 2, 2021

but searching
the db in the terminal works.

That’s great news!

@molleweide
Copy link
Contributor

could flag order be of importance?

@cljoly
Copy link
Owner Author

cljoly commented Nov 9, 2021

I’m still thinking about a way to solve this…

@molleweide
Copy link
Contributor

Me to haha

@molleweide
Copy link
Contributor

I have thinking about this pretty much 24/7 for the last couple of days but this seems to be a bit above my level of nvim so I have had to spend some time on other stuff in the mean time but I am extremely looking forward to get some more time to look into this issue again because this is probably one of the most useful plugins ever.

@cljoly
Copy link
Owner Author

cljoly commented Nov 10, 2021

Thanks for your enthusiasm!

I’ve added some log messages (they may need adjustments so that it is less verbose, but for now it should be fine). You can see them by typing :messages.

When you have some time, maybe copy-pasting the output in a gist for me to look into would prove insightful.

@molleweide
Copy link
Contributor

cool! I will try to do that tomorrow.
I also read a blog post that I found when searching around for how to reload plugins.

@cljoly
Copy link
Owner Author

cljoly commented Nov 10, 2021

If you still have the link, I would be interested, if only for comparison with what I do

@molleweide
Copy link
Contributor

Yo!

I pulled locate branch and when I run the command it shows this:

:!open "https://www.reddit.com/search/?q=call_picker"

Press ENTER or type command to continue

and it open a reddit link in my web browser

@molleweide
Copy link
Contributor

If you still have the link, I would be interested, if only for comparison with what I do

I simply created a command that calls Telescope reloader. This seems to work when I am in the directory working on the actual plugin BUT if I am in the dir of my vimrc, then running the command I cant find any packer modules. I don't understand why yet.

@molleweide
Copy link
Contributor

molleweide commented Nov 12, 2021

This shows what the preview shows me when I search for telerepo with reloader in my vimrc dir.
As you can see, it only lists dirs from within the ~/.config dir.

       8 │  nvim-treesitter.shell_command_selectors : ~/.config/dorothy                                                                                                            │
       9 │  telescope.finders : ~/.config/dorothy                                                                                                                                  │
      10 │  telescope.sorters : ~/.config/dorothy                                                                                                                                  │
      11 │  telescope.pickers : ~/.config/dorothy                                                                                                                                  │
      12 │  telescope.previewers.buffer_previewer : ~/.config/dorothy                                                                                                              │
      13 │  telescope._extensions.gh_previewers : ~/.config/dorothy                                                                                                                │
      14 │  telescope.deprecated : ~/.config/dorothy                                                                                                                               │
      15 │  telescope._extensions.mapper.previewers : ~/.config/dorothy                                                                                                            │
      16 │ telescope._extensions.repo : ~/.config/dorothy                                                                                                                          │
      17 ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
      18 ╭─────────────────────────────────────────────────────────────────────────────── Packages ────────────────────────────────────────────────────────────────────────────────╮
      19 │   telerepo                                                                                                                                                    207 / 300│

@molleweide
Copy link
Contributor

@cljoly
Copy link
Owner Author

cljoly commented Nov 12, 2021

Thanks, I'll look into this in the next few days!

@cljoly
Copy link
Owner Author

cljoly commented Nov 17, 2021

It might be that telescope can’t execute the command for some reason, I’ll try to look deeper into this…

@molleweide
Copy link
Contributor

Hmm interesting!! Tell me if you want me to do something for you

@molleweide
Copy link
Contributor

It might be that telescope can’t execute the command for some reason, I’ll try to look deeper into this…

Do you think that this would be grounds for a bug submission to telescope?

@cljoly
Copy link
Owner Author

cljoly commented Nov 21, 2021

Do you think that this would be grounds for a bug submission to telescope?

Maybe, I wanna read the docs some more first though.

@molleweide
Copy link
Contributor

ooh i have to also read the built-in docs

@cljoly
Copy link
Owner Author

cljoly commented Dec 1, 2021

When I login to this GitHub Actions Workflow (that uses Mac OS), I can run:

nvim +'lua require"telescope".extensions.repo.cached_list{bin="glocate", locate_opts={"-d", "/Users/runner/locatedb"}}'

and after a few seconds, I get a list of repositories, like so:
image

@molleweide You won’t be able to log in to the action as it requires one of my private SSH keys, but maybe by comparing what’s done in the .yml, you will find what was wrong. For instance, it appears that $HOME does not work, as:

nvim +'lua require"telescope".extensions.repo.cached_list{bin="glocate", locate_opts={"-d", "/Users/runner/locatedb"}}'

works as intended, while:

nvim +'lua require"telescope".extensions.repo.cached_list{bin="glocate", locate_opts={"-d", "$HOME/loca
tedb"}}'

did not return any results.
I hope this helps you getting the plugin to work with locate on your Mac.

  • I still need to find if there is a way to get a more verbose error when the command fails, it’s silent at the moment.

@molleweide
Copy link
Contributor

molleweide commented Dec 2, 2021

yo I've seen that you wrote. I'll try to look at this and reply as soon as I can.
I'll also test this on my new M1 mac now as well.

@cljoly
Copy link
Owner Author

cljoly commented Dec 2, 2021

Thanks!

@molleweide
Copy link
Contributor

No worries, i just wanted you to know I am following. I have a lot of stuff to do atm so I cant wait until I get to test this.

This is to pave the way for the use of commands other than fd
Use a `locate` command instead of `fd`, to get cached results. Update
the documentation as well.

Fixes #3
Should hopefully make clearer how the list was built.
The current entry maker process the whole list to remove the last part
of the path and is not very customizable, but there is most likely a
better way, especially for the customizability issue.
@cljoly
Copy link
Owner Author

cljoly commented Dec 11, 2021

@molleweide I’m going to merge this PR as it works for me on Linux and I want to further build on the code without creating more conflicts 😅 .

I’ve created a discussion (#13) to further investigate why the cached_list command did not work on Mac OS, when you have some time. We can then come back and make the necessary changes.

@cljoly cljoly merged commit a8a80b8 into master Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants