firecat53 / urlscan

Mutt and terminal url selector (similar to urlview)
GNU General Public License v2.0
214 stars 37 forks source link

OSC 52 support #140

Open axelkar opened 8 months ago

axelkar commented 8 months ago

https://jdhao.github.io/2021/01/05/nvim_copy_from_remote_via_osc52/ https://github.com/microsoft/terminal/issues/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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

--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 commented 8 months ago

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 https://github.com/firecat53/urlscan/blob/a78bd06c7ec0c1d1f9b8b23d1afbbba306a3dabd/urlscan/urlchoose.py#L786-L787 to before this: https://github.com/firecat53/urlscan/blob/a78bd06c7ec0c1d1f9b8b23d1afbbba306a3dabd/urlscan/urlchoose.py#L762 and remove the with redirect_output():

firecat53 commented 8 months ago

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 commented 4 months ago

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.

firecat53 commented 4 months ago

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

axelkar commented 3 months ago

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)"'