From c9a974d91261c7053bf4f715395beebfa3afcd71 Mon Sep 17 00:00:00 2001 From: Mudox Date: Wed, 13 Apr 2022 12:59:53 +0800 Subject: [PATCH] feat: hide filename extension for buffers component (#629) --- README.md | 1 + lua/lualine/components/buffers/buffer.lua | 13 +++++++++++-- lua/lualine/components/buffers/init.lua | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f2648e4..7a4a298 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/lualine/components/buffers/buffer.lua b/lua/lualine/components/buffers/buffer.lua index 8af11a3..0fbe7f0 100644 --- a/lua/lualine/components/buffers/buffer.lua +++ b/lua/lualine/components/buffers/buffer.lua @@ -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 diff --git a/lua/lualine/components/buffers/init.lua b/lua/lualine/components/buffers/init.lua index 964c4fa..4506269 100644 --- a/lua/lualine/components/buffers/init.lua +++ b/lua/lualine/components/buffers/init.lua @@ -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,