diff --git a/README.md b/README.md index 9e7327b..99ae41f 100644 --- a/README.md +++ b/README.md @@ -593,6 +593,7 @@ sections = { { 'filename', file_status = true, -- Displays file status (readonly status, modified status) + newfile_status = false -- Display new file status (new file means no write after created) path = 0, -- 0: Just the filename -- 1: Relative path -- 2: Absolute path @@ -604,6 +605,7 @@ sections = { modified = '[+]', -- Text to show when the file is modified. readonly = '[-]', -- Text to show when the file is non-modifiable or readonly. unnamed = '[No Name]', -- Text to show for unnamed buffers. + newfile = '[New]', -- Text to show for new created file before first writting } } } diff --git a/lua/lualine/components/filename.lua b/lua/lualine/components/filename.lua index f68dba7..39c4728 100644 --- a/lua/lualine/components/filename.lua +++ b/lua/lualine/components/filename.lua @@ -7,8 +7,14 @@ local modules = require('lualine_require').lazy_require { } local default_options = { - symbols = { modified = '[+]', readonly = '[-]', unnamed = '[No Name]' }, + symbols = { + modified = '[+]', + readonly = '[-]', + unnamed = '[No Name]', + newfile = '[New]', + }, file_status = true, + newfile_status = false, path = 0, shorting_target = 40, } @@ -21,6 +27,11 @@ local function count(base, pattern) return select(2, string.gsub(base, pattern, '')) end +local function is_new_file() + local filename = vim.fn.expand('%') + return vim.bo.buftype == '' and vim.fn.filereadable(filename) == 0 +end + ---shortens path by turning apple/orange -> a/orange ---@param path string ---@param sep string path separator @@ -77,6 +88,10 @@ M.update_status = function(self) data = data .. self.options.symbols.readonly end end + + if self.options.newfile_status and is_new_file() then + data = data .. self.options.symbols.newfile + end return data end