mirror of
https://github.com/iofq/nvim.nix.git
synced 2026-01-23 08:55:16 -06:00
even more jj mini/snacks rice
This commit is contained in:
parent
83f9f90f1f
commit
75c09a73ff
15 changed files with 345 additions and 337 deletions
|
|
@ -10,7 +10,7 @@ end
|
|||
|
||||
JJ.jj_start_watching_tree_state = function(buf_id, path)
|
||||
local stdout = vim.loop.new_pipe()
|
||||
local args = { 'workspace', 'root' }
|
||||
local args = { 'workspace', 'root', '--ignore-working-copy' }
|
||||
local spawn_opts = {
|
||||
args = args,
|
||||
cwd = vim.fn.fnamemodify(path, ':h'),
|
||||
|
|
@ -86,7 +86,7 @@ JJ.jj_set_ref_text = vim.schedule_wrap(function(buf_id)
|
|||
-- Set
|
||||
local stdout = vim.loop.new_pipe()
|
||||
local spawn_opts = {
|
||||
args = { 'file', 'show', '-r', '@-', './' .. basename },
|
||||
args = { 'file', 'show', '--ignore-working-copy', '-r', '@-', './' .. basename },
|
||||
cwd = cwd,
|
||||
stdio = { nil, stdout, nil },
|
||||
}
|
||||
|
|
|
|||
48
nvim/lua/plugins/lib/session_jj.lua
Normal file
48
nvim/lua/plugins/lib/session_jj.lua
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
local M = {}
|
||||
M.load = function()
|
||||
local jj_root = vim.system({ 'jj', 'workspace', 'root' }):wait()
|
||||
local sessions = require('mini.sessions')
|
||||
|
||||
if jj_root.code ~= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local result = vim
|
||||
.system({
|
||||
'jj',
|
||||
'log',
|
||||
'-r',
|
||||
'latest(heads(::@ & bookmarks()))',
|
||||
'--template',
|
||||
'bookmarks',
|
||||
'--no-pager',
|
||||
'--no-graph',
|
||||
})
|
||||
:wait()
|
||||
local branch = vim.trim(string.gsub(result.stdout, '[\n*]', ''))
|
||||
local root = vim.trim(string.gsub(jj_root.stdout, '\n', ''))
|
||||
local jj_sesh = string.gsub(string.format('jj:%s:%s', root, branch), '[./]', '-')
|
||||
if jj_sesh ~= '' then
|
||||
vim.opt.shadafile = vim.fn.stdpath('data') .. '/myshada/' .. jj_sesh .. '.shada'
|
||||
for name, _ in pairs(sessions.detected) do
|
||||
if name == jj_sesh then
|
||||
vim.ui.select({
|
||||
'No',
|
||||
'Yes',
|
||||
}, { prompt = 'Session found at ' .. jj_sesh .. ', load it?' }, function(c)
|
||||
if c == 'Yes' then
|
||||
-- load session (buffers, etc) as well as shada (marks)
|
||||
sessions.read(jj_sesh)
|
||||
vim.cmd('rshada')
|
||||
vim.notify('loaded jj session: ' .. jj_sesh)
|
||||
end
|
||||
end)
|
||||
return
|
||||
end
|
||||
end
|
||||
vim.cmd('wshada')
|
||||
sessions.write(jj_sesh)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -23,7 +23,7 @@ function M.status()
|
|||
file = string.match(text, '{.-=>%s*(.-)}')
|
||||
end
|
||||
|
||||
local diff = vim.fn.system('jj diff ' .. file .. ' --no-pager --stat --git')
|
||||
local diff = vim.fn.system('jj diff ' .. file .. ' --ignore-working-copy --no-pager --stat --git')
|
||||
table.insert(files, {
|
||||
text = text,
|
||||
file = file,
|
||||
|
|
@ -56,77 +56,64 @@ function M.status()
|
|||
end
|
||||
|
||||
function M.revs()
|
||||
local function jj_new()
|
||||
return function(picker, item)
|
||||
picker:close()
|
||||
if item then
|
||||
if not item.rev then
|
||||
Snacks.notify.warn('No branch or commit found', { title = 'Snacks Picker' })
|
||||
return
|
||||
end
|
||||
local cmd = { 'jj', 'new', '-r', item.rev }
|
||||
Snacks.picker.util.cmd(cmd, function()
|
||||
Snacks.notify('Checking out revision: ' .. item.rev, { title = 'Snacks Picker' })
|
||||
vim.cmd.checktime()
|
||||
end, { cwd = item.cwd })
|
||||
local function jj_new(picker, item)
|
||||
picker:close()
|
||||
if item then
|
||||
if not item.rev then
|
||||
Snacks.notify.warn('No branch or commit found', { title = 'Snacks Picker' })
|
||||
return
|
||||
end
|
||||
local cmd = { 'jj', 'new', '-r', item.rev }
|
||||
Snacks.picker.util.cmd(cmd, function()
|
||||
Snacks.notify('Checking out revision: ' .. item.rev, { title = 'Snacks Picker' })
|
||||
vim.cmd.checktime()
|
||||
end, { cwd = item.cwd })
|
||||
end
|
||||
end
|
||||
|
||||
local function jj_rev_cmd(rev)
|
||||
if rev ~= nil then
|
||||
return vim.fn.system { 'jj', 'show', '--git', '-r', rev }
|
||||
local function jj_rev_cmd(ctx)
|
||||
if ctx.item.rev then
|
||||
Snacks.picker.preview.cmd({ 'jj', 'show', '--ignore-working-copy', '--git', '-r', ctx.item.rev }, ctx)
|
||||
else
|
||||
ctx.preview:reset()
|
||||
return 'No preview available.'
|
||||
end
|
||||
end
|
||||
|
||||
local function jj_log(revset)
|
||||
if revset == nil then
|
||||
revset = '-r @'
|
||||
revset = '-r "ancestors(@,25)"'
|
||||
else
|
||||
revset = '-r ' .. revset
|
||||
end
|
||||
local status_raw = vim.fn.system(
|
||||
'jj log '
|
||||
'jj log --ignore-working-copy '
|
||||
.. revset
|
||||
..
|
||||
' --template \'if(root, format_root_commit(self), label(if(current_working_copy, "working_copy"), concat( format_short_commit_header(self) ++ " ", separate(" ", if(empty, label("empty", "(empty)")), if(description, description.first_line(), label(if(empty, "empty"), description_placeholder),),) ++ "\n",),))\''
|
||||
' --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",),)\''
|
||||
)
|
||||
local lines = {}
|
||||
|
||||
for line in status_raw:gmatch('[^\r\n]+') do
|
||||
local sign, rev, description = string.match(line, '(.)%s*(%a+)(.*)')
|
||||
local sign, rev = string.match(line, '(.)%s(%a+)%s.*')
|
||||
table.insert(lines, {
|
||||
text = line,
|
||||
file = line,
|
||||
sign = sign,
|
||||
rev = rev,
|
||||
hl = 'SnacksPickerGitMsg',
|
||||
description = description,
|
||||
diff = jj_rev_cmd(rev),
|
||||
})
|
||||
end
|
||||
|
||||
return lines
|
||||
end
|
||||
|
||||
local lines = jj_log('::@')
|
||||
|
||||
Snacks.picker.pick {
|
||||
source = 'jj_revs',
|
||||
items = lines,
|
||||
layout = 'ivy',
|
||||
format = 'text',
|
||||
title = 'jj log',
|
||||
confirm = jj_new(),
|
||||
preview = function(ctx)
|
||||
if ctx.item.file then
|
||||
Snacks.picker.preview.diff(ctx)
|
||||
else
|
||||
ctx.preview:reset()
|
||||
ctx.preview:set_title('No rev found')
|
||||
end
|
||||
end,
|
||||
items = jj_log(),
|
||||
confirm = jj_new,
|
||||
preview = jj_rev_cmd,
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue