From 753cb493af2a66f8bdb71903156f032dc926a93b Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sun, 14 Aug 2022 17:05:51 -0500 Subject: feat(nvim): improve lualine config --- nvim/.config/nvim/lua/tobyvin/plugins.lua | 3 + nvim/.config/nvim/lua/tobyvin/plugins/lualine.lua | 38 ++++++++----- nvim/.config/nvim/lua/tobyvin/utils.lua | 67 ++++++++++------------- 3 files changed, 56 insertions(+), 52 deletions(-) (limited to 'nvim/.config') diff --git a/nvim/.config/nvim/lua/tobyvin/plugins.lua b/nvim/.config/nvim/lua/tobyvin/plugins.lua index 2d01be2..472a18b 100644 --- a/nvim/.config/nvim/lua/tobyvin/plugins.lua +++ b/nvim/.config/nvim/lua/tobyvin/plugins.lua @@ -49,6 +49,9 @@ M.plugins = function(use) config = function() require("auto-session").setup({ log_level = "error", + cwd_change_handling = { + restore_upcoming_session = true, + }, }) end, }) diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/lualine.lua b/nvim/.config/nvim/lua/tobyvin/plugins/lualine.lua index a7b223a..41022b0 100644 --- a/nvim/.config/nvim/lua/tobyvin/plugins/lualine.lua +++ b/nvim/.config/nvim/lua/tobyvin/plugins/lualine.lua @@ -22,7 +22,8 @@ M.setup = function() return end - local nvim_navic = require("nvim-navic") + local navic_ok, navic = pcall(require, "nvim-navic") + local auto_session_ok, auto_session_library = pcall(require, "auto-session-library") local modules = require("lualine_require").lazy_require({ highlight = "lualine.highlight", @@ -123,9 +124,27 @@ M.setup = function() }, }, lualine_c = { - { "filetype", icon_only = true, colored = false }, - "filename", - { nvim_navic.get_location, cond = nvim_navic.is_available }, + + { + auto_session_library.current_session_name, + cond = function() + return auto_session_ok + end, + separator = ">", + }, + -- { "filetype", icon_only = true, colored = false }, + { + "filename", + path = 1, + separator = ">", + shorting_target = 100, + }, + { + navic.get_location, + cond = function() + return navic_ok and navic.is_available() + end, + }, }, lualine_x = { "encoding", @@ -134,25 +153,18 @@ M.setup = function() }, }, tabline = { - -- lualine_b = { { "buffers", buffers_color = { inactive = "StatusLineNC" } } }, lualine_b = { { "buffers", - -- TODO: figure out how to highlight diagnostic signs fmt = function(name, bufnr) - return string.format("%s %s", name, utils.diagnostics_str(bufnr)) + return string.format("%s %s", name, utils.diagnostic_indicator(bufnr)) end, }, }, - -- lualine_y = { "tabs" }, lualine_y = { { "tabs", mode = 1 } }, }, - extensions = { "quickfix", "man", "fzf", "nvim-dap-ui" }, + extensions = { "quickfix", "man", "fzf", "nvim-dap-ui", "symbols-outline", "toggleterm" }, }) - - -- local nmap = utils.create_map_group("n", "b", { desc = "Buffers" }) - -- nmap("c", M.close_with_pick, { desc = "Close Buffer" }) - -- nmap("b", M.pick_buffer, { desc = "Pick Buffer" }) end return M diff --git a/nvim/.config/nvim/lua/tobyvin/utils.lua b/nvim/.config/nvim/lua/tobyvin/utils.lua index a7705f9..e51b0b3 100644 --- a/nvim/.config/nvim/lua/tobyvin/utils.lua +++ b/nvim/.config/nvim/lua/tobyvin/utils.lua @@ -1,29 +1,11 @@ ---@diagnostic disable: missing-parameter local M = {} -M.diagnostic_signs = { - hint = { text = " ", texthl = "DiagnosticSignHint" }, - info = { text = " ", texthl = "DiagnosticSignInfo" }, - warn = { text = " ", texthl = "DiagnosticSignWarn" }, - error = { text = " ", texthl = "DiagnosticSignError" }, +M.progress_signs = { + complete = { text = " ", texthl = "diffAdded" }, + spinner = { text = { "⣷", "⣯", "⣟", "⡿", "⢿", "⣻", "⣽", "⣾" }, texthl = "DiagnosticSignInfo" }, } -setmetatable(M.diagnostic_signs, { - __index = function(t, k) - if type(k) == "number" then - local levels = { "hint", "info", "warn", "error" } - return levels[k] - end - - local fmt_k = k:gsub("warning", "warn"):lower() - if t[fmt_k] ~= nil then - return t[fmt_k] - end - - return t[k] - end, -}) - M.debug_signs = { breakpoint = { text = " ", texthl = "debugBreakpoint" }, condition = { text = "ﳁ ", texthl = "debugBreakpoint" }, @@ -32,32 +14,39 @@ M.debug_signs = { stopped = { text = " ", texthl = "debugBreakpoint", linehl = "debugPC", numhl = "debugPC" }, } -M.progress_signs = { - complete = { text = " ", texthl = "diffAdded" }, - spinner = { text = { "⣷", "⣯", "⣟", "⡿", "⢿", "⣻", "⣽", "⣾" }, texthl = "DiagnosticSignInfo" }, +M.diagnostic_signs = { + HINT = { text = " ", texthl = "DiagnosticSignHint" }, + INFO = { text = " ", texthl = "DiagnosticSignInfo" }, + WARN = { text = " ", texthl = "DiagnosticSignWarn" }, + ERROR = { text = " ", texthl = "DiagnosticSignError" }, } -M.diagnostics_indicator = function(diagnostics_count) - local tbl = {} - for level, count in pairs(diagnostics_count) do - table.insert(tbl, M.diagnostic_signs[level].text .. count) - end - return table.concat(tbl, " ") -end +setmetatable(M.diagnostic_signs, { + __index = function(t, k) + if type(k) == "number" then + return t[vim.diagnostic.severity[k]] + end + return t[k:upper():gsub("WARNING", "WARN")] + end, +}) -M.diagnostics_count = function(bufnr) +M.diagnostic_count = function(bufnr) local items = {} - for i, level in ipairs({ "hint", "info", "warn", "error" }) do - local count = #vim.diagnostic.get(bufnr, { severity = i }) - if count > 0 then - items[level] = count - end + for i, level in ipairs(vim.diagnostic.severity) do + items[level] = #vim.diagnostic.get(bufnr, { severity = i }) end return items end -M.diagnostics_str = function(bufnr, highlight) - return M.diagnostics_indicator(M.diagnostics_count(bufnr)) +M.diagnostic_indicator = function(bufnr) + local diagnostic_count = M.diagnostic_count(bufnr) + local tbl = {} + for level, count in pairs(diagnostic_count) do + if count > 0 then + table.insert(tbl, M.diagnostic_signs[level].text .. count) + end + end + return table.concat(tbl, " ") end M.update_spinner = function(client_id, token) -- cgit v1.2.3-70-g09d2