Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSC 52 support #140

Open
axelkar opened this issue Jan 14, 2024 · 9 comments
Open

OSC 52 support #140

axelkar opened this issue Jan 14, 2024 · 9 comments

Comments

@axelkar
Copy link

axelkar commented Jan 14, 2024

https://jdhao.github.io/2021/01/05/nvim_copy_from_remote_via_osc52/
microsoft/terminal#2946
https://www.reddit.com/r/commandline/comments/mqyjby/where_can_i_learn_more_about_osc52/

The OSC 52 escape sequence allows programs to paste text to the clipboard over (plain terminal), SSH, telnet, or anything that provides a full ASCII byte stream to a compatible terminal such as Kitty, iTerm2, tmux, screen, Windows Terminal, etc.

# Shell example
echo "my message" | sh -c 'printf "\033]52;c;%s\a" "$(base64)"'
@firecat53
Copy link
Owner

Can you give an example of specific use cases using urlscan and what the user interface (and/or cli arguments) would look like? Thanks!

@axelkar
Copy link
Author

axelkar commented Jan 26, 2024

I'd use it to copy links from Neomutt running on a remote host to my local clipboard. I could also script it if you enabled the -r and -f scripts to pass through stdout.

@firecat53
Copy link
Owner

From urlscan.1 : Run a command with the selected URL as the argument or pipe the selected URL to a command using the --run-safe, --run and --pipe arguments. Does that work for you?

@axelkar
Copy link
Author

axelkar commented Jan 27, 2024

--pipe pipes the URL to stdin instead of substituting '{}' with it, right?

urlscan ./a --pipe --run-safe 'sh -c "notify-send hi $(cat)"'
urlscan ./a --run 'notify-send hi {}'

I use notify-send instead of let's say echo since I can't get any output through urlscan from the process.

Even with --single I can't see the output anywhere:

urlscan ./a --single --run 'echo hi {}'

So no, it doesn't work for me.

@axelkar
Copy link
Author

axelkar commented Jan 27, 2024

The following code does print Foo bar baz into the console when running. I think you have to close the TUI first and not use redirect_output.

import subprocess
subprocess.run("echo Foo bar baz", check=False, shell=True)

So move this block

if self.single is True:
self._quit()

to before this:
with redirect_output():

and remove the with redirect_output():

@firecat53
Copy link
Owner

I can see the value in adding support for this but after looking at it for awhile tonight, I'm going to defer working on this to anyone who is interested in creating a PR.

Thanks for the input and your interest in the project!

@rbmarliere
Copy link

rbmarliere commented Jun 6, 2024

If you have this wrapper script:

#!/bin/bash
echo $1 | sh -c 'printf "\033]52;c;%s\a" "$(base64)"'

and use it with:

macro pager \Co "<pipe-message> urlscan --run '/path/to/wrapper_script {}' --single<Enter>" "call urlscan to extract URLs out of a message"

it will work as intended! This issue can be closed.

P.S.: If inside tmux, make sure to have "set-option -g set-clipboard on" on your config.

rbmarliere added a commit to rbmarliere/dotfiles that referenced this issue Jun 6, 2024
@firecat53
Copy link
Owner

@axelkar, does @rbmarliere's solution work for your use case?

@axelkar
Copy link
Author

axelkar commented Jun 10, 2024

It doesn't work. Urlscan doesn't redirect the output from the --run script to stdout/stderr.

echo 'https://example.com' | urlscan --run '/home/nixos/urlscan-wrapper.sh {}' --single
#!/bin/sh
sleep 3
echo testtesttest
sleep 3
echo -ne "$1" | sh -c 'printf "\033]52;c;%s\a" "$(base64)"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants