neovim configuration using rocks.nvim plugin manager
at main 3.1 kB view raw
1local Util = require("utils") 2local util_hl = require("utils.highlights") 3 4local function is_win_current() 5 local winid = vim.api.nvim_get_current_win() 6 local curwin = tonumber(vim.g.actual_curwin) 7 return winid == curwin 8end 9 10local hls = { 11} 12 13local hl_text = util_hl.hl_text 14 15local function file_name() 16 local path = vim.fn.expand("%:p:h")--[[@as string]] 17 path = path:gsub("oil://", "") 18 -- stylua: ignore 19 path = vim.fs.joinpath(path, "") 20 :gsub(vim.pesc(vim.fs.joinpath(Util.root(), "")), "") 21 22 local name = vim.fn.expand("%:p:t")--[[@as string]] 23 if vim.bo.filetype == "oil" then 24 name = path == "" and "." or path 25 path = "oil://" 26 elseif name == "" then 27 name = "[No Name]" 28 end 29 30 local hi = is_win_current() and hls.bold or hls.nc_bold 31 return hl_text(path, hls.nc_base) .. hl_text(name, hi) 32end 33 34local function sg_name() 35 local path = vim.fn.expand("%:p:h") 36 path = path .. "/" 37 local name = vim.fn.expand("%:p:t") 38 local hi = is_win_current() and hls.bold or hls.nc_bold 39 return hl_text(path, hls.nc_base) .. hl_text(name, hi) 40end 41 42local function sg_status() 43 -- TODO: 44 -- on github.com 45 -- on crates.io 46 return "" 47end 48 49function _G.winbar() 50 local modules = {} 51 local buftype = vim.bo.buftype 52 local filetype = vim.bo.filetype 53 local filename = vim.api.nvim_buf_get_name(0) 54 local function center(title) 55 return { 56 vi_mode(), 57 "%=" .. title .. "%=", 58 vi_mode_placer, 59 } 60 end 61 if buftype == "" or filename:match('^suda://') then 62 modules = { 63 vi_mode(), 64 " ", 65 file_name(), 66 file_modi(), 67 " ", 68 git_status(), 69 "%=", 70 "%<", 71 "%-14.(" .. lsp_status() .. "%)", 72 " ", 73 "%P ", 74 } 75 elseif buftype == "help" then 76 modules = center(help_file()) 77 elseif buftype == "terminal" then 78 modules = { 79 vi_mode(), 80 "%=Terminal%=", 81 -- TODO: add terminal id too 82 vi_mode_placer, 83 } 84 elseif buftype == "nofile" and filetype == "query" and vim.bo.modifiable and not vim.bo.readonly then 85 modules = center("Edit Query") 86 elseif filetype == "qf" then 87 modules = center("Quickfix List") 88 elseif filetype == "checkhealth" then 89 modules = center("checkhealth") 90 elseif filetype == "oil" then 91 modules = { 92 vi_mode(), 93 " ", 94 file_name(), 95 file_modi(), 96 " ", 97 git_status(), 98 "%=", 99 " ", 100 "%P ", 101 } 102 elseif filetype:match("^Neogit.*") then 103 modules = center("Neogit") 104 elseif filetype == "neotest-summary" then 105 modules = center("Test Summary") 106 elseif filetype == "tsplayground" then 107 modules = center("TSPlayground") 108 elseif vim.fn.win_gettype(vim.api.nvim_get_current_win()) == "command" then 109 modules = center("Command Window") 110 elseif filename:match("^sg://") then 111 modules = { 112 vi_mode(), 113 " ", 114 sg_name(), 115 file_modi(), 116 " ", 117 sg_status(), -- TODO: sg_status instead of git_status 118 "%=", 119 "%<", 120 " ", 121 "%P ", 122 } 123 else 124 modules = center(filetype) 125 end 126 return table.concat(vim.tbl_filter(function(i) 127 return i ~= nil 128 end, modules)) 129end