{ 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 " 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}}"; } ]; }; }; }; }; }