61 lines
1.4 KiB
Lua
61 lines
1.4 KiB
Lua
local M = {}
|
|
|
|
local navic = require("nvim-navic")
|
|
|
|
local present, gps = pcall(require, "nvim-gps")
|
|
|
|
if not present then
|
|
return
|
|
end
|
|
|
|
gps.setup()
|
|
navic.setup({
|
|
highlight = true,
|
|
})
|
|
|
|
local function is_empty(s)
|
|
return s == nil or s == ""
|
|
end
|
|
|
|
function M.get_filename()
|
|
return "%#WinBarFilename#" .. "%t" .. "%*"
|
|
end
|
|
|
|
function M.get_location()
|
|
local location = navic.get_location()
|
|
local gps_location = gps.get_location()
|
|
|
|
if not is_empty(location) then
|
|
return "%#WinBarContext#" .. " " .. ">" .. " " .. location .. "%*"
|
|
elseif not is_empty(gps_location) then
|
|
return "%#WinBarContext#" .. " " .. ">" .. " " .. gps_location .. "%*"
|
|
else
|
|
return "%#WinBarContext#" .. "%*"
|
|
end
|
|
end
|
|
|
|
function M.get_fileicon()
|
|
local hl_winbar_file_icon = "WinBarFileIcon"
|
|
local file_path = vim.fn.expand("%:~:.:h")
|
|
local filename = vim.fn.expand("%:t")
|
|
local file_type = vim.fn.expand("%:e")
|
|
local file_icon = ""
|
|
local file_icon_color = ""
|
|
|
|
file_path = file_path:gsub("^%.", "")
|
|
file_path = file_path:gsub("^%/", "")
|
|
|
|
if not is_empty(filename) then
|
|
file_icon, file_icon_color =
|
|
require("nvim-web-devicons").get_icon_color(filename, file_type, { default = true })
|
|
vim.api.nvim_set_hl(0, hl_winbar_file_icon, { fg = file_icon_color })
|
|
end
|
|
|
|
return "%#WinBarContext#" .. "%#" .. hl_winbar_file_icon .. "#" .. file_icon .. " " .. "%*"
|
|
end
|
|
|
|
function M.get_winbar()
|
|
return "%#WinBarContext#" .. M.get_fileicon() .. M.get_filename() .. M.get_location() .. "%*"
|
|
end
|
|
|
|
return M
|