From d3600399692e734854cf8d51a6480f9b8bd98461 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Fri, 28 May 2021 15:49:44 -0400 Subject: [PATCH] fix(filename): include window_width to space estimation & expose shorting_target option setting shorting target to 0 disables path shorting closes #8 Co-authored-by: NullVoxPopuli --- README.md | 4 +++- doc/lualine.txt | 2 ++ lua/lualine/components/filename.lua | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f1a7769..92569ee 100644 --- a/README.md +++ b/README.md @@ -320,7 +320,9 @@ sections = { { 'filename', file_status = true, -- displays file status (readonly status, modified status) - path = 0 -- 0 = just filename, 1 = relative path, 2 = absolute path + path = 0, -- 0 = just filename, 1 = relative path, 2 = absolute path + shorting_target = 40 -- Shortens path to leave 40 space in the window + -- for other components. Terrible name any suggestions? } } } diff --git a/doc/lualine.txt b/doc/lualine.txt index 524dacf..3f49557 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -252,6 +252,8 @@ Component specific local options~ 'filename', file_status = true, -- displays file status (readonly status, modified status) path = 0 -- 0 = just filename, 1 = relative path, 2 = absolute path + shorting_target = 40 -- Shortens path to leave 40 space 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 d43c60b..ad74a78 100644 --- a/lua/lualine/components/filename.lua +++ b/lua/lualine/components/filename.lua @@ -24,6 +24,9 @@ FileName.new = function(self, options, child) new_instance.options.file_status = true end if new_instance.options.path == nil then new_instance.options.path = 0 end + if new_instance.options.shorting_target == nil then + new_instance.options.shorting_target = 40 + end return new_instance end @@ -43,12 +46,15 @@ FileName.update_status = function(self) if data == '' then data = '[No Name]' end - local windwidth = vim.fn.winwidth(0) - local estimated_space_available = 40 - local path_separator = package.config:sub(1, 1) - for _ = 0, count(data, path_separator) do - if windwidth <= 84 or #data > estimated_space_available then - data = shorten_path(data, path_separator) + if self.options.shorting_target ~= 0 then + local windwidth = vim.fn.winwidth(0) + local estimated_space_available = windwidth - self.options.shorting_target + + local path_separator = package.config:sub(1, 1) + for _ = 0, count(data, path_separator) do + if windwidth <= 84 or #data > estimated_space_available then + data = shorten_path(data, path_separator) + end end end