This commit is contained in:
Sage 2026-03-03 15:42:41 +00:00
parent 31514a0b0c
commit e4f6a5b267
4 changed files with 70 additions and 2 deletions

View file

@ -14,6 +14,7 @@
./nvim
./zellij
./opencode
./gh.nix
];
config = lib.mkIf osConfig.mods.desktop.enable {

View file

@ -0,0 +1,67 @@
{
pkgs,
lib,
config,
...
}: let
gh-pr-review = pkgs.writeShellScriptBin "gh-pr-review" ''
PR_NUMBER=$1
if [ -z "$PR_NUMBER" ]; then
echo "Usage: gh-pr-review <pr-number>"
exit 1
fi
ORIGINAL_BRANCH=$(git branch --show-current)
HAS_CHANGES=$(git status --porcelain)
STASH_NAME="gh-pr-review-auto-stash-$(date +%s)"
if [ -n "$HAS_CHANGES" ]; then
echo "Stashing local changes..."
git stash push -m "$STASH_NAME"
fi
echo "Checking out PR #$PR_NUMBER..."
if gh pr checkout "$PR_NUMBER"; then
nvim -c "Octo review"
else
echo "Failed to checkout PR #$PR_NUMBER"
fi
echo "Restoring original branch: $ORIGINAL_BRANCH"
git checkout "$ORIGINAL_BRANCH"
if [ -n "$HAS_CHANGES" ]; then
# Find the stash index by message to be safe
STASH_INDEX=$(git stash list | grep "$STASH_NAME" | cut -d: -f1 | head -n1)
if [ -n "$STASH_INDEX" ]; then
echo "Restoring stashed changes..."
git stash pop "$STASH_INDEX"
fi
fi
'';
in {
options.mods.terminal.gh.enable = lib.mkEnableOption "enables gh and gh-dash";
config = lib.mkIf config.mods.terminal.gh.enable {
home.packages = [gh-pr-review];
programs.gh = {
enable = true;
extensions = [pkgs.gh-dash];
};
programs.gh-dash = {
enable = true;
settings = {
keybindings = {
prs = [
{
key = "d";
command = "gh-pr-review {{.PrNumber}}";
}
];
};
};
};
};
}