better handling of '--ansi' flag, detect extension on filenames with space

main
bhagwan 3 years ago
parent 2ae75cba96
commit bdbd662468

@ -44,8 +44,10 @@ M.vimcmd_file = function(vimcmd, selected)
for i = 2, #selected do
local entry = path.entry_to_file(selected[i])
vim.cmd(vimcmd .. " " .. vim.fn.fnameescape(entry.path))
vim.api.nvim_win_set_cursor(0, {tonumber(entry.line), tonumber(entry.col)-1})
vim.cmd("norm! zz")
if entry.line > 1 or entry.col > 1 then
vim.api.nvim_win_set_cursor(0, {tonumber(entry.line), tonumber(entry.col)-1})
vim.cmd("norm! zz")
end
end
end

@ -127,7 +127,7 @@ end
local get_git_indicator = function(file, diff_files, untracked_files)
-- remove colors from `rg` output
file = file:gsub("%[%d+m", "")
file = utils.strip_ansi_coloring(file)
if diff_files and diff_files[file] then
return diff_files[file]
end

@ -46,11 +46,10 @@ end
function M.extension(path)
-- path = M.basename(path)
-- return path:match(".+%.(.*)")
-- search for the first dotten string part up to space
-- then match anything after the dot up to ':/\.'
path = path:match("(%.[^ :\t\x1b]+)")
if not path then return path end
return path:match("^.*%.([^ :\\/]+)")
-- 1. match anything before the first ':'
-- 2. greedy match anything after the last dot
-- 3. remove coloring escape sequence
return utils.strip_ansi_coloring(path:match("[^:]+"):match("[^.]*$"))
end
---Get the path to the parent directory of the given path. Returns `nil` if the
@ -133,6 +132,7 @@ local function lastIndexOf(haystack, needle)
end
function M.entry_to_file(entry, cwd)
entry = utils.strip_ansi_coloring(entry)
local sep = ":"
local s = strsplit(entry, sep)
local file = s[1]:match("[^"..utils.nbsp.."]*$")

@ -180,6 +180,14 @@ for color, escseq in pairs(M.ansi_colors) do
end
end
function M.strip_ansi_coloring(str)
if not str then return str end
-- remove escape sequences of the following formats:
-- 1. ^[[34m
-- 2. ^[[0;34m
return str:gsub("%[[%d;]+m", "")
end
function M.get_visual_selection()
-- this will exit visual mode
-- use 'gv' to reselect the text

Loading…
Cancel
Save