Skip to content

fix: make every commandName() branch runnable when pasted - #64

Draft
lionello wants to merge 1 commit into
masterfrom
fix/command-name-runnable
Draft

fix: make every commandName() branch runnable when pasted#64
lionello wants to merge 1 commit into
masterfrom
fix/command-name-runnable

Conversation

@lionello

Copy link
Copy Markdown
Owner

commandName() feeds the OAuth callback page the command a user pastes into a shell verbatim, so every branch has to be runnable on its own. The bare-basename fallback was not: for a checkout invoked from an unrelated cwd, or any install whose directory is not on the PATH, onedrive is just not a command.

Now: keep the relative path while it stays short and below the cwd, fall back to the bare name when the script's directory really is on the PATH, and use an absolute path everywhere else.

Before / after

Same function driven over a set of cwd + argv[1] + PATH combinations:

scenario before after
repo cwd, bin/onedrive bin/onedrive bin/onedrive
cwd=/, deep relative onedrive /Users/…/bin/onedrive
global install, dir on PATH onedrive onedrive
sibling checkout, not on PATH onedrive /Users/…/bin/onedrive
cwd == script dir ./onedrive ./onedrive

The ❌ rows are the bug: a bare name for something that is not on the PATH.

Checks

  • process.argv[1] keeps the PATH symlink rather than resolving through to the realpath, verified with an npm-global-install-shaped symlink (bin/od -> ../lib/od.js run via PATH). So the new PATH-membership branch does fire for global installs — it is not silently dead.
  • The dropped Path.isAbsolute(rel) guard is not a regression on Windows: path.win32.relative('C:\\Users\\me', 'D:\\tools\\onedrive') returns D:\tools\onedrive, which is still an absolute, runnable path whichever branch returns it.

Known rough edges (not addressed here)

  • The PATH match is an exact string compare against Path.dirname(argv[1]), so a non-canonical entry (/usr/local/bin/ with a trailing slash, an unexpanded ~, or a case difference on Windows) misses and falls through to the long absolute path. Runnable, just uglier than needed — normalizing both sides would fix it.
  • Paths containing spaces are returned unquoted and break when pasted (my tools/onedrive → shell reads my). Pre-existing, but the absolute-path branch makes it more reachable, and it contradicts the verbatim-runnable premise. Wants shell quoting.

🤖 Generated with Claude Code

commandName() feeds the OAuth callback page the command a user pastes
into a shell verbatim, so each branch has to run on its own. The bare
basename fallback did not: for a checkout invoked from an unrelated cwd,
or any install whose directory is not on the PATH, "onedrive" is simply
not a command.

Keep the relative path only while it stays short and below the cwd, fall
back to the bare name when the script's directory really is on the PATH
(what the user typed, and what reads best for a global install), and use
an absolute path everywhere else.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@lionello
lionello marked this pull request as draft August 16, 2026 22:59
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