bunch of nixos updates
This commit is contained in:
@@ -215,6 +215,95 @@ return {
|
||||
desc = "Recent",
|
||||
},
|
||||
-- git
|
||||
{
|
||||
"<leader>gcb",
|
||||
function()
|
||||
local cwd = vim.fn.getcwd()
|
||||
|
||||
-- Helper to run git commands and capture both stdout and stderr
|
||||
local function git_cmd(cmd)
|
||||
local full_cmd = "cd " .. vim.fn.shellescape(cwd) .. " && " .. cmd .. " 2>&1"
|
||||
local handle = io.popen(full_cmd)
|
||||
local result = handle and handle:read("*a") or ""
|
||||
if handle then
|
||||
handle:close()
|
||||
end
|
||||
return result:gsub("%s+$", "")
|
||||
end
|
||||
|
||||
-- Check if in a git repo
|
||||
local git_dir = git_cmd("git rev-parse --git-dir")
|
||||
if git_dir == "" or git_dir:match("^fatal") then
|
||||
vim.notify("Not in a git repository", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
-- Get the default branch
|
||||
local default_branch = nil
|
||||
if git_cmd("git show-ref --verify --quiet refs/remotes/origin/main") == "" then
|
||||
default_branch = "main"
|
||||
elseif git_cmd("git show-ref --verify --quiet refs/remotes/origin/master") == "" then
|
||||
default_branch = "master"
|
||||
end
|
||||
|
||||
if not default_branch then
|
||||
vim.notify("No origin/main or origin/master found", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
-- Get current branch
|
||||
local current_branch = git_cmd("git branch --show-current")
|
||||
if current_branch == "" then
|
||||
current_branch = "HEAD"
|
||||
end
|
||||
|
||||
local compare_target = "origin/" .. default_branch
|
||||
|
||||
-- Get files that differ from origin/main (includes committed + uncommitted changes)
|
||||
local result = git_cmd("git diff --name-only " .. compare_target)
|
||||
|
||||
-- Also get untracked files
|
||||
local untracked = git_cmd("git ls-files --others --exclude-standard")
|
||||
|
||||
-- Combine results
|
||||
local all_files = {}
|
||||
local seen = {}
|
||||
|
||||
for line in result:gmatch("[^\r\n]+") do
|
||||
if line ~= "" and not seen[line] then
|
||||
seen[line] = true
|
||||
table.insert(all_files, { text = line, file = line })
|
||||
end
|
||||
end
|
||||
|
||||
for line in untracked:gmatch("[^\r\n]+") do
|
||||
if line ~= "" and not seen[line] then
|
||||
seen[line] = true
|
||||
table.insert(all_files, { text = line .. " [untracked]", file = line })
|
||||
end
|
||||
end
|
||||
|
||||
if #all_files == 0 then
|
||||
vim.notify("No modified files (vs " .. compare_target .. ")", vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
|
||||
Snacks.picker({
|
||||
title = "Modified Files (vs " .. compare_target .. ")",
|
||||
items = all_files,
|
||||
layout = { preset = "default" },
|
||||
confirm = function(picker, item)
|
||||
picker:close()
|
||||
if item and item.text then
|
||||
-- Strip [untracked] suffix if present
|
||||
local file = item.text:gsub(" %[untracked%]$", "")
|
||||
vim.cmd("edit " .. vim.fn.fnameescape(file))
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
desc = "Git Modified Files (vs origin/main)",
|
||||
},
|
||||
{
|
||||
"<leader>gb",
|
||||
function()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
return {
|
||||
"sQVe/sort.nvim",
|
||||
-- test
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user