fix: oil-bug in lualine, and partial rewrite

This commit is contained in:
Abdulrahman Sheikho 2026-04-21 07:05:17 +03:00
parent fa3c34d752
commit d73982f20d
1 changed files with 34 additions and 37 deletions

View File

@ -1,5 +1,6 @@
local col_mark_1 = 120 local col_mark_80 = 80
local col_mark_2 = 180 local col_mark_120 = 120
local col_mark_180 = 180
---@class Section ---@class Section
local S = {} local S = {}
@ -50,7 +51,7 @@ end
---@param onColumn integer? The column number where the section will be hidden when the buffer's width is less than ---@param onColumn integer? The column number where the section will be hidden when the buffer's width is less than
---@return Section ---@return Section
function S:set_autohide_fmt(onColumn) function S:set_autohide_fmt(onColumn)
onColumn = onColumn or col_mark_1 onColumn = onColumn or col_mark_120
if self.fmt ~= nil then if self.fmt ~= nil then
vim.defer_fn(function() vim.defer_fn(function()
@ -69,14 +70,12 @@ function S:set_autohide_fmt(onColumn)
end end
local devKit_icons = Glyphs.dev_kit local devKit_icons = Glyphs.dev_kit
local fs_icons = Glyphs.file_status
local diag_icons = {} local diag_icons = {}
for key, val in pairs(Glyphs.diagnostics) do for key, val in pairs(Glyphs.diagnostics) do
diag_icons[key] = val .. ' ' diag_icons[key] = val .. ' '
end end
local fs_icons = Glyphs.file_status
return { return {
'nvim-lualine/lualine.nvim', 'nvim-lualine/lualine.nvim',
dependencies = { dependencies = {
@ -95,7 +94,7 @@ return {
}, },
ignore_focus = {}, ignore_focus = {},
always_divide_middle = true, always_divide_middle = true,
always_show_tabline = true, always_show_tabline = false,
globalstatus = false, globalstatus = false,
refresh = { refresh = {
statusline = 1000, statusline = 1000,
@ -121,7 +120,7 @@ return {
S:new({ 'mode' }) S:new({ 'mode' })
:set_fmt( -- trim to initials using kebab-case :set_fmt( -- trim to initials using kebab-case
function(str) function(str)
if vim.api.nvim_win_get_width(0) > col_mark_1 then if vim.api.nvim_win_get_width(0) > col_mark_120 then
return str return str
end end
if str:match '-' then if str:match '-' then
@ -136,10 +135,10 @@ return {
}, },
lualine_b = { lualine_b = {
S:new({ 'branch' }) S:new({ 'branch', icon = '' })
:set_fmt( -- trim to first char :set_fmt( -- trim to first char
function(str) function(str)
if vim.api.nvim_win_get_width(0) > col_mark_1 then if vim.api.nvim_win_get_width(0) > col_mark_120 then
return str return str
end end
-- just the first char -- just the first char
@ -153,39 +152,37 @@ return {
lualine_c = { lualine_c = {
{ {
-- TODO: this still doesn't work with buffers like oil.nvim
function() function()
-- do some evaluation -- do some evaluation
local buff_width = vim.api.nvim_win_get_width(0) local buff_width = vim.api.nvim_win_get_width(0)
local m_flag = vim.api.nvim_eval_statusline('%m', {}).str local proto_prefix = vim.fn.expand('%'):match '(.-://).+' or ''
local r_flag = vim.api.nvim_eval_statusline('%r', {}).str
local w_flag = vim.api.nvim_eval_statusline('%w', {}).str
local filename_parts = { local filename_parts = {}
-- handle special case before setting default
if proto_prefix == 'oil://' then
filename_parts[1] = (buff_width > col_mark_80 and '%F')
or proto_prefix .. '.../' .. vim.fs.basename(vim.fn.fnamemodify(vim.fn.getcwd(), '%:p')) .. '/'
elseif proto_prefix == 'term://' then
filename_parts[1] = proto_prefix .. '%t'
else
-- responsive file-path-name -- responsive file-path-name
(buff_width > col_mark_2 and '%F') -- full path filename_parts[1] = (buff_width > col_mark_180 and '%F') -- full path
or (buff_width > col_mark_1 and '%f') -- relative path or (buff_width > col_mark_120 and '%f') -- relative path
or '%t', -- file name only or proto_prefix .. '%t' -- file name only
-- modifiable indicator
(m_flag == '[+]' and fs_icons.modified)
or (m_flag == '[-]' and fs_icons.unmodifiable)
or m_flag,
-- read-only indicator
(r_flag == '[RO]' and fs_icons.readOnly) or r_flag,
-- preview indicator
(w_flag == '[Preview]' and fs_icons.preview) or w_flag,
}
-- immediately concating table puts more whitespace for empty fields
-- so I'm manually concating
local str = '%<'
for _, v in ipairs(filename_parts) do
if v ~= '' then
str = str .. v .. ' '
end
end end
return str -- modifiable indicator
filename_parts[#filename_parts + 1] = vim.bo.modified and fs_icons.modified
or not vim.bo.modifiable and fs_icons.unmodifiable
or nil
-- read-only indicator
filename_parts[#filename_parts + 1] = (vim.bo.readonly and fs_icons.readOnly) or nil
-- preview indicator
filename_parts[#filename_parts + 1] = (vim.wo.previewwindow and fs_icons.preview) or nil
return '%<' .. table.concat(filename_parts, ' ')
end, end,
}, },
}, },
@ -247,7 +244,7 @@ return {
S:new({ S:new({
-- A location section, row:col -- A location section, row:col
function() function()
if vim.api.nvim_win_get_width(0) > col_mark_1 then if vim.api.nvim_win_get_width(0) > col_mark_120 then
-- padding with two char -- padding with two char
return '%2l:%-2v' return '%2l:%-2v'
end end