This is the result of ~100 commits to my NixOS config. Since I haven't always used `agenix-rekey`, this is another initial commit so that none of the secrets in my git history are leaked
39 lines
912 B
Nix
39 lines
912 B
Nix
{pkgs, ...}:
|
|
pkgs.writeTextFile rec {
|
|
name = "git-delete-stale";
|
|
destination = "/bin/${name}";
|
|
executable = true;
|
|
|
|
text = ''
|
|
#!${pkgs.nushell}/bin/nu
|
|
|
|
let localBranches = (
|
|
git branch
|
|
| lines
|
|
| str trim
|
|
| where not ($it | str starts-with '* ')
|
|
| where $it != 'master'
|
|
)
|
|
|
|
let remoteBranches = (
|
|
git branch -r
|
|
| lines
|
|
| str trim
|
|
| str replace 'origin/' ""
|
|
)
|
|
|
|
let staleBranches = ($localBranches | where { |$local| $local not-in $remoteBranches })
|
|
|
|
if ($staleBranches | is-empty) {
|
|
print 'No stale branches found.'
|
|
exit 0
|
|
}
|
|
|
|
let deleteBranches = (gum choose --header "Stale branches to delete" --no-limit ...($staleBranches) | lines | compact -e)
|
|
if ($deleteBranches | length) > 0 {
|
|
git branch -D ...($deleteBranches)
|
|
} else {
|
|
print 'No branches selected.'
|
|
}
|
|
'';
|
|
}
|