From 44a0fba86721c248d907ee5227fdc617a03cdef4 Mon Sep 17 00:00:00 2001 From: Mika Raunio Date: Fri, 31 Mar 2023 11:02:12 +0300 Subject: [PATCH 01/18] feat: add name+parent path option for component(filename) (#945) Co-authored-by: Mika Raunio --- README.md | 1 + lua/lualine/components/filename.lua | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 50bbfd96c..6d988d5ac 100644 --- a/README.md +++ b/README.md @@ -626,6 +626,7 @@ sections = { -- 1: Relative path -- 2: Absolute path -- 3: Absolute path, with tilde as the home directory + -- 4: Filename and parent dir, with tilde as the home directory shorting_target = 40, -- Shortens path to leave 40 spaces in the window -- for other components. (terrible name, any suggestions?) diff --git a/lua/lualine/components/filename.lua b/lua/lualine/components/filename.lua index e35b5d553..e6da77fdf 100644 --- a/lua/lualine/components/filename.lua +++ b/lua/lualine/components/filename.lua @@ -50,12 +50,24 @@ local function shorten_path(path, sep, max_len) return table.concat(segments, sep) end +local function filename_and_parent(path, sep) + local segments = vim.split(path, sep) + if #segments == 0 then + return path + elseif #segments == 1 then + return segments[#segments] + else + return table.concat({segments[#segments - 1], segments[#segments]}, sep) + end +end + M.init = function(self, options) M.super.init(self, options) self.options = vim.tbl_deep_extend('keep', self.options or {}, default_options) end M.update_status = function(self) + local path_separator = package.config:sub(1, 1) local data if self.options.path == 1 then -- relative path @@ -66,6 +78,9 @@ M.update_status = function(self) elseif self.options.path == 3 then -- absolute path, with tilde data = vim.fn.expand('%:p:~') + elseif self.options.path == 4 then + -- filename and immediate parent + data = filename_and_parent(vim.fn.expand('%:p:~'), path_separator) else -- just filename data = vim.fn.expand('%:t') @@ -81,7 +96,6 @@ M.update_status = function(self) local windwidth = self.options.globalstatus and vim.go.columns or vim.fn.winwidth(0) local estimated_space_available = windwidth - self.options.shorting_target - local path_separator = package.config:sub(1, 1) data = shorten_path(data, path_separator, estimated_space_available) end From 4bfc6bc4f38355d570e56fed69e01c073d2b6a64 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Fri, 31 Mar 2023 08:02:48 +0000 Subject: [PATCH 02/18] chore: autogen (vimdocs+formating) --- doc/lualine.txt | 1 + lua/lualine/components/filename.lua | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/lualine.txt b/doc/lualine.txt index c4ab5115b..495275496 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -652,6 +652,7 @@ Component specific options These are options that are available on -- 1: Relative path -- 2: Absolute path -- 3: Absolute path, with tilde as the home directory + -- 4: Filename and parent dir, with tilde as the home directory shorting_target = 40, -- Shortens path to leave 40 spaces in the window -- for other components. (terrible name, any suggestions?) diff --git a/lua/lualine/components/filename.lua b/lua/lualine/components/filename.lua index e6da77fdf..fe194a7f2 100644 --- a/lua/lualine/components/filename.lua +++ b/lua/lualine/components/filename.lua @@ -57,7 +57,7 @@ local function filename_and_parent(path, sep) elseif #segments == 1 then return segments[#segments] else - return table.concat({segments[#segments - 1], segments[#segments]}, sep) + return table.concat({ segments[#segments - 1], segments[#segments] }, sep) end end From 0ddacf01ed74c8fca4af4ea926bab5b100e71616 Mon Sep 17 00:00:00 2001 From: Stefan Scherfke Date: Fri, 31 Mar 2023 10:03:47 +0200 Subject: [PATCH 03/18] feat: allow specifying theme as function (#998) Use case: I have a custom theme that dynamically adjusts to the OS' dark/light mode. If the theme can be a function, that function can return the proper color values each time it is called. --- lua/lualine.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/lualine.lua b/lua/lualine.lua index 2a87dd711..bf7651147 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -251,6 +251,9 @@ local function setup_theme() elseif type(theme_name) == 'table' then -- use the provided theme as-is return config.options.theme + elseif type(theme_name) == 'function' then + -- call function and use returned (dynamic) theme as-is + return config.options.theme() end if theme_name ~= 'auto' then notify_theme_error(theme_name) From 9170434aa100f3967b43d5d34bb9adc56fae1986 Mon Sep 17 00:00:00 2001 From: Gennaro Tedesco Date: Fri, 31 Mar 2023 17:07:07 +0200 Subject: [PATCH 04/18] added colours to qf extension to distinguish quickfix and location list (#933) * added colours to qf extension to distinguish quickfix and location list * renamed M.init() more properly * decoupling colours assignments from init method --- lua/lualine/extensions/quickfix.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/lualine/extensions/quickfix.lua b/lua/lualine/extensions/quickfix.lua index 05cced542..3a64414f6 100644 --- a/lua/lualine/extensions/quickfix.lua +++ b/lua/lualine/extensions/quickfix.lua @@ -16,6 +16,11 @@ local function title() return vim.fn.getqflist({ title = 0 }).title end +local qf_colours = { + ll = vim.api.nvim_get_hl_by_name('Constant', false).foreground, + qf = vim.api.nvim_get_hl_by_name('Identifier', false).foreground, +} + local M = {} function M.init() @@ -24,7 +29,14 @@ function M.init() end M.sections = { - lualine_a = { label }, + lualine_a = { + { + label, + color = function() + return is_loclist() and { bg = qf_colours['ll'] } or { bg = qf_colours['qf'] } + end, + }, + }, lualine_b = { title }, lualine_z = { 'location' }, } From c28a7427c3fb29322db136f0564ec58807b26747 Mon Sep 17 00:00:00 2001 From: Chris1320 Date: Mon, 3 Apr 2023 18:41:41 +0800 Subject: [PATCH 05/18] Fix: `searchcount` error (#1004) (#1005) - `searchcount.lua` now checks if the resulting table from `vim.fn.searchcount` is empty to avoid the error. Signed-off-by: Chris1320 --- lua/lualine/components/searchcount.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/lualine/components/searchcount.lua b/lua/lualine/components/searchcount.lua index dfc83861a..8274a7f73 100644 --- a/lua/lualine/components/searchcount.lua +++ b/lua/lualine/components/searchcount.lua @@ -20,6 +20,10 @@ function M:update_status() end local result = vim.fn.searchcount { maxcount = self.options.maxcount, timeout = self.options.timeout } + if next(result) == nil then + return '' + end + local denominator = math.min(result.total, result.maxcount) return string.format('[%d/%d]', result.current, denominator) end From 84ffb80e452d95e2c46fa29a98ea11a240f7843e Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sun, 9 Apr 2023 15:48:56 +0600 Subject: [PATCH 06/18] fixup: showcmd not working with %s switch to using %z for internal separator representation since %s is now used by neovim. closes #949 --- lua/lualine.lua | 18 +++++++++--------- lua/lualine/component.lua | 4 ++-- lua/lualine/components/buffers/buffer.lua | 4 ++-- lua/lualine/components/tabs/tab.lua | 4 ++-- lua/lualine/utils/section.lua | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lua/lualine.lua b/lua/lualine.lua index bf7651147..49e38a124 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -82,7 +82,7 @@ local function fill_section_separator(status, is_focused, str_checked, last_hl, end --- processes statusline string ---- replaces %s/S{sep} with proper left/right separator highlight + sep +--- replaces %z/Z{sep} with proper left/right separator highlight + sep ---@param status string : unprocessed statusline string ---@return string : processed statusline string local function apply_transitional_separators(status, is_focused) @@ -93,7 +93,7 @@ local function apply_transitional_separators(status, is_focused) local copied_pos = 1 -- Tracks how much we've copied over to status_applied local str_checked = 1 -- Tracks where the searcher head is at - -- Process entire status replace the %s{sep} & %S{sep} placeholders + -- Process entire status replace the %z{sep} & %Z{sep} placeholders -- with proper transitional separator. while str_checked ~= nil do str_checked = status:find('%%', str_checked) @@ -108,9 +108,9 @@ local function apply_transitional_separators(status, is_focused) -- %#hl_name# highlights last_hl = status:match('^%%#(.-)#', str_checked) str_checked = str_checked + #last_hl + 3 - elseif next_char == 's' then - -- %s{sep} is marker for left separator and - local sep = status:match('^%%s{(.-)}', str_checked) + elseif next_char == 'z' then + -- %z{sep} is marker for left separator and + local sep = status:match('^%%z{(.-)}', str_checked) str_checked = str_checked + #sep + 4 -- 4 = len(%{}) if not (last_hl == nil and last_hl_reseted) then local trans_sep = fill_section_separator(status, is_focused, str_checked, last_hl, sep, false) @@ -122,11 +122,11 @@ local function apply_transitional_separators(status, is_focused) last_hl_reseted = false end copied_pos = str_checked - elseif next_char == 'S' then - -- %S{sep} is marker for right separator and - local sep = status:match('^%%S{(.-)}', str_checked) + elseif next_char == 'Z' then + -- %Z{sep} is marker for right separator and + local sep = status:match('^%%Z{(.-)}', str_checked) str_checked = str_checked + #sep + 4 -- 4 = len(%{}) - if status:find('^%%s', str_checked) or status:find('^%%<%%s', str_checked) then + if status:find('^%%z', str_checked) or status:find('^%%<%%Z', str_checked) then -- When transitional right_sep and left_sep are right next to each other -- and in this exact order skip the left sep as we can't draw both. str_checked = status:find('}', str_checked) + 1 diff --git a/lua/lualine/component.lua b/lua/lualine/component.lua index cb93dc7db..a42f589bc 100644 --- a/lua/lualine/component.lua +++ b/lua/lualine/component.lua @@ -193,11 +193,11 @@ function M:apply_section_separators() return end if self.options.separator.left ~= nil and self.options.separator.left ~= '' then - self.status = string.format('%%s{%s}%s', self.options.separator.left, self.status) + self.status = string.format('%%z{%s}%s', self.options.separator.left, self.status) self.strip_previous_separator = true end if self.options.separator.right ~= nil and self.options.separator.right ~= '' then - self.status = string.format('%s%%S{%s}', self.status, self.options.separator.right) + self.status = string.format('%s%%Z{%s}', self.status, self.options.separator.right) end end diff --git a/lua/lualine/components/buffers/buffer.lua b/lua/lualine/components/buffers/buffer.lua index d5a5a2367..c58c320db 100644 --- a/lua/lualine/components/buffers/buffer.lua +++ b/lua/lualine/components/buffers/buffer.lua @@ -103,7 +103,7 @@ end ---@return string function Buffer:separator_before() if self.current or self.aftercurrent then - return '%S{' .. self.options.section_separators.left .. '}' + return '%Z{' .. self.options.section_separators.left .. '}' else return self.options.component_separators.left end @@ -113,7 +113,7 @@ end ---@return string function Buffer:separator_after() if self.current or self.beforecurrent then - return '%s{' .. self.options.section_separators.right .. '}' + return '%z{' .. self.options.section_separators.right .. '}' else return self.options.component_separators.right end diff --git a/lua/lualine/components/tabs/tab.lua b/lua/lualine/components/tabs/tab.lua index 8b768610d..8ccdc90c0 100644 --- a/lua/lualine/components/tabs/tab.lua +++ b/lua/lualine/components/tabs/tab.lua @@ -91,7 +91,7 @@ end ---@return string function Tab:separator_before() if self.current or self.aftercurrent then - return '%S{' .. self.options.section_separators.left .. '}' + return '%Z{' .. self.options.section_separators.left .. '}' else return self.options.component_separators.left end @@ -101,7 +101,7 @@ end ---@return string function Tab:separator_after() if self.current or self.beforecurrent then - return '%s{' .. self.options.section_separators.right .. '}' + return '%z{' .. self.options.section_separators.right .. '}' else return self.options.component_separators.right end diff --git a/lua/lualine/utils/section.lua b/lua/lualine/utils/section.lua index 1521a02c9..57a309b0c 100644 --- a/lua/lualine/utils/section.lua +++ b/lua/lualine/utils/section.lua @@ -48,7 +48,7 @@ function M.draw_section(section, section_name, is_focused) and (section[1].options.section_separators.left ~= nil and section[1].options.section_separators.left ~= '') then status[component_no] = - string.format('%s%%S{%s}', status[component_no], section[1].options.section_separators.left) + string.format('%s%%Z{%s}', status[component_no], section[1].options.section_separators.left) end end end @@ -89,7 +89,7 @@ function M.draw_section(section, section_name, is_focused) and (section[1].options.section_separators.right ~= nil and section[1].options.section_separators.right ~= '') then left_separator_string = string.format( - '%%s{%s}', + '%%z{%s}', section[first_component_no].options.ls_separator or section[1].options.section_separators.right ) end @@ -104,7 +104,7 @@ function M.draw_section(section, section_name, is_focused) local needs_hl - local find_start_trans_sep_start, find_start_trans_sep_end = status_str:find('^%%s{.-}') + local find_start_trans_sep_start, find_start_trans_sep_end = status_str:find('^%%z{.-}') if find_start_trans_sep_start then -- the section doesn't need to be prepended with default hl when sections -- first component has transitional sep From 442d2ab757b4de6bc492186ff76ffed9746d772b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 4 May 2023 22:59:39 +0800 Subject: [PATCH 07/18] feat!: switch to Nerd Fonts v3.0.0 for diagnostic symbols (#1033) Ref https://github.com/ryanoasis/nerd-fonts/issues/1059#issuecomment-1404891287 --- lua/lualine/components/diagnostics/config.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/lualine/components/diagnostics/config.lua b/lua/lualine/components/diagnostics/config.lua index bfe3544de..ce48544cc 100644 --- a/lua/lualine/components/diagnostics/config.lua +++ b/lua/lualine/components/diagnostics/config.lua @@ -5,10 +5,10 @@ local M = {} -- default symbols for diagnostics component M.symbols = { icons = { - error = ' ', -- xf659 - warn = ' ', -- xf529 - info = ' ', -- xf7fc - hint = ' ', -- xf835 + error = '󰅚 ', -- x000f015a + warn = '󰀪 ', -- x000f002a + info = '󰋽 ', -- x000f02fd + hint = '󰌶 ', -- x000f0336 }, no_icons = { error = 'E:', warn = 'W:', info = 'I:', hint = 'H:' }, } From 8912bea65de93a56b1f70cdb7c3c26f9cce30394 Mon Sep 17 00:00:00 2001 From: Eugene Oliveros Date: Thu, 4 May 2023 23:08:04 +0800 Subject: [PATCH 08/18] fix: replace deprecated nerdfont icons (#1035) Co-authored-by: Shadman <13149513+shadmansaleh@users.noreply.github.com> --- examples/evil_lualine.lua | 2 +- tests/spec/lualine_spec.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/evil_lualine.lua b/examples/evil_lualine.lua index 251552028..138692036 100644 --- a/examples/evil_lualine.lua +++ b/examples/evil_lualine.lua @@ -200,7 +200,7 @@ ins_right { ins_right { 'diff', -- Is it me or the symbol for modified us really weird - symbols = { added = ' ', modified = '柳 ', removed = ' ' }, + symbols = { added = ' ', modified = '󰝤 ', removed = ' ' }, diff_color = { added = { fg = colors.green }, modified = { fg = colors.orange }, diff --git a/tests/spec/lualine_spec.lua b/tests/spec/lualine_spec.lua index 47854ead8..eb46a3ce1 100644 --- a/tests/spec/lualine_spec.lua +++ b/tests/spec/lualine_spec.lua @@ -732,7 +732,7 @@ describe('Lualine', function() 3: lualine_a_buffers_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" } 4: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" } } - |{1:  a.txt } + |{1: 󰈙 a.txt } {2:} {3: ... } {4: }| From e41d48ebcc1e39e7e57854d29544ea85ac784a9b Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Thu, 4 May 2023 21:14:31 +0600 Subject: [PATCH 09/18] chore: use nvim-tree/nvim-web-devicons in ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9914c3716..be219e263 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,7 @@ jobs: run: | mkdir -p ./tmp_home/nvim/pack/vendor/start git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ./tmp_home/nvim/pack/vendor/start/plenary.nvim - git clone --depth 1 https://github.com/kyazdani42/nvim-web-devicons ./tmp_home/nvim/pack/vendor/start/nvim-web-devicons + git clone --depth 1 https://github.com/nvim-tree/nvim-web-devicons ./tmp_home/nvim/pack/vendor/start/nvim-web-devicons ln -s $(pwd) ./tmp_home/nvim/pack/vendor/start - name: Setup neovim ${{matrix.nvim_version}} uses: rhysd/action-setup-vim@v1 From 05d78e9fd0cdfb4545974a5aa14b1be95a86e9c9 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Thu, 4 May 2023 21:17:02 +0600 Subject: [PATCH 10/18] fixup: fix tests --- tests/spec/lualine_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/spec/lualine_spec.lua b/tests/spec/lualine_spec.lua index eb46a3ce1..47854ead8 100644 --- a/tests/spec/lualine_spec.lua +++ b/tests/spec/lualine_spec.lua @@ -732,7 +732,7 @@ describe('Lualine', function() 3: lualine_a_buffers_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" } 4: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" } } - |{1: 󰈙 a.txt } + |{1:  a.txt } {2:} {3: ... } {4: }| From afece9bbf960f908cbaffebaa4b5a0506e9dc8ed Mon Sep 17 00:00:00 2001 From: Ofir Gal Date: Thu, 3 Aug 2023 10:01:10 +0300 Subject: [PATCH 11/18] Added hlgroup for `diff` of lualine (#846) * added higlightgroups for lualine to allow colorscheme to set colors for lualine * chore: update docs for default diff color change --------- Co-authored-by: Shadman <13149513+shadmansaleh@users.noreply.github.com> --- README.md | 6 +++--- lua/lualine/components/diff/init.lua | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6d988d5ac..39f792d30 100644 --- a/README.md +++ b/README.md @@ -582,9 +582,9 @@ sections = { colored = true, -- Displays a colored diff status if set to true diff_color = { -- Same color values as the general color option can be used here. - added = 'DiffAdd', -- Changes the diff's added color - modified = 'DiffChange', -- Changes the diff's modified color - removed = 'DiffDelete', -- Changes the diff's removed color you + added = 'LuaLineDiffAdd', -- Changes the diff's added color + modified = 'LuaLineDiffChange', -- Changes the diff's modified color + removed = 'LuaLineDiffDelete', -- Changes the diff's removed color you }, symbols = {added = '+', modified = '~', removed = '-'}, -- Changes the symbols used by the diff. source = nil, -- A function that works as a data source for diff. diff --git a/lua/lualine/components/diff/init.lua b/lua/lualine/components/diff/init.lua index 976bd5474..9201b2bba 100644 --- a/lua/lualine/components/diff/init.lua +++ b/lua/lualine/components/diff/init.lua @@ -19,21 +19,21 @@ local function apply_default_colors(opts) added = { fg = modules.utils.extract_color_from_hllist( 'fg', - { 'GitSignsAdd', 'GitGutterAdd', 'DiffAdded', 'DiffAdd' }, + { 'LuaLineDiffAdd', 'GitSignsAdd', 'GitGutterAdd', 'DiffAdded', 'DiffAdd' }, '#90ee90' ), }, modified = { fg = modules.utils.extract_color_from_hllist( 'fg', - { 'GitSignsChange', 'GitGutterChange', 'DiffChanged', 'DiffChange' }, + { 'LuaLineDiffChange', 'GitSignsChange', 'GitGutterChange', 'DiffChanged', 'DiffChange' }, '#f0e130' ), }, removed = { fg = modules.utils.extract_color_from_hllist( 'fg', - { 'GitSignsDelete', 'GitGutterDelete', 'DiffRemoved', 'DiffDelete' }, + { 'LuaLineDiffDelete', 'GitSignsDelete', 'GitGutterDelete', 'DiffRemoved', 'DiffDelete' }, '#ff0038' ), }, From 146f40d83c6d1f6e1b84d503b92ea0055dfa7f3e Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Thu, 3 Aug 2023 07:01:45 +0000 Subject: [PATCH 12/18] chore: autogen (vimdocs+formating) --- doc/lualine.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/lualine.txt b/doc/lualine.txt index 495275496..c2077bd67 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -606,9 +606,9 @@ Component specific options These are options that are available on colored = true, -- Displays a colored diff status if set to true diff_color = { -- Same color values as the general color option can be used here. - added = 'DiffAdd', -- Changes the diff's added color - modified = 'DiffChange', -- Changes the diff's modified color - removed = 'DiffDelete', -- Changes the diff's removed color you + added = 'LuaLineDiffAdd', -- Changes the diff's added color + modified = 'LuaLineDiffChange', -- Changes the diff's modified color + removed = 'LuaLineDiffDelete', -- Changes the diff's removed color you }, symbols = {added = '+', modified = '~', removed = '-'}, -- Changes the symbols used by the diff. source = nil, -- A function that works as a data source for diff. From 45e27ca739c7be6c49e5496d14fcf45a303c3a63 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Thu, 3 Aug 2023 13:02:44 +0600 Subject: [PATCH 13/18] chore: fix tests failing due to icon change --- tests/spec/lualine_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/spec/lualine_spec.lua b/tests/spec/lualine_spec.lua index 47854ead8..eb46a3ce1 100644 --- a/tests/spec/lualine_spec.lua +++ b/tests/spec/lualine_spec.lua @@ -732,7 +732,7 @@ describe('Lualine', function() 3: lualine_a_buffers_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" } 4: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" } } - |{1:  a.txt } + |{1: 󰈙 a.txt } {2:} {3: ... } {4: }| From 5d85dc785869e63191db6e5c995d59002105b2d0 Mon Sep 17 00:00:00 2001 From: Anthony Ruhier Date: Tue, 17 Oct 2023 11:37:24 +0200 Subject: [PATCH 14/18] Add options to the Tabs module to align it with the Buffers module (#920) * Add a path option for tabs Add get_props to align the module on Buffers. * Add option to set the tab max size Shorten dynamically the tab name to minimize its length when needed. * Show modified status --- README.md | 11 ++++ lua/lualine/components/tabs/init.lua | 6 ++ lua/lualine/components/tabs/tab.lua | 92 +++++++++++++++++++++++----- 3 files changed, 92 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 39f792d30..8fb021fa0 100644 --- a/README.md +++ b/README.md @@ -679,6 +679,7 @@ sections = { lualine_a = { { 'tabs', + tab_max_length = 40, -- Maximum width of each tab. The content will be shorten dynamically (example: apple/orange -> a/orange) max_length = vim.o.columns / 3, -- Maximum width of tabs component. -- Note: -- It can also be a function that returns @@ -687,6 +688,11 @@ sections = { -- 1: Shows tab_name -- 2: Shows tab_nr + tab_name + path = 0, -- 0: just shows the filename + -- 1: shows the relative path and shorten $HOME to ~ + -- 2: shows the full path + -- 3: shows the full path and shorten $HOME to ~ + -- Automatically updates active tab color to match color of other components (will be overidden if buffers_color is set) use_mode_colors = false, @@ -696,6 +702,11 @@ sections = { inactive = 'lualine_{section}_inactive', -- Color for inactive tab. }, + show_modified_status = true, -- Shows a symbol next to the tab name if the file has been modified. + symbols = { + modified = '[+]', -- Text to show when the file is modified. + }, + fmt = function(name, context) -- Show + if buffer is modified in tab local buflist = vim.fn.tabpagebuflist(context.tabnr) diff --git a/lua/lualine/components/tabs/init.lua b/lua/lualine/components/tabs/init.lua index b176b450a..5d1966e6d 100644 --- a/lua/lualine/components/tabs/init.lua +++ b/lua/lualine/components/tabs/init.lua @@ -7,12 +7,18 @@ local highlight = require('lualine.highlight') local default_options = { max_length = 0, + tab_max_length = 40, mode = 0, use_mode_colors = false, + path = 0, tabs_color = { active = nil, inactive = nil, }, + show_modified_status = true, + symbols = { + modified = '[+]', + }, } -- This function is duplicated in buffers diff --git a/lua/lualine/components/tabs/tab.lua b/lua/lualine/components/tabs/tab.lua index 8ccdc90c0..170095a6e 100644 --- a/lua/lualine/components/tabs/tab.lua +++ b/lua/lualine/components/tabs/tab.lua @@ -13,6 +13,27 @@ function Tab:init(opts) self.tabId = opts.tabId self.options = opts.options self.highlights = opts.highlights + self.modified_icon = '' + self:get_props() +end + +function Tab:get_props() + local buflist = vim.fn.tabpagebuflist(self.tabnr) + local winnr = vim.fn.tabpagewinnr(self.tabnr) + local bufnr = buflist[winnr] + self.file = modules.utils.stl_escape(vim.api.nvim_buf_get_name(bufnr)) + self.filetype = vim.api.nvim_buf_get_option(bufnr, 'filetype') + self.buftype = vim.api.nvim_buf_get_option(bufnr, 'buftype') + + if self.options.show_modified_status then + for _, b in ipairs(buflist) do + if vim.api.nvim_buf_get_option(b, 'modified') then + self.modified_icon = self.options.symbols.modified or '' + break + end + end + end + end ---returns name for tab. Tabs name is the name of buffer in last active window @@ -26,30 +47,61 @@ function Tab:label() if custom_tabname and custom_tabname ~= '' then return modules.utils.stl_escape(custom_tabname) end - local buflist = vim.fn.tabpagebuflist(self.tabnr) - local winnr = vim.fn.tabpagewinnr(self.tabnr) - local bufnr = buflist[winnr] - local file = modules.utils.stl_escape(vim.api.nvim_buf_get_name(bufnr)) - local buftype = vim.fn.getbufvar(bufnr, '&buftype') - if vim.api.nvim_buf_get_option(bufnr, 'filetype') == 'fugitive' then - return 'fugitive: ' .. vim.fn.fnamemodify(file, ':h:h:t') - elseif buftype == 'help' then - return 'help:' .. vim.fn.fnamemodify(file, ':t:r') - elseif buftype == 'terminal' then - local match = string.match(vim.split(file, ' ')[1], 'term:.*:(%a+)') + if self.filetype == 'fugitive' then + return 'fugitive: ' .. vim.fn.fnamemodify(self.file, ':h:h:t') + elseif self.buftype == 'help' then + return 'help:' .. vim.fn.fnamemodify(self.file, ':t:r') + elseif self.buftype == 'terminal' then + local match = string.match(vim.split(self.file, ' ')[1], 'term:.*:(%a+)') return match ~= nil and match or vim.fn.fnamemodify(vim.env.SHELL, ':t') - elseif vim.fn.isdirectory(file) == 1 then - return vim.fn.fnamemodify(file, ':p:.') - elseif file == '' then + elseif self.file == '' then return '[No Name]' end - return vim.fn.fnamemodify(file, ':t') + if self.options.path == 1 then + return vim.fn.fnamemodify(self.file, ':~:.') + elseif self.options.path == 2 then + return vim.fn.fnamemodify(self.file, ':p') + elseif self.options.path == 3 then + return vim.fn.fnamemodify(self.file, ':p:~') + else + return vim.fn.fnamemodify(self.file, ':t') + end +end + +---shortens path by turning apple/orange -> a/orange +---@param path string +---@param sep string path separator +---@param max_len integer maximum length of the full filename string +---@return string +local function shorten_path(path, sep, max_len) + local len = #path + if len <= max_len then + return path + end + + local segments = vim.split(path, sep) + for idx = 1, #segments - 1 do + if len <= max_len then + break + end + + local segment = segments[idx] + local shortened = segment:sub(1, vim.startswith(segment, '.') and 2 or 1) + segments[idx] = shortened + len = len - (#segment - #shortened) + end + + return table.concat(segments, sep) end ---returns rendered tab ---@return string function Tab:render() local name = self:label() + if self.options.tab_max_length ~= 0 then + local path_separator = package.config:sub(1, 1) + name = shorten_path(name, path_separator, self.options.tab_max_length) + end if self.options.fmt then name = self.options.fmt(name or '', self) end @@ -59,12 +111,18 @@ function Tab:render() -- different formats for different modes if self.options.mode == 0 then name = tostring(self.tabnr) + if self.modified_icon ~= '' then + name = string.format('%s%s', name, self.modified_icon) + end elseif self.options.mode == 1 then - name = name + if self.modified_icon ~= '' then + name = string.format('%s %s', self.modified_icon, name) + end else - name = string.format('%s %s', tostring(self.tabnr), name) + name = string.format('%s%s %s', tostring(self.tabnr), self.modified_icon, name) end end + name = Tab.apply_padding(name, self.options.padding) self.len = vim.fn.strchars(name) From e7efd7dd3a1cde676fbbc4ad4f20c64a9ee3077a Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Tue, 17 Oct 2023 09:37:53 +0000 Subject: [PATCH 15/18] chore: autogen (vimdocs+formating) --- doc/lualine.txt | 11 +++++++++++ lua/lualine/components/tabs/tab.lua | 1 - 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/lualine.txt b/doc/lualine.txt index c2077bd67..6e8a0e2ab 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -708,6 +708,7 @@ Component specific options These are options that are available on lualine_a = { { 'tabs', + tab_max_length = 40, -- Maximum width of each tab. The content will be shorten dynamically (example: apple/orange -> a/orange) max_length = vim.o.columns / 3, -- Maximum width of tabs component. -- Note: -- It can also be a function that returns @@ -716,6 +717,11 @@ Component specific options These are options that are available on -- 1: Shows tab_name -- 2: Shows tab_nr + tab_name + path = 0, -- 0: just shows the filename + -- 1: shows the relative path and shorten $HOME to ~ + -- 2: shows the full path + -- 3: shows the full path and shorten $HOME to ~ + -- Automatically updates active tab color to match color of other components (will be overidden if buffers_color is set) use_mode_colors = false, @@ -725,6 +731,11 @@ Component specific options These are options that are available on inactive = 'lualine_{section}_inactive', -- Color for inactive tab. }, + show_modified_status = true, -- Shows a symbol next to the tab name if the file has been modified. + symbols = { + modified = '[+]', -- Text to show when the file is modified. + }, + fmt = function(name, context) -- Show + if buffer is modified in tab local buflist = vim.fn.tabpagebuflist(context.tabnr) diff --git a/lua/lualine/components/tabs/tab.lua b/lua/lualine/components/tabs/tab.lua index 170095a6e..56c4788a0 100644 --- a/lua/lualine/components/tabs/tab.lua +++ b/lua/lualine/components/tabs/tab.lua @@ -33,7 +33,6 @@ function Tab:get_props() end end end - end ---returns name for tab. Tabs name is the name of buffer in last active window From 388a3964119cf805220ac1f995aacbd0d4ce08d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9A=AE=E6=99=A8?= Date: Tue, 17 Oct 2023 17:51:54 +0800 Subject: [PATCH 16/18] Added extension for mason (#1113) * feat: added extension for mason * feat: update readme * feat: capitalize the first letter * feat: delete icon --------- Co-authored-by: Shadman <13149513+shadmansaleh@users.noreply.github.com> --- README.md | 1 + lua/lualine/extensions/mason.lua | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 lua/lualine/extensions/mason.lua diff --git a/README.md b/README.md index 8fb021fa0..577f18018 100644 --- a/README.md +++ b/README.md @@ -912,6 +912,7 @@ extensions = {'quickfix'} - symbols-outline - toggleterm - trouble +- mason #### Custom extensions diff --git a/lua/lualine/extensions/mason.lua b/lua/lualine/extensions/mason.lua new file mode 100644 index 000000000..16ed56b40 --- /dev/null +++ b/lua/lualine/extensions/mason.lua @@ -0,0 +1,25 @@ +-- lualine extension for mason.nvim + +local ok, mason_registry = pcall(require, 'mason-registry') +if not ok then + return '' +end + +local M = {} + +M.sections = { + lualine_a = { + function() + return 'Mason' + end, + }, + lualine_b = { + function() + return 'Installed: ' .. #mason_registry.get_installed_packages() .. '/' .. #mason_registry.get_all_package_specs() + end, + }, +} + +M.filetypes = { 'mason' } + +return M From 1a3f6bba410aff5a51bf8c84287aaa3a8ba30d0d Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Tue, 17 Oct 2023 09:52:19 +0000 Subject: [PATCH 17/18] chore: autogen (vimdocs+formating) --- doc/lualine.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/lualine.txt b/doc/lualine.txt index 6e8a0e2ab..9946c98f2 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -966,6 +966,7 @@ extensions with: - symbols-outline - toggleterm - trouble +- mason *lualine-Custom-extensions* From c55af3b39cc50109aa75d445e38f2089b023e5df Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Wed, 18 Oct 2023 06:49:27 +0200 Subject: [PATCH 18/18] enhance: Update git_branch.lua to use GIT_DIR environment variable (#1114) Fix typo Remove whitespace Try GIT_DIR first --- lua/lualine/components/branch/git_branch.lua | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lua/lualine/components/branch/git_branch.lua b/lua/lualine/components/branch/git_branch.lua index c9f36e9a5..48625f558 100644 --- a/lua/lualine/components/branch/git_branch.lua +++ b/lua/lualine/components/branch/git_branch.lua @@ -56,14 +56,27 @@ local function update_branch() branch_cache[vim.api.nvim_get_current_buf()] = current_git_branch end +---updates the current value of current_git_branch and sets up file watch on HEAD file if value changed +local function update_current_git_dir(git_dir) + if current_git_dir ~= git_dir then + current_git_dir = git_dir + update_branch() + end +end + ---returns full path to git directory for dir_path or current directory ---@param dir_path string|nil ----@return string +---@return string|nil function M.find_git_dir(dir_path) + local git_dir = vim.env.GIT_DIR + if git_dir then + update_current_git_dir(git_dir) + return git_dir + end + -- get file dir so we can search from that dir local file_dir = dir_path or vim.fn.expand('%:p:h') local root_dir = file_dir - local git_dir -- Search upward for .git file or folder while root_dir do if git_dir_cache[root_dir] then @@ -101,9 +114,8 @@ function M.find_git_dir(dir_path) end git_dir_cache[file_dir] = git_dir - if dir_path == nil and current_git_dir ~= git_dir then - current_git_dir = git_dir - update_branch() + if dir_path == nil then + update_current_git_dir(git_dir) end return git_dir end