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:
parent
1fdb057edf
commit
add2ceb869
1 changed files with 28 additions and 10 deletions
|
@ -1,6 +1,5 @@
|
||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local cmd = vim.cmd
|
|
||||||
|
|
||||||
local gstatus = { ahead = 0, behind = 0 }
|
local gstatus = { ahead = 0, behind = 0 }
|
||||||
local update_gstatus = function()
|
local update_gstatus = function()
|
||||||
|
@ -70,6 +69,7 @@ highlight("DiagnosticsH", colors.orange , colors.bg)
|
||||||
|
|
||||||
highlight("Location" , colors.yellow , colors.bg)
|
highlight("Location" , colors.yellow , colors.bg)
|
||||||
highlight("Progress" , colors.magenta, colors.bg)
|
highlight("Progress" , colors.magenta, colors.bg)
|
||||||
|
highlight("WinbarFile" , colors.magenta, colors.bg)
|
||||||
|
|
||||||
M.trunc_width = setmetatable({
|
M.trunc_width = setmetatable({
|
||||||
git_status = 80,
|
git_status = 80,
|
||||||
|
@ -146,7 +146,7 @@ M.get_git_status = function(self)
|
||||||
or ""
|
or ""
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_filename = function(self)
|
M.get_filename = function()
|
||||||
local filetype = vim.bo.filetype
|
local filetype = vim.bo.filetype
|
||||||
local special_ft = { 'diff', 'fugitive', 'git', 'qf' }
|
local special_ft = { 'diff', 'fugitive', 'git', 'qf' }
|
||||||
for _, v in pairs(special_ft) do
|
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
|
-- Putting this in a function like the others seems to not work. And takes
|
||||||
-- the window number of the active window. Same for filename.
|
-- the window number of the active window. Same for filename.
|
||||||
" %{winnr()}",
|
" %{winnr()}",
|
||||||
"%#Filename#",
|
|
||||||
' %t%m%r',
|
|
||||||
self:get_git_branch(),
|
self:get_git_branch(),
|
||||||
"%=",
|
"%=",
|
||||||
self:get_fileformat(),
|
self:get_fileformat(),
|
||||||
|
@ -238,26 +236,46 @@ _G.Statusline = setmetatable(M, {
|
||||||
end,
|
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"}, {
|
api.nvim_create_autocmd({"WinEnter", "BufEnter"}, {
|
||||||
group = "Statusline",
|
group = status_id,
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
command = "setlocal statusline=%!v:lua.Statusline('active')"
|
command = "setlocal statusline=%!v:lua.Statusline('active')"
|
||||||
})
|
})
|
||||||
api.nvim_create_autocmd({"WinLeave" , "BufLeave"}, {
|
api.nvim_create_autocmd({"WinLeave" , "BufLeave"}, {
|
||||||
group = "Statusline",
|
group = status_id,
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
command = "setlocal statusline=%!v:lua.Statusline('inactive')"
|
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"}, {
|
api.nvim_create_autocmd({"TermOpen", "TermEnter"}, {
|
||||||
group = "HideStatusline",
|
group = hide_status_id,
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
command = "set laststatus=0 noshowmode noruler"
|
command = "set laststatus=0 noshowmode noruler"
|
||||||
})
|
})
|
||||||
api.nvim_create_autocmd({"TermLeave"}, {
|
api.nvim_create_autocmd({"TermLeave"}, {
|
||||||
group = "HideStatusline",
|
group = hide_status_id,
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
command = "set laststatus=2 showmode ruler"
|
command = "set laststatus=2 showmode ruler"
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue