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