+1
.direnv/flake-profile
+1
.direnv/flake-profile
···
1
+
flake-profile-2-link
+1
.direnv/flake-profile-2-link
+1
.direnv/flake-profile-2-link
···
1
+
/nix/store/00g4iiial6nbpwaza45r9374mg9avdqn-nix-shell-env
+1
.envrc
+1
.envrc
···
1
+
use flake
+47
README.md
+47
README.md
···
1
+
# `jj-log.nvim`
2
+
3
+
*Watch your revision messages.*
4
+
5
+
This plugin retrieves the latest revision description (commit message) from `jj` and lets you use it through a global variable. It's nice to see the description of what you are working on at the moment.
6
+
7
+
## Example with NvChad
8
+
9
+
```lua
10
+
-- NvChad statusbar configuration
11
+
12
+
-- ...things...
13
+
M.ui = {
14
+
statusline = {
15
+
enabled = true,
16
+
theme = "default",
17
+
separator_style = "block",
18
+
order = { ..., "jj_msg", ... },
19
+
20
+
modules = {
21
+
jj_msg = function()
22
+
local result = vim.b.jj_desc -- The variable you need
23
+
24
+
if not result then
25
+
return ""
26
+
end
27
+
28
+
return "%#St_JJ_Text# " .. result .. " "
29
+
end,
30
+
}
31
+
}
32
+
}
33
+
-- ...things continue...
34
+
35
+
```
36
+
37
+
## Setup
38
+
39
+
**Lazy**
40
+
```lua
41
+
{
42
+
'https://tangled.org/bpavuk.neocities.org/jj-log.nvim',
43
+
opts = {},
44
+
}
45
+
```
46
+
47
+
I'll be happy to add other package manager instructions! Hit me up, open an issue, or send a PR
+22
dev.lua
+22
dev.lua
···
1
+
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
2
+
if not vim.loop.fs_stat(lazypath) then
3
+
vim.fn.system({
4
+
"git", "clone", "--filter=blob:none",
5
+
"https://github.com/folke/lazy.nvim.git",
6
+
lazypath,
7
+
})
8
+
end
9
+
vim.opt.rtp:prepend(lazypath)
10
+
11
+
require("lazy").setup({
12
+
{
13
+
"jj-log.nvim",
14
+
dir = ".",
15
+
config = function()
16
+
require("jj-log").setup()
17
+
end,
18
+
},
19
+
})
20
+
21
+
vim.opt.statusline = "%f %{get(b:, 'jj_desc', '')}"
22
+
+25
flake.lock
+25
flake.lock
···
1
+
{
2
+
"nodes": {
3
+
"nixpkgs": {
4
+
"locked": {
5
+
"lastModified": 1765779637,
6
+
"narHash": "sha256-KJ2wa/BLSrTqDjbfyNx70ov/HdgNBCBBSQP3BIzKnv4=",
7
+
"rev": "1306659b587dc277866c7b69eb97e5f07864d8c4",
8
+
"revCount": 912002,
9
+
"type": "tarball",
10
+
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.912002%2Brev-1306659b587dc277866c7b69eb97e5f07864d8c4/019b2463-7b8e-7042-8b7e-490d08a3cd7a/source.tar.gz"
11
+
},
12
+
"original": {
13
+
"type": "tarball",
14
+
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1"
15
+
}
16
+
},
17
+
"root": {
18
+
"inputs": {
19
+
"nixpkgs": "nixpkgs"
20
+
}
21
+
}
22
+
},
23
+
"root": "root",
24
+
"version": 7
25
+
}
+42
flake.nix
+42
flake.nix
···
1
+
{
2
+
description = "A flake for developing a jj-log.nvim plugin";
3
+
4
+
# Flake inputs
5
+
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1"; # unstable Nixpkgs
6
+
7
+
# Flake outputs
8
+
outputs =
9
+
{ self, ... }@inputs:
10
+
11
+
let
12
+
# The systems supported for this flake
13
+
supportedSystems = [
14
+
"x86_64-linux" # 64-bit Intel/AMD Linux
15
+
"aarch64-linux" # 64-bit ARM Linux
16
+
"x86_64-darwin" # 64-bit Intel macOS
17
+
"aarch64-darwin" # 64-bit ARM macOS
18
+
];
19
+
20
+
# Helper to provide system-specific attributes
21
+
forEachSupportedSystem =
22
+
f:
23
+
inputs.nixpkgs.lib.genAttrs supportedSystems (
24
+
system:
25
+
f {
26
+
pkgs = import inputs.nixpkgs { inherit system; };
27
+
}
28
+
);
29
+
in
30
+
{
31
+
devShells = forEachSupportedSystem (
32
+
{ pkgs }:
33
+
{
34
+
default = pkgs.mkShellNoCC {
35
+
packages = with pkgs; [
36
+
neovim # of course you need an instance of Neovim
37
+
];
38
+
};
39
+
}
40
+
);
41
+
};
42
+
}
+6
lazy.lua
+6
lazy.lua
+67
lua/jj-log/init.lua
+67
lua/jj-log/init.lua
···
1
+
local M = {}
2
+
3
+
M.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(current_file) }, 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)
53
+
end
54
+
55
+
M.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
+
})
65
+
end
66
+
67
+
return M