Keep an eye on those revision descriptions.
1local M = {} 2 3M.update_jj_status = function(bufnr) 4 vim.api.nvim_buf_set_var(bufnr, "jj_desc", "󰔟") 5 6 local current_file = vim.api.nvim_buf_get_name(bufnr) 7 if current_file == "" or current_file == nil then 8 vim.api.nvim_buf_del_var(bufnr, "jj_desc") 9 return 10 end 11 12 local jj_root = vim.fs.find( 13 ".jj", { 14 upward = true, 15 stop = vim.loop.os_homedir(), 16 path = current_file, 17 type = "directory", 18 } 19 )[1] 20 21 if not jj_root then 22 vim.api.nvim_buf_set_var(bufnr, "jj_desc", "~no_jj_repo~") 23 return 24 end 25 26 local repo_root = vim.fs.dirname(jj_root) 27 local _cmd = string.format("jj log -R %s -r @ -T description --no-graph", repo_root) 28 29 local cmd = { "jj", "log", "-R", repo_root, "-r", "@", "-T", "description", "--no-graph", } 30 31 vim.system(cmd, { text = true, cwd = vim.fs.dirname(repo_root) }, function(obj) 32 if obj.code ~= 0 then 33 vim.api.nvim_buf_del_var(bufnr, "jj_desc") 34 return 35 end 36 37 local output = vim.trim(obj.stdout or "") 38 output = output:gsub("\n", ""):gsub("^%s*", ""):gsub("%s*$", "") 39 40 if output == "" then output = "~no_desc~" end 41 if #output > 50 then output = string.sub(output, 1, 47) .. "..." end 42 43 vim.schedule(function() 44 if vim.api.nvim_buf_is_valid(bufnr) then 45 vim.api.nvim_buf_set_var(bufnr, "jj_desc", output) 46 47 if bufnr == vim.api.nvim_get_current_buf() then 48 vim.cmd.redrawstatus() 49 end 50 end 51 end) 52 end) 53end 54 55M.setup = function() 56 local group = vim.api.nvim_create_augroup("JJLogPlugin", { clear = true }) 57 58 vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter", "BufWritePost", "FocusGained" }, { 59 group = group, 60 pattern = "*", 61 callback = function(args) 62 M.update_jj_status(args.buf) 63 end, 64 }) 65end 66 67return M