dotfiles/config/nvim/lua/lualine/components/custom/filename.lua

36 lines
973 B
Lua

local M = require("lualine.component"):extend()
function M:init(options)
M.super.init(self, options)
local color = self.options.color or {}
local modified = { gui = "italic" }
self.custom_highlights = { -- [is_focused, modified]
[true] = {
[true] = self:create_hl(vim.tbl_extend("force", color, modified), "focus_modified"),
[false] = self:create_hl(color, "focus"),
},
[false] = {
[true] = self:create_hl(modified, "nofocus_modified"),
[false] = self:create_hl({}, "nofocus"),
},
}
end
function M:update_status(is_focused)
self.options.color_highlight = self.custom_highlights[is_focused][vim.bo.modified]
local path = vim.fn.expand("%:~:.")
local window = require("util.window")
if window.is_wide() then
return path
elseif window.is_medium() then
return vim.fn.pathshorten(path) -- only first letter of directories
else
return vim.fn.fnamemodify(path, ":t") -- only tail
end
end
return M