Skip to content

feat: add realpath to print an item's View Online URL - #74

Open
lionello wants to merge 1 commit into
masterfrom
feat/realpath
Open

feat: add realpath to print an item's View Online URL#74
lionello wants to merge 1 commit into
masterfrom
feat/realpath

Conversation

@lionello

@lionello lionello commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Closes #12.

realpath prints an item's own webUrl — the View Online address, which exists whether or not the file has ever been shared. That is deliberately not what ln does: ln calls createLink and mints a new sharing permission, and the URL it prints only exists because you shared the file. Different things, which is why #12 stayed open alongside ln.

Naming: realpath is the POSIX/coreutils verb for "take this name and give me its one true canonical form", which is exactly what webUrl is. readlink would be wrong — it means "print what this link points at", and nothing here is a link.

Both directions

onedrive realpath Documents/report.docx              # remote path
onedrive realpath ~/OneDrive/Documents/report.docx   # local synced path

Sync roots come from $OneDrive / $OneDriveConsumer / $OneDriveCommercial (set by the Windows client), ~/OneDrive, and any ~/Library/CloudStorage/OneDrive* — the leaf name varies per tenant on macOS, so it is discovered rather than hardcoded.

Only ~-, .-, /- or drive-letter-prefixed arguments are considered local, and an absolute path outside every sync root falls through to remote, so onedrive ls /Public-style paths keep working unchanged.

Verified against a live drive

Same file three ways — remote path, absolute local path, ~-relative local path — all print the same URL. A nested path (Xcj/WP_20130227_004.jpg) maps correctly, /etc/hosts falls back to remote and reports not-found, and no arguments gives the drive root. npm run lint and prettier --check are clean.

Known limitation

The local→remote mapping is purely textual; it does not consult the sync client's database. A file whose local name differs from its remote one (the sync client's rename-on-conflict) would resolve to the wrong item. Reading the real metadata is a larger job, left out of scope.

🤖 Generated with Claude Code

Answers #12: print the item's own `webUrl`, which exists whether or not
the file has ever been shared -- unlike the sharing link `ln` mints via
`createLink`.

Accepts a remote path, or a local path inside the folder the OneDrive
sync client mirrors. Sync roots come from $OneDrive/$OneDriveConsumer/
$OneDriveCommercial, ~/OneDrive, and ~/Library/CloudStorage/OneDrive*
(the leaf name varies per tenant on macOS). Only ~, ., / or drive-letter
prefixed arguments are treated as local, and an absolute path outside
every sync root falls through to remote, so `ls /Public` keeps working.

The mapping is textual: it does not consult the sync client's database,
so a local file renamed on conflict would resolve to the wrong item.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

Question about "Ability to get the link for a file"

1 participant