added preview for files which spaces in names. (#35)

TODO: Still need to do better escaping.
This commit is contained in:
Subeet Kumar Dutta
2020-09-06 01:19:01 +05:30
committed by GitHub
parent 639497ae6d
commit d3c9b65252

View File

@@ -140,10 +140,10 @@ previewers.vim_buffer_or_bat = defaulter(function(_)
local file_name = vim.split(value, ":")[1] local file_name = vim.split(value, ":")[1]
log.trace("Previewing File: %s", file_name) log.trace("Previewing File: '%s'", file_name)
-- vim.fn.termopen( -- vim.fn.termopen(
-- string.format("bat --color=always --style=grid %s"), -- string.format("bat --color=always --style=grid '%s'"),
-- vim.fn.fnamemodify(file_name, ":p") -- vim.fn.fnamemodify(file_name, ":p")
local bufnr = vim.fn.bufadd(file_name) local bufnr = vim.fn.bufadd(file_name)
@@ -159,7 +159,7 @@ previewers.vim_buffer_or_bat = defaulter(function(_)
vim.api.nvim_win_set_option(status.preview_win, 'signcolumn', 'no') vim.api.nvim_win_set_option(status.preview_win, 'signcolumn', 'no')
vim.api.nvim_win_set_option(status.preview_win, 'foldlevel', 100) vim.api.nvim_win_set_option(status.preview_win, 'foldlevel', 100)
else else
vim.api.nvim_buf_set_lines(status.preview_bufnr, 0, -1, false, vim.fn.systemlist(string.format('bat %s', file_name))) vim.api.nvim_buf_set_lines(status.preview_bufnr, 0, -1, false, vim.fn.systemlist(string.format('bat "%s"', file_name)))
end end
end, end,
} }
@@ -168,9 +168,9 @@ end, {})
previewers.cat = defaulter(function(opts) previewers.cat = defaulter(function(opts)
return previewers.new { return previewers.new {
setup = function() setup = function()
local command_string = "cat %s" local command_string = "cat '%s'"
if 1 == vim.fn.executable("bat") then if 1 == vim.fn.executable("bat") then
command_string = "bat %s --style=grid --paging=always" command_string = "bat '%s' --style=grid --paging=always"
end end
return { return {
@@ -203,9 +203,9 @@ end, {})
previewers.vimgrep = defaulter(function(_) previewers.vimgrep = defaulter(function(_)
return previewers.new { return previewers.new {
setup = function() setup = function()
local command_string = "cat %s" local command_string = "cat '%s'"
if vim.fn.executable("bat") then if vim.fn.executable("bat") then
command_string = "bat %s --highlight-line %s -r %s:%s" .. bat_options command_string = "bat '%s' --highlight-line '%s' -r '%s':'%s'" .. bat_options
end end
return { return {
@@ -244,9 +244,9 @@ end, {})
previewers.qflist = defaulter(function(_) previewers.qflist = defaulter(function(_)
return previewers.new { return previewers.new {
setup = function() setup = function()
local command_string = "cat %s" local command_string = "cat '%s'"
if vim.fn.executable("bat") then if vim.fn.executable("bat") then
command_string = "bat %s --highlight-line %s -r %s:%s" .. bat_options command_string = "bat '%s' --highlight-line '%s' -r '%s':'%s'" .. bat_options
end end
return { return {