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

Global settings #41

Merged
merged 3 commits into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
# CLI arguments
args: --check .
version: 0.13.1
48 changes: 45 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,50 @@ use {

## Usage

### list
### Global Configuration
Copy link
Owner Author

@cljoly cljoly Jun 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chetan496 feel free to point out anything unclear in that section or anything that does not work for you. (this is re: #38)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chetan496 feel free to point out anything unclear in that section or anything that does not work for you. (this is re: #38)

Thanks for this, this is very helpful.
I will try this feature soon.


You can change the default argument given to subcommands (like [`list`](#list) or [`cached_list`](#cached_list)) using the telescope `setup` function with a table like this:

```lua
{
extensions = {
repo = {
<subcommand> = {
<argument> = {
"new",
"default",
"value",
},
},
},
},
}
```

for instance, you could do:

```lua
require("telescope").setup {
extensions = {
repo = {
list = {
fd_opts = {
"--no-ignore-vcs",
},
search_dirs = {
"~/my_projects",
},
},
},
},
}

require("telescope").load_extension "repo"
```

**Note**: make sure to have `require("telescope").load_extension "repo"` *after* the call to `require("telescope").setup {…}`, otherwise the global configuration won’t be taken into account.

### `list`

`:Telescope repo list` or `lua require'telescope'.extensions.repo.list{}`

Expand Down Expand Up @@ -198,7 +241,7 @@ Here is how you can use this plugin with various SCM:

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!

### cached_list
### `cached_list`

`:Telescope repo cached_list`

Expand Down Expand Up @@ -236,7 +279,6 @@ exports the `LOCATE_PATH` variable.

Provide instructions on how to setup periodic update of the locate database.


#### Troubleshooting

You should try to run:
Expand Down
2 changes: 2 additions & 0 deletions lua/telescope/_extensions/repo.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
local main = require("telescope._extensions.repo.main")
local r_config = require("telescope._extensions.repo.config")
local health = require("telescope._extensions.repo.health")

local fallback_error = { "Falling back to `:Telescope repo list`, but this behavior may change in the future" }

return require("telescope").register_extension({
health = health.check,
setup = r_config.setup,
exports = {
list = main.list,
cached_list = main.cached_list,
Expand Down
9 changes: 9 additions & 0 deletions lua/telescope/_extensions/repo/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local M = {}

M.values = {}

M.setup = function(opts)
M.values = opts
end

return M
5 changes: 3 additions & 2 deletions lua/telescope/_extensions/repo/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local Path = require("plenary.path")
local utils = require("telescope._extensions.repo.utils")
local list = require("telescope._extensions.repo.list")
local cached_list = require("telescope._extensions.repo.cached_list")
local r_config = require("telescope._extensions.repo.config")

local M = {}

Expand Down Expand Up @@ -187,7 +188,7 @@ end

-- List of repos built using locate (or variants)
M.cached_list = function(opts)
opts = opts or {}
opts = vim.tbl_deep_extend("force", r_config.values.cached_list or {}, opts or {})
opts.entry_maker = t_utils.get_lazy_default(opts.entry_maker, gen_from_locate_wrapper, opts)
local locate_command = cached_list.prepare_command(opts)

Expand All @@ -196,7 +197,7 @@ end

-- Always up to date list of repos built using fd
M.list = function(opts)
opts = opts or {}
opts = vim.tbl_deep_extend("force", r_config.values.list or {}, opts or {})
opts.entry_maker = t_utils.get_lazy_default(opts.entry_maker, gen_from_fd, opts)
local fd_command = list.prepare_command(opts)

Expand Down