feat(nvim): add filetype to winbar

This commit is contained in:
Price Hiller 2023-09-06 22:52:54 -05:00
parent 4eebd2919e
commit 0030d0616e
Signed by: Price
SSH Key Fingerprint: SHA256:Y4S9ZzYphRn1W1kbJerJFO6GGsfu9O70VaBSxJO7dF8
2 changed files with 72 additions and 10 deletions

View File

@ -6,6 +6,7 @@ return {
"lewis6991/gitsigns.nvim", "lewis6991/gitsigns.nvim",
}, },
opts = function() opts = function()
local core_utils = require("utils.funcs")
local colors = require("kanagawa.colors").setup().palette local colors = require("kanagawa.colors").setup().palette
local seps = { local seps = {
@ -143,24 +144,38 @@ return {
local buftype = vim.api.nvim_get_option_value("buftype", { local buftype = vim.api.nvim_get_option_value("buftype", {
buf = self.bufnr buf = self.bufnr
}) })
local filetype = vim.api.nvim_get_option_value("filetype", {
buf = self.bufnr
})
self.icon, self.icon_color = self.icon, self.icon_color =
require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) require("nvim-web-devicons").get_icon_color(filename, extension, { default = true })
local ft_overrides = { local ft_overrides = {
["rs"] = { icon = "", icon_color = self.icon_color }, ["rust"] = { icon = "", icon_color = self.icon_color },
["sshconfig"] = { icon = "󱂺", icon_color = colors.carpYellow },
["sshdconfig"] = "sshconfig"
} }
local buftype_overrides = { local buftype_overrides = {
["terminal"] = { icon = "", icon_color = colors.roninYellow } ["terminal"] = { icon = "", icon_color = colors.roninYellow }
} }
local ft_override = ft_overrides[extension] local function get_override(name, overrides)
local override = overrides[name]
if type(override) == "string" then
override = get_override(override, overrides)
end
return override
end
local ft_override = get_override(filetype, ft_overrides)
if ft_override ~= nil then if ft_override ~= nil then
self.icon = ft_override.icon self.icon = ft_override.icon
self.icon_color = ft_override.icon_color self.icon_color = ft_override.icon_color
end end
local buftype_override = buftype_overrides[buftype] local buftype_override = get_override(buftype, buftype_overrides)
if buftype_override ~= nil then if buftype_override ~= nil then
self.icon = buftype_override.icon self.icon = buftype_override.icon
self.icon_color = buftype_override.icon_color self.icon_color = buftype_override.icon_color
@ -632,20 +647,55 @@ return {
{ {
provider = seps.full.left, provider = seps.full.left,
hl = function() hl = function()
return { fg = colors.sumiInk5, bg = utils.get_highlight("WinBar").bg } return { fg = colors.crystalBlue, bg = utils.get_highlight("WinBar").bg }
end,
},
{
provider = function ()
local ft = vim.bo.filetype or "[No Filetype]"
return ft .. " "
end,
hl = {
fg = colors.sumiInk0,
bg = colors.crystalBlue,
},
},
{
provider = seps.full.left,
hl = function()
return { fg = colors.sumiInk4, bg = colors.crystalBlue }
end,
},
{
FileIcon,
hl = { bg = colors.sumiInk4 }
},
{
provider = seps.full.right,
hl = function()
return { fg = colors.sumiInk4, bg = utils.get_highlight("WinBar").bg }
end,
},
},
margin(1),
{
{
provider = seps.full.left,
hl = function()
return { fg = colors.sumiInk4, bg = utils.get_highlight("WinBar").bg }
end, end,
}, },
{ {
provider = "%p%% ", provider = "%p%% ",
hl = { hl = {
fg = colors.fujiWhite, fg = colors.fujiWhite,
bg = colors.sumiInk5, bg = colors.sumiInk4,
}, },
}, },
{ {
provider = seps.full.left, provider = seps.full.left,
hl = function() hl = function()
return { fg = colors.carpYellow, bg = colors.sumiInk5 } return { fg = colors.carpYellow, bg = colors.sumiInk4 }
end, end,
}, },
{ {
@ -667,20 +717,20 @@ return {
{ {
provider = seps.full.left, provider = seps.full.left,
hl = function() hl = function()
return { fg = colors.sumiInk5, bg = utils.get_highlight("WinBar").bg } return { fg = colors.sumiInk4, bg = utils.get_highlight("WinBar").bg }
end, end,
}, },
{ {
provider = "%3l:%c ", provider = "%l:%c ",
hl = { hl = {
fg = colors.fujiWhite, fg = colors.fujiWhite,
bg = colors.sumiInk5, bg = colors.sumiInk4,
}, },
}, },
{ {
provider = seps.full.left, provider = seps.full.left,
hl = function() hl = function()
return { fg = colors.crystalBlue, bg = colors.sumiInk5 } return { fg = colors.crystalBlue, bg = colors.sumiInk4 }
end, end,
}, },
{ {

View File

@ -40,4 +40,16 @@ U.get_color = function(group, attr)
return fn.synIDattr(fn.synIDtrans(fn.hlID(group)), attr) return fn.synIDattr(fn.synIDtrans(fn.hlID(group)), attr)
end end
-- https://stackoverflow.com/a/22548737
---Title cases a given string
---@param str string
U.title_case = function(str)
local function inner(first, rest)
return first:upper() .. rest:lower()
end
return string.gsub(str, "(%a)([%w_']*)", inner)
end
return U return U