Compare commits
5
Commits
e5aa95f71d
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fab3dc1d94
|
||
|
|
c3bf6eec2e
|
||
|
|
ab59364e78 | ||
|
|
cdcea08071 | ||
|
|
00b85c7c7e |
No files matched your search
@@ -13,5 +13,8 @@ _G.Config = {
|
|||||||
later = function(f) misc.safely('later', f) end,
|
later = function(f) misc.safely('later', f) end,
|
||||||
autocmd = function(event, pattern, callback, desc, once)
|
autocmd = function(event, pattern, callback, desc, once)
|
||||||
vim.api.nvim_create_autocmd(event, { group = gr, pattern = pattern, callback = callback, desc = desc, once = once })
|
vim.api.nvim_create_autocmd(event, { group = gr, pattern = pattern, callback = callback, desc = desc, once = once })
|
||||||
end
|
end,
|
||||||
|
command = function(name, callback, desc, opts)
|
||||||
|
vim.api.nvim_create_user_command(name, callback, vim.tbl_extend('force', { desc = desc }, opts or {}))
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
+92
-38
@@ -1,52 +1,106 @@
|
|||||||
local ns = vim.api.nvim_create_namespace('git_status')
|
local ns = vim.api.nvim_create_namespace('git')
|
||||||
local hls = { M = 'DiagnosticWarn', ['?'] = 'DiagnosticInfo', D = 'DiagnosticError' }
|
local status_hl = { M = 'DiagnosticWarn', A = 'DiagnosticOk', D = 'DiagnosticError', ['?'] = 'DiagnosticInfo' }
|
||||||
|
|
||||||
local function show(buf_id, items, query)
|
local function git(args)
|
||||||
MiniPick.default_show(buf_id, items, query)
|
local result = vim.system(vim.list_extend({ 'git', '-c', 'core.quotepath=false' }, args)):wait()
|
||||||
vim.api.nvim_buf_clear_namespace(buf_id, ns, 0, -1)
|
if result.code ~= 0 then error(vim.trim(result.stderr), 0) end
|
||||||
|
return result.stdout
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Picker lines look like ' M path'; colour the status letter
|
||||||
|
local function show(buf, items, query)
|
||||||
|
MiniPick.default_show(buf, items, query)
|
||||||
|
vim.api.nvim_buf_clear_namespace(buf, ns, 0, -1)
|
||||||
for i, item in ipairs(items) do
|
for i, item in ipairs(items) do
|
||||||
if item.hl then
|
vim.api.nvim_buf_set_extmark(buf, ns, i - 1, 1, { end_col = 2, hl_group = status_hl[item.status], priority = 202, hl_mode = 'combine' })
|
||||||
vim.api.nvim_buf_set_extmark(buf_id, ns, i - 1, 1, { end_col = 3, hl_group = item.hl, priority = 202, hl_mode = 'combine' })
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Diff current file against the index (staged version)
|
-- Diff the current file against its staged version
|
||||||
local function diff()
|
local function diff()
|
||||||
vim.cmd.diffthis()
|
vim.cmd('diffthis')
|
||||||
vim.cmd('vert Git show :./%')
|
vim.cmd('vertical Git show :./%')
|
||||||
vim.cmd.diffthis()
|
vim.cmd('diffthis')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Deleted files can't be opened, so choosing one stages the deletion instead
|
-- Pick an unstaged file; picking a deleted file stages the deletion
|
||||||
local function choose(item)
|
local function status()
|
||||||
if vim.uv.fs_stat(item.path) then return MiniPick.default_choose(item) end
|
local items = {}
|
||||||
vim.fn.system({ 'git', 'add', '--', item.path })
|
for _, line in ipairs(vim.split(git({ 'status', '--short', '--untracked-files' }), '\n', { trimempty = true })) do
|
||||||
|
local s = line:sub(2, 2)
|
||||||
|
local path = line:sub(4):gsub('.* %-> ', ''):gsub('^"(.*)"$', '%1')
|
||||||
|
if s ~= ' ' then table.insert(items, { status = s, path = path, text = ' ' .. s .. ' ' .. path }) end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function choose(item)
|
||||||
|
if vim.uv.fs_stat(item.path) then return MiniPick.default_choose(item) end
|
||||||
|
git({ 'add', '--', item.path })
|
||||||
|
end
|
||||||
|
|
||||||
|
MiniPick.start({ source = { name = 'Git status', items = items, show = show, choose = choose } })
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
-- Write `path` as it is at `rev` to a temp file (empty if it doesn't exist there)
|
||||||
diff = diff,
|
local function file_at(rev, path)
|
||||||
status = function()
|
local file = vim.fn.tempname() .. '/' .. path
|
||||||
local lines = vim.fn.systemlist('git -c core.quotepath=false status -s -u')
|
vim.fn.mkdir(vim.fs.dirname(file), 'p')
|
||||||
if vim.v.shell_error ~= 0 then
|
local content = rev and vim.F.npcall(git, { 'show', rev .. ':' .. path }) or ''
|
||||||
return vim.notify('Not a git repository', vim.log.levels.WARN)
|
vim.fn.writefile(vim.split(content, '\n'), file, 'b')
|
||||||
end
|
return file
|
||||||
|
end
|
||||||
|
|
||||||
local items = {}
|
-- Open `right` in the current window and diff it against `left` in a split, replacing the previous split
|
||||||
for _, l in ipairs(lines) do
|
local split
|
||||||
-- Skip fully staged files (nothing left in the worktree column)
|
local function open_diff(left, right)
|
||||||
if l:sub(2, 2) ~= ' ' then
|
if split and vim.api.nvim_win_is_valid(split) then vim.api.nvim_win_close(split, true) end
|
||||||
local s = l:sub(1, 2):match('%S+')
|
vim.cmd('edit ' .. vim.fn.fnameescape(right))
|
||||||
local p = l:sub(4):gsub('.* %-> ', ''):gsub('^"(.*)"$', '%1')
|
vim.cmd('leftabove vertical diffsplit ' .. vim.fn.fnameescape(left))
|
||||||
items[#items + 1] = {
|
split = vim.api.nvim_get_current_win()
|
||||||
text = string.format(' %-2s %s', s == '??' and '?' or s, p),
|
vim.cmd('wincmd p')
|
||||||
path = p,
|
end
|
||||||
hl = hls[l:sub(2, 2)],
|
|
||||||
}
|
-- Last review, refreshed by `review()` without args
|
||||||
|
local last = {}
|
||||||
|
|
||||||
|
-- Review changes since the merge-base with `base` (default @{upstream}, i.e. unpushed commits) up to `head`.
|
||||||
|
-- Without `head` the working tree is used, so the right side is your real, editable file.
|
||||||
|
local function review(base, head)
|
||||||
|
if base or not last.base then last = { base = base or '@{upstream}', head = head, seen = {} } end
|
||||||
|
local root = vim.trim(git({ 'rev-parse', '--show-toplevel' }))
|
||||||
|
local merge_base = vim.trim(git({ 'merge-base', last.base, last.head or 'HEAD' }))
|
||||||
|
local range = last.head and (merge_base .. '..' .. last.head) or merge_base
|
||||||
|
|
||||||
|
local items = {}
|
||||||
|
for _, line in ipairs(vim.split(git({ 'diff', '--name-status', '--no-renames', range }), '\n', { trimempty = true })) do
|
||||||
|
local s, path = line:match('^(%a)\t(.*)$')
|
||||||
|
table.insert(items, { status = s, path = path, text = ' ' .. s .. ' ' .. path })
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ✓ is drawn on display (not part of the text) so it stays current when the picker is resumed
|
||||||
|
local function show_seen(buf, shown, query)
|
||||||
|
show(buf, shown, query)
|
||||||
|
for i, item in ipairs(shown) do
|
||||||
|
if last.seen[item.path] then
|
||||||
|
vim.api.nvim_buf_set_extmark(buf, ns, i - 1, 3, { virt_text = { { '✓' } }, virt_text_pos = 'overlay' })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #items == 0 then return vim.notify('No unstaged changes', vim.log.levels.INFO) end
|
end
|
||||||
|
|
||||||
MiniPick.start({ source = { items = items, name = 'Git Status', show = show, choose = choose } })
|
local function preview(buf, item)
|
||||||
end,
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, vim.split(git({ 'diff', range, '--', ':/' .. item.path }), '\n'))
|
||||||
}
|
vim.bo[buf].filetype = 'diff'
|
||||||
|
end
|
||||||
|
|
||||||
|
local function choose(item)
|
||||||
|
last.seen[item.path] = true
|
||||||
|
local real_file = root .. '/' .. item.path
|
||||||
|
local left = file_at(merge_base, item.path)
|
||||||
|
local right = (not last.head and vim.uv.fs_stat(real_file)) and real_file or file_at(last.head, item.path)
|
||||||
|
vim.schedule(function() open_diff(left, right) end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local name = 'Review ' .. last.base .. '..' .. (last.head or 'worktree')
|
||||||
|
MiniPick.start({ source = { name = name, items = items, show = show_seen, preview = preview, choose = choose } })
|
||||||
|
end
|
||||||
|
|
||||||
|
return { status = status, diff = diff, review = review }
|
||||||
+3
-3
@@ -5,7 +5,7 @@
|
|||||||
"src": "https://github.com/stevearc/conform.nvim"
|
"src": "https://github.com/stevearc/conform.nvim"
|
||||||
},
|
},
|
||||||
"mini.nvim": {
|
"mini.nvim": {
|
||||||
"rev": "ac5dffcc52b8378fbb15efeb0497a83e57a0b01c",
|
"rev": "6d5a29e86a7352739506c28e0bc50fe214b5216f",
|
||||||
"src": "https://github.com/nvim-mini/mini.nvim"
|
"src": "https://github.com/nvim-mini/mini.nvim"
|
||||||
},
|
},
|
||||||
"nvim-dap": {
|
"nvim-dap": {
|
||||||
@@ -13,11 +13,11 @@
|
|||||||
"src": "https://github.com/mfussenegger/nvim-dap"
|
"src": "https://github.com/mfussenegger/nvim-dap"
|
||||||
},
|
},
|
||||||
"nvim-lspconfig": {
|
"nvim-lspconfig": {
|
||||||
"rev": "ac9d2f7c4757db6320cab6697fe73e5e8adb2457",
|
"rev": "d8d2fda7aae57030452ce8cd6e770b1eb704514e",
|
||||||
"src": "https://github.com/neovim/nvim-lspconfig"
|
"src": "https://github.com/neovim/nvim-lspconfig"
|
||||||
},
|
},
|
||||||
"nvim-treesitter": {
|
"nvim-treesitter": {
|
||||||
"rev": "9a168f6357ed21c3a636e1727bc7d382abc451b8",
|
"rev": "a9c4e1457e2e59f1b82c8f78dcdb3b2517555200",
|
||||||
"src": "https://github.com/nvim-treesitter/nvim-treesitter"
|
"src": "https://github.com/nvim-treesitter/nvim-treesitter"
|
||||||
},
|
},
|
||||||
"rose-pine": {
|
"rose-pine": {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ vim.o.virtualedit = 'block' -- Allow cursor past end of line in visual block
|
|||||||
vim.o.spelloptions = 'camel' -- Spell-check camelCase words per part
|
vim.o.spelloptions = 'camel' -- Spell-check camelCase words per part
|
||||||
|
|
||||||
-- Completion
|
-- Completion
|
||||||
vim.o.autocomplete = true -- Show completion popup while typing
|
|
||||||
vim.o.complete = '.,w,b,kspell' -- Complete from buffer, windows, buffers, spell
|
vim.o.complete = '.,w,b,kspell' -- Complete from buffer, windows, buffers, spell
|
||||||
vim.o.completeopt = 'menuone,noselect,fuzzy,popup' -- Show menu for one match, don't preselect, fuzzy match, description popup
|
vim.o.completeopt = 'menuone,noselect,fuzzy,popup' -- Show menu for one match, don't preselect, fuzzy match, description popup
|
||||||
vim.o.pumheight = 10 -- Max items visible in completion popup
|
vim.o.pumheight = 10 -- Max items visible in completion popup
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- :Review [base] [head] e.g. `:Review origin/develop`, `:Review origin/main origin/feat-x`
|
||||||
|
-- Without args it refreshes the last review (or starts one against @{upstream}: unpushed commits)
|
||||||
|
Config.command('Review', function(o) require('git').review(o.fargs[1], o.fargs[2]) end, 'Review changes against merge-base', {
|
||||||
|
nargs = '*',
|
||||||
|
complete = function() return vim.fn.systemlist('git branch -a --format=%(refname:short)') end,
|
||||||
|
})
|
||||||
@@ -9,11 +9,17 @@ Config.now(function()
|
|||||||
starter.setup({
|
starter.setup({
|
||||||
items = {
|
items = {
|
||||||
function()
|
function()
|
||||||
local dirs = vim.list_extend(vim.fn.glob('~/Code/*', 0, 1), vim.fn.glob('~/Documents/*/*', 0, 1))
|
local dirs = vim.fn.glob('~/Code/*/', false, true)
|
||||||
return vim.iter(dirs):filter(function(p) return vim.fn.isdirectory(p) == 1 end):map(function(p)
|
return vim.tbl_map(function(p)
|
||||||
local open = function() vim.fn.chdir(p) require('mini.files').open(p) end
|
return {
|
||||||
return { name = vim.fn.fnamemodify(p, ':t'), action = open, section = 'Projects' }
|
name = vim.fn.fnamemodify(p, ':h:t'),
|
||||||
end):totable()
|
section = 'Projects',
|
||||||
|
action = function()
|
||||||
|
vim.fn.chdir(p)
|
||||||
|
MiniStarter.close()
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end, dirs)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
starter.sections.builtin_actions(),
|
starter.sections.builtin_actions(),
|
||||||
@@ -70,5 +76,4 @@ Config.now(function()
|
|||||||
MiniFiles.set_bookmark('c', vim.fn.stdpath('config'), { desc = 'Config' })
|
MiniFiles.set_bookmark('c', vim.fn.stdpath('config'), { desc = 'Config' })
|
||||||
MiniFiles.set_bookmark('w', vim.fn.getcwd, { desc = 'Working directory' })
|
MiniFiles.set_bookmark('w', vim.fn.getcwd, { desc = 'Working directory' })
|
||||||
end, 'Add default marks')
|
end, 'Add default marks')
|
||||||
require('mini.misc').setup_auto_root()
|
|
||||||
end)
|
end)
|
||||||
File renamed without changes.
Reference in new issue
Block a user