nvim: statusline: Enable winbar

Use it to show full path for file. This frees up space in status line
when git branch names are long.
This commit is contained in:
Sanchayan Maity 2022-06-01 20:37:05 +05:30
parent 1fdb057edf
commit add2ceb869

View file

@ -1,6 +1,5 @@
local fn = vim.fn
local api = vim.api
local cmd = vim.cmd
local gstatus = { ahead = 0, behind = 0 }
local update_gstatus = function()
@ -70,6 +69,7 @@ highlight("DiagnosticsH", colors.orange , colors.bg)
highlight("Location" , colors.yellow , colors.bg)
highlight("Progress" , colors.magenta, colors.bg)
highlight("WinbarFile" , colors.magenta, colors.bg)
M.trunc_width = setmetatable({
git_status = 80,
@ -146,7 +146,7 @@ M.get_git_status = function(self)
or ""
end
M.get_filename = function(self)
M.get_filename = function()
local filetype = vim.bo.filetype
local special_ft = { 'diff', 'fugitive', 'git', 'qf' }
for _, v in pairs(special_ft) do
@ -222,8 +222,6 @@ M.set_inactive = function(self)
-- Putting this in a function like the others seems to not work. And takes
-- the window number of the active window. Same for filename.
" %{winnr()}",
"%#Filename#",
' %t%m%r',
self:get_git_branch(),
"%=",
self:get_fileformat(),
@ -238,26 +236,46 @@ _G.Statusline = setmetatable(M, {
end,
})
api.nvim_create_augroup("Statusline", {clear = true})
local status_id = api.nvim_create_augroup("Statusline", {clear = true})
local hide_status_id = api.nvim_create_augroup("HideStatusline", {clear = true})
api.nvim_create_autocmd({"WinEnter", "BufEnter"}, {
group = "Statusline",
group = status_id,
pattern = "*",
command = "setlocal statusline=%!v:lua.Statusline('active')"
})
api.nvim_create_autocmd({"WinLeave" , "BufLeave"}, {
group = "Statusline",
group = status_id,
pattern = "*",
command = "setlocal statusline=%!v:lua.Statusline('inactive')"
})
api.nvim_create_autocmd({"BufWinEnter", "BufFilePost"}, {
group = status_id,
callback = function()
local winbar_filetype_exclude = {
"diff",
"fugitive",
"git",
"help",
"packer",
"qf"
}
api.nvim_create_augroup("HideStatusline", {clear = true})
if vim.tbl_contains(winbar_filetype_exclude, vim.bo.filetype) then
vim.opt_local.winbar = nil
return
end
vim.opt_local.winbar = string.format(" %s%s", "%#WinbarFile#", '%f%m%r')
end,
})
api.nvim_create_autocmd({"TermOpen", "TermEnter"}, {
group = "HideStatusline",
group = hide_status_id,
pattern = "*",
command = "set laststatus=0 noshowmode noruler"
})
api.nvim_create_autocmd({"TermLeave"}, {
group = "HideStatusline",
group = hide_status_id,
pattern = "*",
command = "set laststatus=2 showmode ruler"
})