cli icon indicating copy to clipboard operation
cli copied to clipboard

Consider `{.open some/path/to/whatever.xlsx}` as a way of delegating a file path to the OS

Open jennybc opened this issue 11 months ago • 2 comments

https://cli.r-lib.org/reference/links.html#default-handler

In RStudio file: URLs open within RStudio. If you click on a file link outside of RStudio, typically the operating system is consulted for the application to open it.

It might be interesting to have markup that produces the more common behaviour for a file hyperlink, i.e. to delegate opening to the OS.

In terms of mindset, then it becomes clear that .file is for file hyperlinks that you want to open "in this product", where the product might be RStudio or Positron (or VS Code). So probably a plain text file (maybe an image?). And .open (or some other designation) is for files where the OS should be consulted re: how to open. Like an Excel workbook or a Word document.

Context: In terminals in Positron/VS Code, file: hyperlinks are delegated to the OS and there's basically no way to intervene in that. (In the Positron R console, we can intervene and create behaviour similar to RStudio.) So in Positron/VS Code terminals, file hyperlinks that should open "in this product" have to be produced using a special URL scheme, e.g. vscode://file/{full path to file} or positron://file/{full path to file}.

https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls

This issue is related to a side point made in #601.

In hindsight, maybe it would have been good to introduce a scheme like rstudio://file{full path to file}, but I imagine that ship has sailed and it wouldn't make sense to reopen it.

Other interesting features supported by the vscode: and positron: scheme: can also be used to open a workspace (folder) or to go directly to the configuration for a setting.

jennybc avatar Dec 16 '24 22:12 jennybc

I wonder if this is something that could be configured by the end user, instead of the IDE and the package developer?

gaborcsardi avatar Dec 17 '24 08:12 gaborcsardi

I tend to think the person writing the code (vs the person running the code) is in the best position to know which behaviour is desired:

  • Open with whatever the OS thinks is "best" = typical behaviour for file:// links, though not in RStudio (or Positron's R console, which is emulating RStudio)
  • Open with "the current product" = typical behaviour for product:// links, where the construction of said links might come from using an auto-detected template or user opt-in

Because it really comes down to how likely it is that the file is plain text versus something else.

jennybc avatar Dec 17 '24 17:12 jennybc