feat(make_entry): replace $HOME with '~' where possible (#436)

main
bhagwan 2 years ago
parent 3079c9561a
commit 62f67b6194

@ -491,7 +491,7 @@ M.set_header = function(opts, hdr_tbl)
cwd = path.relative(cwd, vim.loop.cwd())
end
-- make our home dir path look pretty
return cwd:gsub("^"..vim.env.HOME, "~")
return path.HOME_to_tilde(cwd)
end
},
search = {

@ -312,6 +312,10 @@ M.file = function(opts, x)
-- TODO: does this work if there are ANSI escape codes in x?
x = path.relative(x, opts.cwd)
end
-- replace $HOME with ~
if path.starts_with_separator(x) then
x = path.HOME_to_tilde(x)
end
if opts.path_shorten then
x = path.shorten(x, tonumber(opts.path_shorten))
end

@ -125,6 +125,14 @@ local function find_next(str, char, start_idx)
end
end
function M.tilde_to_HOME(path)
return path and path:gsub("^~", vim.env.HOME) or nil
end
function M.HOME_to_tilde(path)
return path and path:gsub("^"..vim.env.HOME, "~") or nil
end
function M.shorten(path, max_len)
local sep = M.separator()
local parts = {}
@ -200,6 +208,7 @@ function M.entry_to_file(entry, opts, force_uri)
-- Remove ansi coloring and prefixed icons
entry = utils.strip_ansi_coloring(entry)
local stripped, idx = stripBeforeLastOccurrenceOf(entry, utils.nbsp)
stripped = M.tilde_to_HOME(stripped)
local isURI = stripped:match("^%a+://")
-- Prepend cwd before constructing the URI (#341)
if cwd and #cwd>0 and not isURI and

@ -614,6 +614,7 @@ function Previewer.buffer_or_file:update_border(entry)
if entry.path and self.opts.cwd then
entry.path = path.relative(entry.path, self.opts.cwd)
end
entry.path = path.HOME_to_tilde(entry.path)
local title = (' %s '):format(entry.path or entry.uri)
if entry.bufnr then
-- local border_width = api.nvim_win_get_width(self.win.preview_winid)

@ -120,7 +120,7 @@ local function gen_buffer_entry(opts, buf, hl_curbuf)
bufname = path.basename(bufname)
end
-- replace $HOME with '~' for paths outside of cwd
bufname = bufname:gsub("^"..vim.env.HOME, "~")
bufname = path.HOME_to_tilde(bufname)
-- add line number
bufname = ("%s:%s"):format(bufname, buf.info.lnum>0 and buf.info.lnum or "")
if buf.flag == '%' then

Loading…
Cancel
Save