Cannot use urlscan in a non-interactive session
typoon opened this issue · 10 comments
When trying to use urlscan
in a non-interactive session (via a tmux plugin or rofi
) the following error is thrown:
Traceback (most recent call last):
File "/home/gilgamesh/code/urlscan/bin/urlscan", line 191, in <module>
main()
File "/home/gilgamesh/code/urlscan/bin/urlscan", line 166, in main
msg = process_input(args.message)
File "/home/gilgamesh/code/urlscan/bin/urlscan", line 140, in process_input
close_stdin()
File "/home/gilgamesh/code/urlscan/bin/urlscan", line 100, in close_stdin
fdesc = os.open('/dev/tty', os.O_RDONLY)
OSError: [Errno 6] No such device or address: '/dev/tty'
It can be reproduced by creating a script in your home directory like this:
#!/usr/bin/env bash
items=$(echo "https://www.google.com" | urlscan -d -n -c > /tmp/log.txt 2>&1)
echo $items
Run that script through rofi
for example (or any way you have of running it non-interactively) and check the contents of /tmp/log.txt
I have written a fix for this issue that I will submit the PR in a few minutes.
I don't understand how your example reproduces the error that you're reporting. I can and do use urlscan
fine from a tmux
plugin. Can you give an example of piping it into rofi
? For your rofi
case, I'm stuck not able to pipe any urls, but that's because I don't see an appropriate rofi
"mode", not because of any error in urlscan
.
More fundamentally, I don't understand why you're even trying to run urlscan
non-interactively. The whole point of it is to be an interactive command! Any attempt to use urlscan
non-interactively will have to perform "double-work" in parsing the urls out of the urlscan
output because after urlscan
itself parses the urls, it outputs much more than the raw urls. That's true even when option --compact
is used.
It is not piping it through rofi, it is literally running it through rofi. Open rofi and type the whole path to your shellscript in it. You will be able to reproduce it like that.
The use case is passing the output of urlscan to fzf when being used from the context of a tmux plugin.
Try this plugin I created: https://github.com/typoon/tmux-urlscan-fzf
Without the patch I submitted it does not work, because urlscan is ran non-interactively.
Hopefully this clears things out. Let me know if it still does not make sense.
Thank you for the conversation! I promise I am following, although I have not had time to sit down and process it fully. I hopefully will have time soon!
I'll go ahead and merge the PR as it seems so far to have no negative side
effects. If it helps you get creative in using urlscan, I'm all for it! Thanks
to the both of you for the respectful conversation and ideas thrown around. This
is how open source should work!