mtime: 2023-09-19
I use newsboat (my atom/rss reader of choice) for more purposes than just opening links:
The point is, I ‘consume’ these various kinds of content in various ways, and so far I didn’t really have a neat way of doing it. I’d open most links in my web browser, and I had macros for opening youtube links in mpv, and for gemini links I’d manually copy them, which was obviously a bad solution.
Well, the other day, a friend was setting up his newsboat config and he asked me if I have some vim-keybinds reconfiguration. I shared my whole config with him, and he said he’s going to write a link-opening script, using the switch-case statement in sh. At first, I didn’t like the idea, but I soon realized it’d be more convenient than adding more macros, even though there’d be potential for errors. So, I wrote it and I’ve been using it for a couple of days now.
# link opener script
#!/usr/bin/sh
case "$1" in
*youtube*) mpv --profile=720p "$1" ;;
*\.png*) curl --output /tmp/image.png "$1" && sxiv /tmp/image.png ;;
*\.jpeg*) curl --output /tmp/image.jpeg "$1" && sxiv /tmp/image.jpeg ;;
*\.jpg*) curl --output /tmp/image.jpg "$1" && sxiv /tmp/image.jpg ;;
*.pdf) zathura "$1" ;;
http*) qutebrowser "$1" ;;
gemini*) amfora "$1" ;;
esac
There are no syntactical problems, at least not according to shellcheck, but that doesn’t mean there are no problems with the logic.
Problems I’m aware of:
Assume there are many more unknown problems.
Potential mitigation of failures: Add an || statement at the end of each case; if opening fails, copy “$1” to xclip.
I’ve just changed the newsboat browser to the script. I press ‘o’ and it opens the selected media in the right application, as expected, 99.9% of the time (so far).
# relevant newsboat config line
# sets the default browser to qutebrowser
browser "~/.config/newsboat/link_opener.sh"
Conclusion: I’ve got some pretty smart friends. Here’s a link to his plain-web log:
Take care until the next time :)