diff --git a/doc/telescope.txt b/doc/telescope.txt index 42e1006..6bb4947 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1213,6 +1213,10 @@ builtin.command_history({opts}) *telescope.builtin.command_history()* Parameters: ~ {opts} (table) options to pass to the picker + Options: ~ + {filter_fn} (function) filter fn(cmd:string). true if the history + command should be presented. + builtin.search_history({opts}) *telescope.builtin.search_history()* Lists searches that were executed recently, and reruns them on `` diff --git a/lua/telescope/builtin/__internal.lua b/lua/telescope/builtin/__internal.lua index 9b6931d..d0f32a3 100644 --- a/lua/telescope/builtin/__internal.lua +++ b/lua/telescope/builtin/__internal.lua @@ -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 diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index b912c80..4c069f0 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -271,6 +271,7 @@ builtin.oldfiles = require_on_exported_call("telescope.builtin.__internal").oldf --- - Default keymaps: --- - ``: open the command line with the text of the currently selected result populated in it ---@param opts table: options to pass to the picker +---@field filter_fn function: filter fn(cmd:string). true if the history command should be presented. builtin.command_history = require_on_exported_call("telescope.builtin.__internal").command_history --- Lists searches that were executed recently, and reruns them on ``