@@ -135,6 +135,40 @@ M.setup = function()
135
135
end , { nargs = 1 })
136
136
end
137
137
138
+ M .command_history = function (opts )
139
+ local history_count = vim .fn .histnr (" cmd" )
140
+ local results = {}
141
+ for i = history_count , 1 , - 1 do
142
+ table.insert (results , vim .fn .histget (" cmd" , i ))
143
+ end
144
+
145
+ local pickers = require " telescope.pickers"
146
+ local finders = require " telescope.finders"
147
+ local actions = require " telescope.actions"
148
+ local conf = require (" telescope.config" ).values
149
+
150
+ -- The rest of this function is copied from Telescope's command_history function.
151
+ -- The reason we are not using Telescope's command_history is because Telescope uses `:history cmd` which truncates items.
152
+ -- https://sourcegraph.com/github.com/nvim-telescope/[email protected] /-/blob/lua/telescope/builtin/__internal.lua?L566-567
153
+ pickers
154
+ .new (opts , {
155
+ prompt_title = " Command History" ,
156
+ finder = finders .new_table (results ),
157
+ sorter = conf .generic_sorter (opts ),
158
+
159
+ attach_mappings = function (_ , map )
160
+ actions .select_default :replace (actions .set_command_line )
161
+ map ({ " i" , " n" }, " <C-e>" , actions .edit_command_line )
162
+
163
+ -- TODO: Find a way to insert the text... it seems hard.
164
+ -- map('i', '<C-i>', actions.insert_value, { expr = true })
165
+
166
+ return true
167
+ end ,
168
+ })
169
+ :find ()
170
+ end
171
+
138
172
-- This sorter/matcher will preserve the order of the results, while still
139
173
-- allowing for fuzzy matching. This is useful for the command history search,
140
174
-- where we want to show the most recent commands first, but still allow for
@@ -168,7 +202,7 @@ M.telescope_history_search = function()
168
202
end
169
203
170
204
return function ()
171
- require ( ' telescope.builtin ' ) .command_history ({sorter = preserve_order_fuzzy_sorter ()})
205
+ M .command_history ({sorter = preserve_order_fuzzy_sorter ()})
172
206
end
173
207
end
174
208
0 commit comments