neovim configuration using rocks.nvim plugin manager
at main 1.9 kB view raw
1local function filename() 2 local path = vim.fn.expand("%:p:h")--[[@as string]] 3 path = path:gsub("oil://", "") 4 path = vim.fs.joinpath(path, "") -- 5 :gsub("^" .. vim.pesc(vim.fs.joinpath(vim.fn.getcwd(0, 0), "")), "") 6 7 local name = vim.fn.expand("%:p:t")--[[@as string]] 8 if vim.bo.filetype == "oil" then 9 name = path == "" and "." or path 10 path = "oil://" 11 elseif name == "" then 12 name = "[No Name]" 13 end 14 return path .. name 15end 16 17local function rest() 18 local env_file = vim.b._rest_nvim_env_file 19 if not env_file then 20 return "" 21 end 22 return "(" .. env_file .. ") " 23end 24 25---Show attached LSP clients in `[name1, name2]` format. 26---Long server names will be modified. For example, `lua-language-server` will be shorten to `lua-ls` 27---Returns an empty string if there aren't any attached LSP clients. 28---@return string 29local function lsp_status() 30 local attached_clients = vim.lsp.get_clients({ bufnr = 0 }) 31 if #attached_clients == 0 then 32 return "" 33 end 34 local it = vim.iter(attached_clients) 35 it:map(function (client) 36 local name = client.name:gsub("language.server", "ls") 37 return name 38 end) 39 local names = it:totable() 40 return "[" .. table.concat(names, ", ") .. "]" 41end 42 43local function tab_size() 44 local tabstop = vim.bo.tabstop 45 -- local sts = vim.bo.softtabstop 46 -- if sts < 0 then 47 -- tabsize = vim.bo.shiftwidth 48 -- elseif sts == 0 then 49 -- else 50 -- end 51 -- if vim.bo.expandtab then 52 -- end 53 return "[ts:" .. tabstop .. "]" 54end 55 56function _G.statusline() 57 return table.concat({ 58 filename(), 59 "%h%w%m%r", 60 " [%{&ff}] ", 61 -- "(on main)", 62 "%=", 63 rest(), 64 "%y", 65 tab_size(), 66 lsp_status(), 67 " ", 68 "%-10(%l,%c%V%)", 69 "%P", 70 }) 71end 72 73vim.o.statusline = "%{%v:lua._G.statusline()%}"