mirror of
https://github.com/iofq/nvim.nix.git
synced 2026-03-24 10:50:50 -05:00
use jj.nvim instead of custom jank
Some checks failed
build / build (nvim-min) (push) Failing after 37m5s
Some checks failed
build / build (nvim-min) (push) Failing after 37m5s
This commit is contained in:
parent
3c5c3a6745
commit
7a86861f09
7 changed files with 57 additions and 100 deletions
17
nvim/after/lua/iofq/jj.lua
Normal file
17
nvim/after/lua/iofq/jj.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
local M = {}
|
||||
|
||||
M.is_jj_diffedit_open = function()
|
||||
local qf = vim.fn.getqflist()
|
||||
|
||||
local entry = qf[1]
|
||||
if not entry or not entry.user_data or not entry.user_data.diff then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
M.diffedit = function()
|
||||
vim.fn.jobstart('jj diffedit --tool diffview-new')
|
||||
end
|
||||
return M
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
local M = {}
|
||||
|
||||
function M.status()
|
||||
local function get_files()
|
||||
local status_raw = vim.fn.system('jj diff --no-pager --quiet --summary')
|
||||
local files = {}
|
||||
|
||||
for status in status_raw:gmatch('[^\r\n]+') do
|
||||
local state, file = string.match(status, '^(%a)%s(.+)$')
|
||||
|
||||
if state and file then
|
||||
local hl = ''
|
||||
if state == 'A' then
|
||||
hl = 'SnacksPickerGitStatusAdded'
|
||||
elseif state == 'M' then
|
||||
hl = 'SnacksPickerGitStatusModified'
|
||||
elseif state == 'D' then
|
||||
hl = 'SnacksPickerGitStatusDeleted'
|
||||
elseif state == 'R' then
|
||||
hl = 'SnacksPickerGitStatusRenamed'
|
||||
file = string.match(file, '{.-=>%s*(.-)}')
|
||||
end
|
||||
|
||||
local diff = vim.fn.system('jj diff ' .. file .. ' --no-pager --stat --git')
|
||||
table.insert(files, {
|
||||
file = file,
|
||||
filename_hl = hl,
|
||||
diff = diff,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
return files
|
||||
end
|
||||
|
||||
Snacks.picker.pick {
|
||||
source = 'jj_status',
|
||||
items = get_files(),
|
||||
format = 'file',
|
||||
title = 'jj status',
|
||||
preview = function(ctx)
|
||||
if ctx.item.file then
|
||||
Snacks.picker.preview.diff(ctx)
|
||||
else
|
||||
ctx.preview:reset()
|
||||
ctx.preview:set_title('No preview')
|
||||
end
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
function M.file_history(filename)
|
||||
local function preview(ctx)
|
||||
if ctx.item.rev then
|
||||
Snacks.picker.preview.cmd(
|
||||
{ 'jj', 'log', '--ignore-working-copy', '--git', '-r', ctx.item.rev, '-p', filename },
|
||||
ctx
|
||||
)
|
||||
else
|
||||
ctx.preview:reset()
|
||||
return 'No preview available.'
|
||||
end
|
||||
end
|
||||
|
||||
local function get_history(f)
|
||||
local status_raw = vim.fn.system(
|
||||
'jj log --ignore-working-copy --no-graph'
|
||||
.. ' --template \'if(root, format_root_commit(self), label(if(current_working_copy, "working_copy"), concat(separate(" ", self.change_id().shortest(8), self.bookmarks()), " | ", if(empty, label("empty", "(empty)")), if(description, description.first_line(), label(if(empty, "empty"), description_placeholder),),) ++ "\n",),)\''
|
||||
.. ' -- '
|
||||
.. f
|
||||
)
|
||||
local lines = {}
|
||||
for line in status_raw:gmatch('[^\r\n]+') do
|
||||
local rev = string.match(line, '(%w+)%s.*')
|
||||
table.insert(lines, {
|
||||
text = line,
|
||||
rev = rev,
|
||||
})
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
Snacks.picker.pick {
|
||||
format = 'text',
|
||||
title = 'jj file history for ' .. filename,
|
||||
items = get_history(filename),
|
||||
preview = preview,
|
||||
}
|
||||
end
|
||||
return M
|
||||
Loading…
Add table
Add a link
Reference in a new issue