mirror of
https://github.com/iofq/nvim.nix.git
synced 2026-01-23 08:55:16 -06: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
|
||||
|
|
@ -9,17 +9,12 @@ vim.schedule(function()
|
|||
ai.setup {
|
||||
n_lines = 300,
|
||||
custom_textobjects = {
|
||||
i = require('mini.extra').gen_ai_spec.indent(),
|
||||
a = ai.gen_spec.treesitter { a = '@parameter.outer', i = '@parameter.inner' },
|
||||
f = ai.gen_spec.treesitter { a = '@function.outer', i = '@function.inner' },
|
||||
},
|
||||
}
|
||||
|
||||
require('mini.git').setup()
|
||||
map('n', '<leader>gb', '<Cmd>Git blame -- %<CR>')
|
||||
map('n', '<leader>go', function()
|
||||
return MiniGit.show_at_cursor()
|
||||
end)
|
||||
|
||||
local jump = require('mini.jump2d')
|
||||
jump.setup {
|
||||
mappings = {
|
||||
|
|
|
|||
|
|
@ -55,16 +55,22 @@ map('n', '<leader>fj', Snacks.picker.jumps)
|
|||
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()
|
||||
require('nvim-treesitter-textobjects').setup()
|
||||
require('nvim-autopairs').setup()
|
||||
|
||||
require('jj').setup {}
|
||||
map('n', '<leader>gb', require('jj.annotate').file)
|
||||
map('n', '<leader>jf', require('jj.picker').status)
|
||||
map('n', '<leader>jj', require('jj.cmd').log)
|
||||
map('n', '<leader>jh', require('jj.picker').file_history)
|
||||
map('n', '<leader>je', require('iofq.jj').diffedit)
|
||||
map('n', '<leader>jd', function()
|
||||
require('jj.diff').open_vdiff { rev = 'trunk()' }
|
||||
end)
|
||||
|
||||
require('quicker').setup()
|
||||
map('n', '<leader>qf', function()
|
||||
require('quicker').toggle { max_height = 20 }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue