local conditions = require("heirline.conditions") local utils = require("heirline.utils") local FileNameBlock = { -- let's first set up some attributes needed by this component and it's children init = function(self) self.filename = vim.api.nvim_buf_get_name(0) end, } -- We can now define some children separately and add them later local FileIcon = { init = function(self) local filename = self.filename self.icon = vim.fn["nerdfont#find"](filename) end, provider = function(self) return self.icon and (self.icon .. " ") end, hl = { fg = utils.get_highlight("Directory").fg }, } local FileName = { provider = function(self) -- first, trim the pattern relative to the current directory. For other -- options, see :h filename-modifers local filename = vim.fn.fnamemodify(self.filename, ":.") if filename == "" then return "[No Name]" end -- now, if the filename would occupy more than 1/4th of the available -- space, we trim the file path to its initials -- See Flexible Components section below for dynamic truncation if not conditions.width_percent_below(#filename, 0.25) then filename = vim.fn.pathshorten(filename) end return filename end, hl = { fg = utils.get_highlight("Directory").fg }, } local FileFlags = { { condition = function() return vim.bo.modified end, provider = "[+]", hl = { fg = "green" }, }, { condition = function() return not vim.bo.modifiable or vim.bo.readonly end, provider = "", hl = { fg = "orange" }, }, } -- let's add the children to our FileNameBlock component FileNameBlock = utils.insert( FileNameBlock, FileIcon, FileName, -- a new table where FileName is a child of FileNameModifier FileFlags, { provider = "%<" } -- this means that the statusline is cut here when there's not enough space ) return FileNameBlock