Skip to content

Commit 1355477

Browse files
committed
feat: add cached_list
Use a `locate` command instead of `fd`, to get cached results. Update the documentation as well. Fixes #3
1 parent 0358139 commit 1355477

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

README.md

+48-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ use {
8080

8181
### Required
8282

83-
* [`fd`][] to find the repositories on the filesystem
83+
* [`fd`][] to find the repositories on the filesystem with `list`
84+
* [`plocate`][] or [`locate`][] to find the repositories on the filesystem with `cached_list`
8485

8586
[`fd`]: https://github.com/sharkdp/fd
87+
[`locate`]: https://man.archlinux.org/man/locate.1
88+
[`plocate`]: https://man.archlinux.org/man/plocate.1
8689

8790
### Optional
8891

@@ -173,9 +176,52 @@ Here is how you can use this plugin with various SCM:
173176

174177
Is your favorite SCM missing? It should be straightforward to support it by changing the pattern parameter. If you want it to be considered for addition here, open a PR!
175178

179+
### cached_list
180+
181+
`:Telescope repo cached_list`
182+
183+
This relies on a `locate` command to find repositories. This should be much faster than the `list` command, as it relies on a pre-built index but results may be stalled.
184+
185+
*Note*: at this point, the plugin does not manage index update. Updating the index often requires to run a command like `updatedb` as root.
186+
187+
#### Troubleshooting
188+
189+
You should try to run:
190+
```
191+
sudo updatedb
192+
```
193+
if you encounter any problems. If it’s not the case by default, you should automate such index update with for instance `cron` or `systemd-timers`. See https://wiki.archlinux.org/title/Locate.
194+
195+
#### Options
196+
197+
Options are the similar to `repo list`, bearing in mind that we use `locate` instead of `fd`. Note that:
198+
199+
* `fd_opts` is not supported, as we don’t use `fd`
200+
201+
#### Examples
202+
203+
##### Exclude Irrelevant Results
204+
205+
Chances are you will get results from folders you don’t care about like `.cache` or `.cargo`. In that case, you can use the `file_ignore_patterns` option of Telescope, like so (these are lua regexes):
206+
207+
```
208+
:lua require'telescope'.extensions.repo.cached_list{file_ignore_patterns={'.cache/', '.cargo/'}}
209+
```
210+
211+
##### Use With Other SCMs
212+
213+
Here is how you can use this plugin with various SCM (we match on the whole path with `locate`, so patterns differ slightly from `repo list`: notice the `^` that becomes a `/`):
214+
215+
| SCM | Command |
216+
|--------|----------------------------------------------------------------------------|
217+
| git | `:Telescope repo list` or `lua require'telescope'.extensions.repo.list{}` |
218+
| pijul | `lua require'telescope'.extensions.repo.list{pattern=[[/\.pijul$]]}` |
219+
| hg | `lua require'telescope'.extensions.repo.list{pattern=[[/\.hg$]]}` |
220+
| fossil | `lua require'telescope'.extensions.repo.list{pattern=[[/\.fslckout$]]}` |
221+
176222
## FAQ
177223

178224
### Getting the repository list is slow
179225

180-
You can use your `.fdignore` to exclude some folders from your filesystem. If there is enough interest, [#1](https://github.com/cljoly/telescope-repo.nvim/issues/1) could further enhance this.
226+
If `:Telescope repo list` is slow, you can use your `.fdignore` to exclude some folders from your filesystem. If there is enough interest, [#1](https://github.com/cljoly/telescope-repo.nvim/issues/1) could further enhance this.
181227

lua/telescope/_extensions/repo.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local repo_builtin = require'telescope._extensions.repo_builtin'
22

33
return require'telescope'.register_extension{
44
exports = {
5-
list = repo_builtin.list
5+
list = repo_builtin.list,
6+
cached_list = repo_builtin.cached_list,
67
},
78
}

lua/telescope/_extensions/repo_builtin.lua

+22
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ local function call_picker(opts, command)
125125
}):find()
126126
end
127127

128+
-- List of repos built using locate (or variants)
129+
M.cached_list = function(opts)
130+
opts = opts or {}
131+
opts.cwd = vim.env.HOME
132+
opts.bin = opts.bin and vim.fn.expand(opts.bin) or nil
133+
-- Use alternative locate if possible
134+
if opts.bin == nil then
135+
if vim.fn.executable'plocate' == 1 then
136+
opts.bin = 'plocate'
137+
elseif vim.fn.executable'locate' == 1 then -- Fallback
138+
opts.bin = 'locate'
139+
else
140+
error "Please install locate (or one of its alternatives)"
141+
end
142+
end
143+
local bin = vim.fn.expand(opts.bin)
144+
145+
local repo_pattern = opts.pattern or [[/\.git$]] -- We match on the whole path
146+
local locate_command = {bin, '-r', repo_pattern}
147+
call_picker(opts, locate_command)
148+
end
149+
128150
-- Always up to date list of repos built using fd
129151
M.list = function(opts)
130152
opts = opts or {}

0 commit comments

Comments
 (0)