From f15a64c121bf4bc7f1f84aa8d41dcc9514ad406b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 15 Sep 2024 22:11:20 +0200 Subject: [PATCH] nvim: Extract statusline plugin into separate file Extract lualine into its own 'statusline.lua' plugin file. This makes the ui plugin file a little more lean but also prepares the way of tinkering with statusline alternatives, like heirline. --- nvim/.config/nvim/lua/plugins/statusline.lua | 90 ++++++++++++++++++++ nvim/.config/nvim/lua/plugins/ui.lua | 87 ------------------- 2 files changed, 90 insertions(+), 87 deletions(-) create mode 100644 nvim/.config/nvim/lua/plugins/statusline.lua diff --git a/nvim/.config/nvim/lua/plugins/statusline.lua b/nvim/.config/nvim/lua/plugins/statusline.lua new file mode 100644 index 0000000..468067b --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/statusline.lua @@ -0,0 +1,90 @@ +return { + -- statusline + { + "nvim-lualine/lualine.nvim", + cond = true, + dependencies = { { "nvim-tree/nvim-web-devicons", config = true } }, + config = function() + local has_pynvim = -1 + -- if molten exists, is initialized and connected to a kernel + -- show it in the statusline + local function molten() + -- we don't have access to python, disregard element + if has_pynvim == 0 then + return "" + elseif has_pynvim == 1 then + local status_ok, res = pcall(function() + return require("molten.status").kernels() ~= "" + end) + if status_ok and res then + return "󱪄" + end + return "" + -- we don't know if we have python yet, start a check + else + vim.system({ "poetry", "env", "info", "-p" }, { text = true }, function(obj) + if obj.code == 0 then + has_pynvim = 1 + else + has_pynvim = 0 + end + end) + has_pynvim = 0 + end + end + + -- count number of selected lines and characters + -- stolen: https://github.com/chrisgrieser/.config/blob/8af1841ba24f7c81c513e12f853b52f530ef5b37/nvim/lua/plugins/lualine.lua#L80C1-L87C4 + local function selectionCount() + local isVisualMode = vim.fn.mode():find("[Vv]") + if not isVisualMode then + return "" + end + local starts = vim.fn.line("v") + local ends = vim.fn.line(".") + local lines = starts <= ends and ends - starts + 1 or starts - ends + 1 + return " " .. tostring(lines) .. "L " .. tostring(vim.fn.wordcount().visual_chars) .. "C" + end + require("lualine").setup({ + options = { + icons_enabled = true, + theme = "auto", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + disabled_filetypes = {}, + always_divide_middle = true, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch", "diff", "diagnostics" }, + lualine_c = { "filename" }, + lualine_x = { "encoding", "fileformat", "filetype", molten }, + lualine_y = { "progress" }, + lualine_z = { selectionCount, "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = { "branch", "diff" }, + lualine_c = { "filename" }, + lualine_x = {}, + lualine_y = { "location" }, + lualine_z = {}, + }, + tabline = {}, + extensions = { + "aerial", + "lazy", + "man", + "mason", + "nvim-dap-ui", + "nvim-tree", + "oil", + "quickfix", + "toggleterm", + "trouble", + }, + }) + end, + event = { "VeryLazy" }, + }, +} diff --git a/nvim/.config/nvim/lua/plugins/ui.lua b/nvim/.config/nvim/lua/plugins/ui.lua index e0f13f1..33d0684 100644 --- a/nvim/.config/nvim/lua/plugins/ui.lua +++ b/nvim/.config/nvim/lua/plugins/ui.lua @@ -1,91 +1,4 @@ return { - -- statusline - { - "nvim-lualine/lualine.nvim", - dependencies = { { "nvim-tree/nvim-web-devicons", config = true } }, - config = function() - local has_pynvim = -1 - -- if molten exists, is initialized and connected to a kernel - -- show it in the statusline - local function molten() - -- we don't have access to python, disregard element - if has_pynvim == 0 then - return "" - elseif has_pynvim == 1 then - local status_ok, res = pcall(function() - return require("molten.status").kernels() ~= "" - end) - if status_ok and res then - return "󱪄" - end - return "" - -- we don't know if we have python yet, start a check - else - vim.system({ "poetry", "env", "info", "-p" }, { text = true }, function(obj) - if obj.code == 0 then - has_pynvim = 1 - else - has_pynvim = 0 - end - end) - has_pynvim = 0 - end - end - - -- count number of selected lines and characters - -- stolen: https://github.com/chrisgrieser/.config/blob/8af1841ba24f7c81c513e12f853b52f530ef5b37/nvim/lua/plugins/lualine.lua#L80C1-L87C4 - local function selectionCount() - local isVisualMode = vim.fn.mode():find("[Vv]") - if not isVisualMode then - return "" - end - local starts = vim.fn.line("v") - local ends = vim.fn.line(".") - local lines = starts <= ends and ends - starts + 1 or starts - ends + 1 - return " " .. tostring(lines) .. "L " .. tostring(vim.fn.wordcount().visual_chars) .. "C" - end - require("lualine").setup({ - options = { - icons_enabled = true, - theme = "auto", - component_separators = { left = "", right = "" }, - section_separators = { left = "", right = "" }, - disabled_filetypes = {}, - always_divide_middle = true, - }, - sections = { - lualine_a = { "mode" }, - lualine_b = { "branch", "diff", "diagnostics" }, - lualine_c = { "filename" }, - lualine_x = { "encoding", "fileformat", "filetype", molten }, - lualine_y = { "progress" }, - lualine_z = { selectionCount, "location" }, - }, - inactive_sections = { - lualine_a = {}, - lualine_b = { "branch", "diff" }, - lualine_c = { "filename" }, - lualine_x = {}, - lualine_y = { "location" }, - lualine_z = {}, - }, - tabline = {}, - extensions = { - "aerial", - "lazy", - "man", - "mason", - "nvim-dap-ui", - "nvim-tree", - "oil", - "quickfix", - "toggleterm", - "trouble", - }, - }) - end, - event = { "VeryLazy" }, - }, -- create pretty unobtrusive notifications { "j-hui/fidget.nvim",