--@action Projects with changes --@version 1.0.0 --@author TheFile.Ninja --@id git-changes --@description Looks through the Git projects in the active pane's folder and lists those with uncommitted changes or unpushed commits in a folder of their own: lua://changes/. --@tags git, script folders --@requires shell -- Run it in the folder that holds your projects (C:\src, say). Each project -- with something to commit or push becomes a row in lua://changes/, which -- opens in a new tab: the row is the project's folder (Enter goes in), its -- Type column says the branch and what is waiting. Run it again to update. if not shell.which("git") then ui.message("Git is not on the PATH.", "Projects with changes", "error") return end local p = pane.active() local root = p:path() local projects = {} for _, e in ipairs(fs.list(root)) do if e.is_directory and fs.exists(path.join(e.full_path, ".git")) then projects[#projects + 1] = e end end if #projects == 0 then ui.message("No Git projects directly in " .. root .. ".", "Projects with changes") return end board.clear("vfs:changes") local prog = ui.progress("Git status") local waiting = 0 for i, project in ipairs(projects) do if prog:is_cancelled() then break end prog:update(math.floor((i - 1) * 100 / #projects), project.name) -- One line for the branch ("## main...origin/main [ahead 2]"), one per changed file. local r = shell.capture("git status --porcelain=v1 --branch", { working_dir = project.full_path, timeout_ms = 20000 }) if r.exit_code == 0 then local first = r.stdout:match("^[^\n]*") local branch = first:match("^## No commits yet on (%S+)") or first:match("^## (.-)%.%.%.") or first:match("^## (%S+)") local ahead = tonumber(first:match("ahead (%d+)")) or 0 local behind = tonumber(first:match("behind (%d+)")) or 0 local _, lines = r.stdout:gsub("\n", "") local changed = math.max(0, lines - 1) if changed > 0 or ahead > 0 then waiting = waiting + 1 board.set("vfs:changes", project.name, { target = project.full_path, branch = branch, changed = changed, ahead = ahead, behind = behind, }) end else ui.log_warning(project.name .. ": " .. (r.stderr ~= "" and r.stderr or "git status failed")) end end prog:finish(waiting .. " of " .. #projects .. " have changes") if waiting > 0 then p:new_tab("lua://changes/") else ui.status("All " .. #projects .. " projects are committed and pushed") end