broke the tele picker, fix pt 3
This commit is contained in:
parent
a5b0da62c1
commit
12ae5d3a90
|
@ -4,25 +4,38 @@ local finders = require 'telescope.finders'
|
||||||
local sorters = require('telescope.config').values
|
local sorters = require('telescope.config').values
|
||||||
local actions = require 'telescope.actions'
|
local actions = require 'telescope.actions'
|
||||||
local action_state = require 'telescope.actions.state'
|
local action_state = require 'telescope.actions.state'
|
||||||
local Path = require 'plenary.path'
|
|
||||||
|
|
||||||
local function collect_executables(start_dir)
|
local function collect_executables(start_dir)
|
||||||
local results = {}
|
local results = {}
|
||||||
local fd = vim.fn.systemlist { 'fd', '--type', 'x', '--exec', 'file', '{}', start_dir }
|
local fd_result = vim
|
||||||
for _, line in ipairs(fd) do
|
.system({
|
||||||
|
'fd',
|
||||||
|
'--type',
|
||||||
|
'x',
|
||||||
|
'--exec',
|
||||||
|
'file',
|
||||||
|
'{}',
|
||||||
|
start_dir,
|
||||||
|
}, { text = true })
|
||||||
|
:wait()
|
||||||
|
|
||||||
|
local lines = vim.split(fd_result.stdout, '\n', { trimempty = true })
|
||||||
|
|
||||||
|
for _, line in ipairs(lines) do
|
||||||
local path, typeinfo = line:match '^(.-):%s*(.+)$'
|
local path, typeinfo = line:match '^(.-):%s*(.+)$'
|
||||||
if path and not path:match 'CMakeFiles' and typeinfo and typeinfo:match 'Mach%-O' or typeinfo:match 'ELF' then
|
if path and not path:match 'CMakeFiles' and typeinfo and (typeinfo:match 'Mach%-O' or typeinfo:match 'ELF') then
|
||||||
table.insert(results, path)
|
table.insert(results, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return results
|
return results
|
||||||
end
|
end
|
||||||
|
|
||||||
local function pick_executable(start_dir)
|
local function pick_executable(start_dir)
|
||||||
return async.wrap(function(start_dir, on_choice)
|
return async.wrap(function(_start_dir, on_choice)
|
||||||
local executables = collect_executables(start_dir)
|
local executables = collect_executables(_start_dir)
|
||||||
if #executables == 0 then
|
if #executables == 0 then
|
||||||
vim.notify('No executables found in ' .. start_dir, vim.log.levels.WARN)
|
vim.notify('No executables found in ' .. _start_dir, vim.log.levels.WARN)
|
||||||
on_choice(nil)
|
on_choice(nil)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -33,17 +46,17 @@ local function pick_executable(start_dir)
|
||||||
finder = finders.new_table { results = executables },
|
finder = finders.new_table { results = executables },
|
||||||
sorter = sorters.generic_sorter {},
|
sorter = sorters.generic_sorter {},
|
||||||
attach_mappings = function(_, map)
|
attach_mappings = function(_, map)
|
||||||
actions.select_default:replace(function(prompt_bufnr)
|
actions.select_default:replace(function(bufnr)
|
||||||
local entry = action_state.get_selected_entry()
|
local entry = action_state.get_selected_entry()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(bufnr)
|
||||||
on_choice(entry.value)
|
on_choice(entry.value)
|
||||||
end)
|
end)
|
||||||
map('i', '<Esc>', function(buf)
|
map('i', '<Esc>', function(bufnr)
|
||||||
actions.close(buf)
|
actions.close(bufnr)
|
||||||
on_choice(nil)
|
on_choice(nil)
|
||||||
end)
|
end)
|
||||||
map('n', 'q', function(buf)
|
map('n', 'q', function(bufnr)
|
||||||
actions.close(buf)
|
actions.close(bufnr)
|
||||||
on_choice(nil)
|
on_choice(nil)
|
||||||
end)
|
end)
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue