Bohdan's terminal configuration

nvim: added jj log output to the statusline

bpavuk.neocities.org 536752be 484aafd6

verified
Changed files
+73
nvim
.config
nvim
lua
configs
custom
+1
nvim/.config/nvim/init.lua
··· 29 29 dofile(vim.g.base46_cache .. "defaults") 30 30 dofile(vim.g.base46_cache .. "statusline") 31 31 32 + require "configs.custom.jj_utils" 32 33 require "options" 33 34 require "nvchad.autocmds" 34 35 require "preferences"
+28
nvim/.config/nvim/lua/chadrc.lua
··· 13 13 -- Comment = { italic = true }, 14 14 -- ["@comment"] = { italic = true }, 15 15 -- }, 16 + 17 + hl_add = { 18 + St_JJ_Text = { 19 + fg = "white", 20 + bg = "none" 21 + }, 22 + }, 23 + } 24 + 25 + M.ui = { 26 + statusline = { 27 + enabled = true, 28 + theme = "default", 29 + separator_style = "block", 30 + order = { "mode", "file", "jj_msg", "%=", "lsp_msg", "%=", "diagnostics", "lsp", "cwd", "cursor" }, 31 + 32 + modules = { 33 + jj_msg = function() 34 + result = vim.b.jj_desc 35 + 36 + if not result then 37 + return "" 38 + end 39 + 40 + return "%#St_JJ_Text# 󰜘 " .. result .. " " 41 + end, 42 + } 43 + } 16 44 } 17 45 18 46 return M
+44
nvim/.config/nvim/lua/configs/custom/jj_utils.lua
··· 1 + local M = {} 2 + 3 + M.update_jj_status = function() 4 + local current_file = vim.api.nvim_buf_get_name(0) 5 + if current_file == "" or current_file == nil then 6 + vim.b.jj_desc = nil 7 + return 8 + end 9 + 10 + local jj_root = vim.fs.find( 11 + ".jj", { 12 + upward = true, 13 + stop = vim.loop.os_homedir(), 14 + path = current_file, 15 + type = "directory", 16 + } 17 + )[1] 18 + 19 + if not jj_root then 20 + vim.b.jj_desc = "~no_jj_repo~" 21 + return 22 + end 23 + 24 + local repo_root = vim.fs.dirname(jj_root) 25 + local cmd = string.format("jj log -R %s -r @ -T description --no-graph", repo_root) 26 + local output = vim.fn.system(cmd) 27 + 28 + output = output:gsub("\n", ""):gsub("^%s*", ""):gsub("%s*$", "") 29 + 30 + if output == "" then output = "~no_desc~" end 31 + if #output > 50 then output = string.sub(output, 1, 47) .. "..." end 32 + 33 + vim.b.jj_desc = output 34 + end 35 + 36 + local function init() 37 + vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "FocusGained" }, { 38 + callback = M.update_jj_status, 39 + }) 40 + end 41 + 42 + init() 43 + 44 + return M