Add Bash and PowerShell scripts for monitoring GitHub API rate limits#25
Add Bash and PowerShell scripts for monitoring GitHub API rate limits#25
Conversation
There was a problem hiding this comment.
Pull request overview
Adds command-line utilities to query and display GitHub API rate-limit buckets (via gh api rate_limit) in both Bash and PowerShell, with optional watch/JSON/quiet modes.
Changes:
- Add a Bash script to render
/rate_limitbuckets as a pressure-sorted table (or JSON) with watch mode. - Add a PowerShell equivalent that uses native JSON parsing (no
jq) and supports watch/JSON/quiet modes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
_in progress/gh-ratelimit |
New Bash implementation of a GitHub rate-limit monitor (table/JSON/watch). |
_in progress/gh-ratelimit.ps1 |
New PowerShell implementation of the same monitor (table/JSON/watch). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #!/usr/bin/env bash | ||
| # gh-ratelimit - GitHub API rate-limit monitor for Bash and POSIX-style shells. | ||
| # |
There was a problem hiding this comment.
The header comment claims this script works with "Bash and POSIX-style shells", but the implementation uses Bash-specific features (#!/usr/bin/env bash, [[ ... ]], local, and process substitution < <(...)). Either update the description to state it requires Bash, or refactor to be POSIX-sh compatible.
| #!/usr/bin/env bash | ||
| # gh-ratelimit - GitHub API rate-limit monitor for Bash and POSIX-style shells. | ||
| # | ||
| # What it does: | ||
| # Queries GitHub's /rate_limit endpoint through GitHub CLI and renders the | ||
| # current API buckets sorted by pressure so the tightest buckets appear first. | ||
| # | ||
| # Requirements: |
There was a problem hiding this comment.
These scripts are being added under _in progress/ (which also contains a space). That makes invocation and discoverability harder (paths need quoting) and is inconsistent with the existing top-level Bash/ and PowerShell/ script organization. Consider moving this Bash script into Bash/ (and the PowerShell one into PowerShell/) as part of this PR if they’re intended for general use.
| #!/usr/bin/env pwsh | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Displays GitHub API rate-limit buckets using GitHub CLI. | ||
|
|
||
| .DESCRIPTION | ||
| Queries GitHub's /rate_limit endpoint through GitHub CLI and renders the | ||
| response as either formatted JSON or a terminal-friendly table sorted by the | ||
| most constrained buckets first. | ||
|
|
||
| This PowerShell version only requires GitHub CLI. Unlike the Bash version, it | ||
| does not require jq because JSON parsing is handled natively by PowerShell. | ||
|
|
||
| .REQUIREMENTS | ||
| - GitHub CLI: gh |
There was a problem hiding this comment.
This script is being added under _in progress/ (which contains a space in the directory name). That makes running it more cumbersome (paths need quoting) and is inconsistent with the existing PowerShell/ directory used for PowerShell tooling in this repo. If this is meant to be a supported utility, consider relocating it into PowerShell/ and/or adding a stable entrypoint.
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| -w|--watch) WATCH=1 ;; | ||
| -i|--interval) INTERVAL="${2:-10}"; shift ;; |
There was a problem hiding this comment.
-i|--interval parsing shifts an extra time even when no interval value is provided (e.g., gh-ratelimit -i), which will trigger shift: shift count out of range under set -e and exit unexpectedly. Add an explicit check for a missing/invalid $2 before shifting, and print a clear usage error when the interval argument is absent.
| -i|--interval) INTERVAL="${2:-10}"; shift ;; | |
| -i|--interval) | |
| if [[ -z "${2:-}" || "${2:-}" == -* ]]; then | |
| echo "error: -i|--interval requires a positive integer argument" >&2 | |
| show_usage >&2 | |
| exit 2 | |
| fi | |
| if ! [[ "$2" =~ ^[1-9][0-9]*$ ]]; then | |
| echo "error: invalid interval '$2'; expected a positive integer" >&2 | |
| show_usage >&2 | |
| exit 2 | |
| fi | |
| INTERVAL="$2" | |
| shift | |
| ;; |
| # Header | ||
| local user host now | ||
| user=$(gh api user --jq .login 2>/dev/null || echo '?') | ||
| host=$(gh auth status 2>&1 | awk -F'[ ()]+' '/Logged in to/{print $5; exit}' || echo 'github.com') |
There was a problem hiding this comment.
Host parsing from gh auth status is using awk ... {print $5}, which (with the common output Logged in to github.com as <user> (...)) will print as instead of the hostname. Adjust the parsing to reliably extract the hostname (e.g., the token after to), or use a less brittle approach than fixed field numbers.
| host=$(gh auth status 2>&1 | awk -F'[ ()]+' '/Logged in to/{print $5; exit}' || echo 'github.com') | |
| host=$(gh auth status 2>&1 | awk -F'[ ()]+' '/Logged in to/ { for (i = 1; i < NF; i++) if ($i == "to") { print $(i + 1); exit } }' || echo 'github.com') |
Change
Feel free to remove this sample text
Type of Change
Please delete options that are not relevant.
Checklist