Skip to content

Commit fec63d4

Browse files
committed
feat: add :CommandTFd
Which uses: - https://github.com/sharkdp/fd Closes: #433
1 parent ddc4fe4 commit fec63d4

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

doc/command-t.txt

+7
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ COMMANDS *command-t-commands*
313313
except that the selection is limited to files that
314314
you already have open in buffers.
315315

316+
*:CommandTFd
317+
|:CommandTFd| Brings up the Command-T file window, starting in the current
318+
working directory as returned by the |:pwd| command. Scans
319+
for files using `fd`.
320+
316321
*:CommandTFind*
317322
|:CommandTFind| Brings up the Command-T file window, starting in the current
318323
working directory as returned by the |:pwd| command. Scans
@@ -918,6 +923,8 @@ main (not yet released) ~
918923
(https://github.com/wincent/command-t/discussions/429).
919924
- feat: add |commandt.setup.match_listing.icons| setting
920925
(https://github.com/wincent/command-t/issues/430).
926+
- feat: add |:CommandTFd|
927+
(https://github.com/wincent/command-t/issues/433).
921928

922929
6.0.0-b.1 (16 December 2022) ~
923930

lua/wincent/commandt/init.lua

+34
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ local options_spec = {
199199
scanners = {
200200
kind = 'table',
201201
keys = {
202+
fd = {
203+
kind = 'table',
204+
keys = {
205+
max_files = { kind = 'number' },
206+
},
207+
optional = true,
208+
},
202209
find = {
203210
kind = 'table',
204211
keys = {
@@ -303,6 +310,30 @@ local default_options = {
303310
end,
304311
options = force_dot_files,
305312
},
313+
fd = {
314+
command = function(directory, options)
315+
if vim.startswith(directory, './') then
316+
directory = directory:sub(3, -1)
317+
end
318+
if directory ~= '' and directory ~= '.' then
319+
directory = vim.fn.shellescape(directory)
320+
elseif directory == '' then
321+
directory = '.'
322+
end
323+
local drop = 0
324+
if directory == '.' then
325+
drop = 2
326+
end
327+
local command = 'fd --hidden --print0 --search-path'
328+
command = command .. ' ' .. directory
329+
command = command .. ' 2> /dev/null'
330+
return command, drop
331+
end,
332+
fallback = true,
333+
max_files = function(options)
334+
return options.scanners.fd.max_files
335+
end,
336+
},
306337
find = {
307338
command = function(directory, options)
308339
if vim.startswith(directory, './') then
@@ -526,6 +557,9 @@ local default_options = {
526557
open = open,
527558
root_markers = { '.git', '.hg', '.svn', '.bzr', '_darcs' },
528559
scanners = {
560+
fd = {
561+
max_files = 0,
562+
},
529563
file = {
530564
max_files = 0,
531565
},

plugin/command-t.lua

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local CommandTWatchman = nil
99
if vim.g.CommandTPreferredImplementation == 'lua' then
1010
CommandT = 'CommandT'
1111
CommandTBuffer = 'CommandTBuffer'
12+
CommandTFd = 'CommandTFd'
1213
CommandTFind = 'CommandTFind'
1314
CommandTGit = 'CommandTGit'
1415
CommandTHelp = 'CommandTHelp'
@@ -18,6 +19,7 @@ if vim.g.CommandTPreferredImplementation == 'lua' then
1819

1920
vim.keymap.set('n', '<Plug>(CommandT)', ':CommandT<CR>', { silent = true })
2021
vim.keymap.set('n', '<Plug>(CommandTBuffer)', ':CommandTBuffer<CR>', { silent = true })
22+
vim.keymap.set('n', '<Plug>(CommandTFd)', ':CommandTFd<CR>', { silent = true })
2123
vim.keymap.set('n', '<Plug>(CommandTFind)', ':CommandTFind<CR>', { silent = true })
2224
vim.keymap.set('n', '<Plug>(CommandTGit)', ':CommandTGit<CR>', { silent = true })
2325
vim.keymap.set('n', '<Plug>(CommandTHelp)', ':CommandTHelp<CR>', { silent = true })
@@ -27,6 +29,7 @@ if vim.g.CommandTPreferredImplementation == 'lua' then
2729
else
2830
CommandT = 'KommandT'
2931
CommandTBuffer = 'KommandTBuffer'
32+
CommandTFd = 'KommandTFd'
3033
CommandTFind = 'KommandTFind'
3134
CommandTGit = 'KommandTGit'
3235
CommandTHelp = 'KommandTHelp'
@@ -48,6 +51,13 @@ end, {
4851
nargs = 0,
4952
})
5053

54+
vim.api.nvim_create_user_command(CommandTFd, function(command)
55+
require('wincent.commandt').finder('fd', command.args)
56+
end, {
57+
complete = 'dir',
58+
nargs = '?',
59+
})
60+
5161
vim.api.nvim_create_user_command(CommandTFind, function(command)
5262
require('wincent.commandt').finder('find', command.args)
5363
end, {

0 commit comments

Comments
 (0)