aws-sso-cli icon indicating copy to clipboard operation
aws-sso-cli copied to clipboard

Better use of OSC terminal escape codes

Open kevcube opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe. We are using aws-sso-cli in codespaces, where xdg-open and xsel|xclip etc are not options. We are looking for ways to make the UX as simple as possible for the end users of this codespaces environment.

Describe the solution you'd like I am requesting options for url-action that can either print the URL to a terminal using OSC 8 escape codes, or copy into clipboard using OSC 52 escape codes. These are both supported by VSCode's integrated terminal, as well as kitty terminal. Not sure about others.

As mentioned, xsel|xclip are not available, so copy to clipboard doesn't work at all over a codespaces/remote connection, but print to terminal obviously works, OSC 8 just gives the opportunity to improve the formatting of these links.

I wish there was an escape code for opening a link in the user's default browser, but I don't see one.

kevcube avatar Oct 02 '24 13:10 kevcube

ex OSC 8 echo -e "\e]8;;https://example.com\aClick here\e]8;;\a"

ex OSC 52 printf "\e]52;c;$(echo -n 'Text to copy' | base64)\a"

kevcube avatar Oct 02 '24 14:10 kevcube

https://pkg.go.dev/github.com/charmbracelet/x/ansi#SetHyperlink

OSC 8 support in golang

kevcube avatar Oct 02 '24 14:10 kevcube

iTerm and VSCode terminal both support (on macOS) Command-Click. Not sure what the equivalent would be on Windows/Linux off the top of my head?

Testing echo -e "\e]8;;https://example.com\aClick here\e]8;;\a" in VSCode, basically just rewrites the string to be "Click here" but doesn't remove the need to Command-Click in my experience. Honestly, I'm not really excited by the idea of hiding the URL from the user since IMHO people shouldn't be clicking on random urls for authentication purposes.

As for clipboard support that feature already exists. https://synfinatic.github.io/aws-sso-cli/v1.17.0/config/#browser-urlaction-urlexeccommand

synfinatic avatar Oct 02 '24 16:10 synfinatic

Honestly, I'm not really excited by the idea of hiding the URL from the user since IMHO people shouldn't be clicking on random urls for authentication purposes.

agreed, but the terminal will provide more context about the full url with a hover. Anyone security-conscious should be checking this, anyone who doesn't care already didn't care.

As for clipboard support that feature already exists. https://synfinatic.github.io/aws-sso-cli/v1.17.0/config/#browser-urlaction-urlexeccommand

Yes it exists. But in a remote shell (ssh or container etc) this error happens:

FATAL   Unable to exec: unable to copy URL to clipboard: No clipboard utilities available. Please install xsel, xclip, wl-clipboard or Termux:API add-on for termux-clipboard-get/set. 

There could be a platform agnostic additional url-action, maybe termclip or something that will use escape codes to copy into the terminal user's clipboard. Because even with one of these utilities installed, it would be copied into the clipboard of the host machine in an ssh example.

kevcube avatar Oct 02 '24 16:10 kevcube

agreed, but the terminal will provide more context about the full url with a hover. Anyone security-conscious should be checking this, anyone who doesn't care already didn't care.

as a CLI, there's already the possibility that you're using escape codes to present a URL as something that it isn't, like echo -e "\e]8;;https://badurl.com\ahttps://goodurl.com\e]8;;\a"

kevcube avatar Oct 02 '24 16:10 kevcube

Regarding "Click me"- Yes. I don't deny that could be happening. Just not sure why I would deliberately obfuscate the actual URL the user should click on? I guess I'm having a hard time imaging there are a set of users who don't know what a URL looks like or when shown one, they don't know what to do with it.

As for clipboard- ah, now I understand the use case. That makes sense.

synfinatic avatar Oct 02 '24 16:10 synfinatic