feat(nvim): make heirline format terminal fts better

This commit is contained in:
Price Hiller 2023-09-05 11:00:18 -05:00
parent 04bfe7e9b1
commit 3e707923a7
Signed by: Price
SSH Key Fingerprint: SHA256:Y4S9ZzYphRn1W1kbJerJFO6GGsfu9O70VaBSxJO7dF8

View File

@ -162,17 +162,21 @@ return {
local FileName = { local FileName = {
provider = function(self) provider = function(self)
-- first, trim the pattern relative to the current directory. For other local filename = ""
-- options, see :h filename-modifers if self.filename:match("^term://.*") then
local filename = vim.fn.fnamemodify(self.filename, ":.") local term_name = ""
if filename == "" then local subs = 0
return "[No Name]" term_name, subs = self.filename:gsub(".*;", "")
if subs == 0 then
term_name = self.filename:gsub(".*:", "")
end end
-- now, if the filename would occupy more than 1/4th of the available filename = term_name .. ""
-- space, we trim the file path to its initials else
-- See Flexible Components section below for dynamic truncation ---@diagnostic disable-next-line: cast-local-type
if not conditions.width_percent_below(#filename, 0.25) then filename = vim.fn.fnamemodify(self.filename, ":~:.")
filename = vim.fn.pathshorten(filename) end
if filename == "" then
filename = "[No Name]"
end end
return filename return filename
end, end,
@ -269,7 +273,11 @@ return {
-- we redefine the filename component, as we probably only want the tail and not the relative path -- we redefine the filename component, as we probably only want the tail and not the relative path
local StatusLineFileName = { local StatusLineFileName = {
init = function(self) init = function(self)
if self.filename:match("^term://.*") then
self.lfilename = self.filename:gsub(".*:", "")
else
self.lfilename = vim.fn.fnamemodify(self.filename, ":~:.") self.lfilename = vim.fn.fnamemodify(self.filename, ":~:.")
end
if self.lfilename == "" then if self.lfilename == "" then
self.lfilename = "[No Name]" self.lfilename = "[No Name]"
end end