Open axelkar opened 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!
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.
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?
--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.
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():
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!
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.
@axelkar, does @rbmarliere's solution work for your use case?
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)"'
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.