feat(picker): command history filter (#2132)
* feat(picker): command history filter
I've recently start using command history. For sometime was a bit annoyed of unrelevant commands
like edit/write and others (most likely only used once)
I've considered using lua patterns, however, logical `or` isn't a thing. Additionally, passing a list of lua patterns and checking each pattern for each command history entry felt tedious.
This PR introduce a new optional function to filter command history items.
For example, in my configurations
~~~lua
local command_history_ignore = vim.regex "edit\\|Move\\|write\\|Write\\|e\\s\\|lua\\sI("
overrides.command_history = minimal {
prompt_prefix = "CMDHistory> ",
filter_fn = function(item)
if #item < 3 then
return false
else
return not command_history_ignore:match_str(item)
end
end,
}
~~~
* [docgen] Update doc/telescope.txt
skip-checks: true
Co-authored-by: Github Actions <actions@github>
This commit is contained in:
@@ -542,10 +542,20 @@ internal.command_history = function(opts)
|
||||
local history_list = vim.split(history_string, "\n")
|
||||
|
||||
local results = {}
|
||||
local filter_fn = opts.filter_fn
|
||||
|
||||
for i = #history_list, 3, -1 do
|
||||
local item = history_list[i]
|
||||
local _, finish = string.find(item, "%d+ +")
|
||||
table.insert(results, string.sub(item, finish + 1))
|
||||
local cmd = string.sub(item, finish + 1)
|
||||
|
||||
if filter_fn then
|
||||
if filter_fn(cmd) then
|
||||
table.insert(results, cmd)
|
||||
end
|
||||
else
|
||||
table.insert(results, cmd)
|
||||
end
|
||||
end
|
||||
|
||||
pickers
|
||||
|
||||
Reference in New Issue
Block a user