caarlos0/xdg-open-svc

Same as `nc -lk -p 2226 -e "xargs open"`

pbnj opened this issue ยท 10 comments

pbnj commented

This is not an issue. Just sharing a similar approach using netcat.

$ ncat --version
Ncat: Version 7.93 ( https://nmap.org/ncat )

$ ncat -lk -p 2226 --sh-exec "xargs open"

In another shell:

$ echo "https://carlosbecker.com" | nc localhost 2226

whoa, that's actually amazing... did not know you could do that...

Thanks for sharing!

added a note about it in the readme, thanks again!

FWIW, also mentioned you in https://carlosbecker.com/posts/pbcopy-pbpaste-open-ssh/

@pbnj I'm trying the ncat solution, but an issue I have is that when I do something like:

echo "https://carlosbecker.com" | nc localhost 2226

it "freezes", and only opens the link once I press ctrl+c there; is there something additional I need to do?

nc -q1

nc -q1

Hmmm, I have netcat (The GNU Netcat) 0.7.1, and it says:

nc: invalid option -- 'q'
Try `nc --help' for more information.
pbnj commented

@farzadmf - I have experienced the same issue with GNU netcat. I forget if I worked around it by using xargs (e.g. netcat -l -p 2226 -e "xargs open"), but I quickly ran into another issue with GNU version that netcat terminates/exits after the response and it doesn't support the -k, --keep-open Accept multiple connections in listen mode flag

Hmm, apparently I'm using netcat-openbsd for some reason, will investigate further later

with netcat-gnu, probably something like this:

echo "https://carlosbecker.com" | nc -c -w1 localhost 2226

fwiw, I just made netcat-gnu my standard too: caarlos0/dotfiles@84e75bd

Thank you both for your answers

@caarlos0 I do have another question for you: I installed xdg-open-svc using brew and I've brew services start it. I guess it should run automatically if I restart my computer?

Reason I'm asking that it works, but I think when I restart my computer, it doesn't work anymore; I restarted it, killed existing ssh processes etc. to make it work, but I guess that's not "normal", is it? ๐Ÿ˜