diff --git a/CHANGELOG.md b/CHANGELOG.md index 97cdfa9..bc453a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- `additional_args` support to `live_grep_args()` + ## 1.1.0 - 2024-06-09 ### Added diff --git a/README.md b/README.md index c85a799..a8d7c97 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,12 @@ telescope.load_extension("live_grep_args") This extension accepts the same options as `builtin.live_grep`, check out `:help live_grep` and `:help vimgrep_arguments` for more information. Additionally it also accepts `theme` and `layout_config`. +`live_grep_args` args + +| Name | Type | Description | Example | +| --- | --- | --- | --- | +| `additional_args` | `function|table` | additional arguments to be passed on. Can be fn(opts) -> tbl | `{ '-tmd' }` | + ### Mapping recipes: diff --git a/lua/telescope/_extensions/live_grep_args.lua b/lua/telescope/_extensions/live_grep_args.lua index 1ff3e2d..b679332 100644 --- a/lua/telescope/_extensions/live_grep_args.lua +++ b/lua/telescope/_extensions/live_grep_args.lua @@ -32,6 +32,15 @@ local live_grep_args = function(opts) opts.entry_maker = opts.entry_maker or make_entry.gen_from_vimgrep(opts) opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) + local additional_args = {} + if opts.additional_args ~= nil then + if type(opts.additional_args) == "function" then + additional_args = opts.additional_args(opts) + elseif type(opts.additional_args) == "table" then + additional_args = opts.additional_args + end + end + if opts.search_dirs then for i, path in ipairs(opts.search_dirs) do opts.search_dirs[i] = vim.fn.expand(path) @@ -43,7 +52,7 @@ local live_grep_args = function(opts) return nil end - local args = tbl_clone(opts.vimgrep_arguments) + local args = vim.tbl_flatten({ tbl_clone(opts.vimgrep_arguments), tbl_clone(additional_args) }) local prompt_parts = prompt_parser.parse(prompt, opts.auto_quoting) local cmd = vim.tbl_flatten({ args, prompt_parts, opts.search_dirs })