+32
-4
README.md
+32
-4
README.md
···
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
···
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
}
···
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
···
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
+
## Requirements
8
+
9
+
- Neovim 0.10 or newer
10
+
- `jj` installed and available on `PATH`
11
+
12
+
## How do I use it?
13
+
14
+
Once you connect a plugin, it will automatically set the `vim.b.jj_desc` variable, which contains the description or `nil`. If your currently open buffer is not a file, (e.g. terminal) `vim.b.jj_desc` will return `nil`. Make sure to handle that case in your configuration!
15
+
16
## Example with NvChad
17
18
```lua
···
30
jj_msg = function()
31
local result = vim.b.jj_desc -- The variable you need
32
33
+
if not result then -- Null handling - just don't display anything
34
return ""
35
end
36
+
37
+
-- May look bad online - I am using a Nerd Font commit icon here
38
+
return "%#St_JJ_Text# " .. result .. " " -- Decorating the description
39
end,
40
}
41
}
···
44
45
```
46
47
+
And here comes the result!
48
+
49
+

50
+
51
## Setup
52
53
**Lazy**
54
```lua
55
{
56
'https://tangled.org/bpavuk.neocities.org/jj-log.nvim',
57
+
opts = {
58
+
-- these are default options
59
+
out_waiting = "...",
60
+
out_no_jj_repo = "~no_jj_repo~",
61
+
out_no_desc = "~no_desc~",
62
+
max_desc_length = 47, -- including truncation dots, that's 50
63
+
},
64
}
65
```
66
67
I'll be happy to add other package manager instructions! Hit me up, open an issue, or send a PR
68
+
69
+
## Contributing?
70
+
71
+
You can do so much to help me develop this plugin:
72
+
73
+
- Try to break it and open an issue
74
+
- Try to fix it and open a PR
75
+
- Most importantly, spread the word about it
docs/assets/nvchad_statusbar.png
docs/assets/nvchad_statusbar.png
This is a binary file and will not be displayed.
+24
-6
lua/jj-log/init.lua
+24
-6
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
···
9
return
10
end
11
12
local jj_root = vim.fs.find(
13
".jj", {
14
upward = true,
···
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
···
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
···
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
···
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" }, {
···
1
local M = {}
2
3
+
local defaults = {
4
+
out_waiting = "...",
5
+
out_no_jj_repo = "~no_jj_repo~",
6
+
out_no_desc = "~no_desc~",
7
+
max_desc_length = 47,
8
+
}
9
+
10
+
M.config = vim.deepcopy(defaults)
11
+
12
M.update_jj_status = function(bufnr)
13
+
vim.api.nvim_buf_set_var(bufnr, "jj_desc", M.config.out_waiting)
14
15
local current_file = vim.api.nvim_buf_get_name(bufnr)
16
if current_file == "" or current_file == nil then
···
18
return
19
end
20
21
+
if not vim.fn.filereadable(current_file) then
22
+
vim.api.nvim_buf_del_var(bufnr, "jj_desc")
23
+
return
24
+
end
25
+
26
local jj_root = vim.fs.find(
27
".jj", {
28
upward = true,
···
33
)[1]
34
35
if not jj_root then
36
+
vim.api.nvim_buf_set_var(bufnr, "jj_desc", M.config.out_no_jj_repo)
37
return
38
end
39
···
42
43
local cmd = { "jj", "log", "-R", repo_root, "-r", "@", "-T", "description", "--no-graph", }
44
45
+
vim.system(cmd, { text = true, cwd = vim.fs.dirname(repo_root) }, function(obj)
46
if obj.code ~= 0 then
47
vim.api.nvim_buf_del_var(bufnr, "jj_desc")
48
return
···
51
local output = vim.trim(obj.stdout or "")
52
output = output:gsub("\n", ""):gsub("^%s*", ""):gsub("%s*$", "")
53
54
+
if output == "" then output = M.config.out_no_desc end
55
+
if #output > (M.config.max_desc_length + 3) then
56
+
output = string.sub(output, 1, M.config.max_desc_length) .. "..."
57
+
end
58
59
vim.schedule(function()
60
if vim.api.nvim_buf_is_valid(bufnr) then
···
68
end)
69
end
70
71
+
M.setup = function(opts)
72
+
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
73
+
74
local group = vim.api.nvim_create_augroup("JJLogPlugin", { clear = true })
75
76
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter", "BufWritePost", "FocusGained" }, {