Skip to content

fix(github-pat-install): make it work on macOS - #26

Merged
natevick merged 1 commit into
mainfrom
fix/stat-portability
Aug 21, 2026
Merged

fix(github-pat-install): make it work on macOS#26
natevick merged 1 commit into
mainfrom
fix/stat-portability

Conversation

@natevick

Copy link
Copy Markdown
Owner

github-pat-install shipped in #25 and does not run on a Mac. Two separate failures, both on paths the script's own header documents.

1. stat -c is GNU-only

$ stat -c%s /tmp/probe
stat: illegal option -- c

Three call sites used it: the "already exists (N bytes)" prompt — i.e. the moment you're deciding whether to clobber an existing token — and the wrote … (N bytes, mode M) confirmation.

Replaced with file_size / file_mode, chosen by probing stat -c%s once. The probe is in the GNU direction deliberately: BSD rejects -c unambiguously, so Linux keeps byte-for-byte the flags it had.

2. pbpaste | died silently

IFS= read -r token returns non-zero at EOF when input has no trailing newline. pbpaste emits none (verified: clipboard read back with no 0x0a terminator), so set -e killed the script after reading the token but before writing it:

script exit code  : 1
stdout bytes      : 0
stderr bytes      : 0
token file written: NO

No message, nothing written. read had already populated $token, so the fix tolerates the EOF and leans on the existing [ -n "${token:-}" ] || die guard for genuinely-empty input.

Verification

Run on this Mac against a throwaway GITHUB_PAT_DIR, never a real token:

Case Result
fresh install, pipe with newline wrote … (40 bytes, mode 600)
fresh install, pipe without newline (pbpaste shape) wrote … (40 bytes, mode 600) — was silent exit 1
existing token, answer y prompt reports already exists (39 bytes) — was illegal option
existing token, answer n aborted; nothing changed, old token intact
empty stdin error: no token entered; nothing changed, nothing written
GNU-shaped stat shim on PATH selects the -c flags — Linux path intact

shellcheck clean; pre-commit (whitespace, EOF, shellcheck, gitleaks) passed.

Two ways the script failed on a Mac, both on paths its own header documents.

`stat -c%s` / `stat -c%a` are GNU coreutils flags. BSD stat rejects them
outright ("stat: illegal option -- c"), so the "already exists" prompt and the
"wrote N bytes, mode M" confirmation both broke — the former right before
asking whether to overwrite an existing token. Replaced with file_size /
file_mode helpers selected by probing `stat -c%s` once: BSD rejects it, GNU
does not, so the Linux agent boxes keep the exact flags they had.

`IFS= read -r token` returns non-zero at EOF when the input has no trailing
newline. `pbpaste` emits none, so the documented `pbpaste | github-pat-install
<owner>` died on set -e before writing anything — exit 1, zero bytes of output,
no error message. The value was already in $token, so tolerate the EOF and let
the existing empty-token guard handle the genuinely-empty case.

Exercised on this Mac: fresh install, replace-existing (y and n), empty stdin,
and both pipe forms. Also run against a GNU-shaped stat shim to confirm the
probe still selects the -c flags.
@natevick
natevick merged commit cc40a92 into main Aug 21, 2026
3 checks passed
@natevick
natevick deleted the fix/stat-portability branch August 21, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant