mirror of
https://github.com/iofq/nvim.nix.git
synced 2026-01-23 08:55:16 -06:00
jj file hist
This commit is contained in:
parent
ce017fd37c
commit
f6e4e39f2f
5 changed files with 73 additions and 31 deletions
|
|
@ -49,4 +49,42 @@ function M.status()
|
|||
}
|
||||
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
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ vim.api.nvim_create_autocmd('FileType', {
|
|||
local qf = vim.fn.getqflist()
|
||||
|
||||
local entry = qf[1]
|
||||
if not entry or not entry.user_data.diff then
|
||||
if not entry or not entry.user_data or not entry.user_data.diff then
|
||||
return nil
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@ map('n', '<leader>f.', Snacks.picker.resume)
|
|||
map('n', '<leader>fb', Snacks.picker.buffers)
|
||||
map('n', '<leader>fq', Snacks.picker.qflist)
|
||||
map('n', '<leader>jf', require('iofq.snacks_jj').status)
|
||||
map('n', '<leader>jh', function()
|
||||
require('iofq.snacks_jj').file_history(vim.api.nvim_buf_get_name(0))
|
||||
end)
|
||||
|
||||
vim.schedule(function()
|
||||
require('nvim-treesitter').setup()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue