[filename] support detect new file status (#785)
* [filename] support detect new file status * update readme about new file status * add definition for new file
This commit is contained in:
parent
e22c7b3c9b
commit
679e9e71de
|
@ -593,6 +593,7 @@ sections = {
|
||||||
{
|
{
|
||||||
'filename',
|
'filename',
|
||||||
file_status = true, -- Displays file status (readonly status, modified status)
|
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
|
path = 0, -- 0: Just the filename
|
||||||
-- 1: Relative path
|
-- 1: Relative path
|
||||||
-- 2: Absolute path
|
-- 2: Absolute path
|
||||||
|
@ -604,6 +605,7 @@ sections = {
|
||||||
modified = '[+]', -- Text to show when the file is modified.
|
modified = '[+]', -- Text to show when the file is modified.
|
||||||
readonly = '[-]', -- Text to show when the file is non-modifiable or readonly.
|
readonly = '[-]', -- Text to show when the file is non-modifiable or readonly.
|
||||||
unnamed = '[No Name]', -- Text to show for unnamed buffers.
|
unnamed = '[No Name]', -- Text to show for unnamed buffers.
|
||||||
|
newfile = '[New]', -- Text to show for new created file before first writting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,14 @@ local modules = require('lualine_require').lazy_require {
|
||||||
}
|
}
|
||||||
|
|
||||||
local default_options = {
|
local default_options = {
|
||||||
symbols = { modified = '[+]', readonly = '[-]', unnamed = '[No Name]' },
|
symbols = {
|
||||||
|
modified = '[+]',
|
||||||
|
readonly = '[-]',
|
||||||
|
unnamed = '[No Name]',
|
||||||
|
newfile = '[New]',
|
||||||
|
},
|
||||||
file_status = true,
|
file_status = true,
|
||||||
|
newfile_status = false,
|
||||||
path = 0,
|
path = 0,
|
||||||
shorting_target = 40,
|
shorting_target = 40,
|
||||||
}
|
}
|
||||||
|
@ -21,6 +27,11 @@ local function count(base, pattern)
|
||||||
return select(2, string.gsub(base, pattern, ''))
|
return select(2, string.gsub(base, pattern, ''))
|
||||||
end
|
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
|
---shortens path by turning apple/orange -> a/orange
|
||||||
---@param path string
|
---@param path string
|
||||||
---@param sep string path separator
|
---@param sep string path separator
|
||||||
|
@ -77,6 +88,10 @@ M.update_status = function(self)
|
||||||
data = data .. self.options.symbols.readonly
|
data = data .. self.options.symbols.readonly
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.options.newfile_status and is_new_file() then
|
||||||
|
data = data .. self.options.symbols.newfile
|
||||||
|
end
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue