feat: hide filename extension for buffers component (#629)

This commit is contained in:
Mudox 2022-04-13 12:59:53 +08:00 committed by GitHub
parent bb8dd4c1c5
commit c9a974d912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -434,6 +434,7 @@ sections = {
{
'buffers',
show_filename_only = true, -- Shows shortened relative path when set to false.
hide_filename_extension = false, -- Hide filename extension when set to true.
show_modified_status = true, -- Shows indicator when the buffer is modified.
mode = 0, -- 0: Shows buffer name

View File

@ -132,8 +132,17 @@ function Buffer:name()
elseif self.file == '' then
return '[No Name]'
end
return self.options.show_filename_only and vim.fn.fnamemodify(self.file, ':t')
or vim.fn.pathshorten(vim.fn.fnamemodify(self.file, ':p:.'))
local name
if self.options.show_filename_only then
name = vim.fn.fnamemodify(self.file, ':t')
else
name = vim.fn.pathshorten(vim.fn.fnamemodify(self.file, ':p:.'))
end
if self.options.hide_filename_extension then
name = vim.fn.fnamemodify(name, ':r')
end
return name
end
---adds spaces to left and right

View File

@ -7,6 +7,7 @@ local highlight = require('lualine.highlight')
local default_options = {
show_filename_only = true,
hide_filename_extension = false,
show_modified_status = true,
mode = 0,
max_length = 0,