fix: Multiple Previewer fixes (#225)
Fixes previews for files beginning with ~/ Previewer will now show directories Fix if clause with vim.fn.executable
This commit is contained in:
@@ -842,9 +842,7 @@ builtin.man_pages = function(opts)
|
|||||||
|
|
||||||
local cmd = opts.man_cmd or "apropos --sections=1 ''"
|
local cmd = opts.man_cmd or "apropos --sections=1 ''"
|
||||||
|
|
||||||
local f = assert(io.popen(cmd, 'r'))
|
local pages = utils.get_os_command_output(cmd)
|
||||||
local pages = assert(f:read('*a'))
|
|
||||||
f:close()
|
|
||||||
|
|
||||||
local lines = {}
|
local lines = {}
|
||||||
for s in pages:gmatch("[^\r\n]+") do
|
for s in pages:gmatch("[^\r\n]+") do
|
||||||
|
|||||||
@@ -21,7 +21,15 @@ Previewer.__index = Previewer
|
|||||||
local bat_options = {"--style=plain", "--color=always", "--paging=always"}
|
local bat_options = {"--style=plain", "--color=always", "--paging=always"}
|
||||||
local has_less = (vim.fn.executable('less') == 1) and config.values.use_less
|
local has_less = (vim.fn.executable('less') == 1) and config.values.use_less
|
||||||
|
|
||||||
|
local get_file_stat = function(filename)
|
||||||
|
return assert(vim.loop.fs_stat(vim.fn.expand(filename)))
|
||||||
|
end
|
||||||
|
|
||||||
local bat_maker = function(filename, lnum, start, finish)
|
local bat_maker = function(filename, lnum, start, finish)
|
||||||
|
if get_file_stat(filename).type == 'directory' then
|
||||||
|
return { 'ls', '-la' }
|
||||||
|
end
|
||||||
|
|
||||||
local command = {"bat"}
|
local command = {"bat"}
|
||||||
local theme = os.getenv("BAT_THEME")
|
local theme = os.getenv("BAT_THEME")
|
||||||
|
|
||||||
@@ -46,23 +54,26 @@ local bat_maker = function(filename, lnum, start, finish)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return flatten {
|
return flatten {
|
||||||
command, bat_options, "--", filename
|
command, bat_options, "--", vim.fn.expand(filename)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: Add other options for cat to do this better
|
-- TODO: Add other options for cat to do this better
|
||||||
local cat_maker = function(filename, _, _, _)
|
local cat_maker = function(filename, _, _, _)
|
||||||
if vim.fn.executable('file') then
|
if get_file_stat(filename).type == 'directory' then
|
||||||
local handle = io.popen('file --mime-type -b ' .. filename)
|
return { 'ls', '-la' }
|
||||||
local mime_type = vim.split(handle:read('*a'), '/')[1]
|
end
|
||||||
handle:close()
|
|
||||||
|
if 1 == vim.fn.executable('file') then
|
||||||
|
local output = utils.get_os_command_output('file --mime-type -b ' .. filename)
|
||||||
|
local mime_type = vim.split(output, '/')[1]
|
||||||
if mime_type ~= "text" then
|
if mime_type ~= "text" then
|
||||||
return { "echo", "Binary file found. These files cannot be displayed!" }
|
return { "echo", "Binary file found. These files cannot be displayed!" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"cat", "--", filename
|
"cat", "--", vim.fn.expand(filename)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -190,4 +190,11 @@ function utils.display_termcodes(str)
|
|||||||
return str:gsub(string.char(9), "<TAB>"):gsub("", "<C-F>"):gsub(" ", "<Space>")
|
return str:gsub(string.char(9), "<TAB>"):gsub("", "<C-F>"):gsub(" ", "<Space>")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function utils.get_os_command_output(cmd)
|
||||||
|
local handle = assert(io.popen(cmd, 'r'))
|
||||||
|
local output = assert(handle:read('*a'))
|
||||||
|
assert(handle:close())
|
||||||
|
return output
|
||||||
|
end
|
||||||
|
|
||||||
return utils
|
return utils
|
||||||
|
|||||||
Reference in New Issue
Block a user