commit de0ae0319a1b6df1cadd5175618b7fe5bc7ee771
parent 16b1b01c8575afffef365420a56d25cddca55d3a
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Thu, 3 Oct 2019 10:58:11 +0200
Fix rss and comic handling
Diffstat:
3 files changed, 41 insertions(+), 34 deletions(-)
diff --git a/.config/mutt/muttrc b/.config/mutt/muttrc
@@ -165,15 +165,10 @@ macro index,pager \ l "<enter-command>unset wait_key<enter>\
<shell-escape>tmux split-window -l 10 \"tail -f /var/log/maillog\"; tmux select-pane -l<enter>\
<enter-command>set wait_key<enter>"
-folder-hook princeton 'macro index o "<enter-command>unset wait_key<enter>\
-<shell-escape>tmux split-window -l 1 \"mbsync princeton:INBOX; dwmstatus-refresh\";\
-tmux select-pane -l<enter>\
-<enter-command>set wait_key<enter>"'
-
-folder-hook geomail 'macro index o "<enter-command>unset wait_key<enter>\
-<shell-escape>tmux split-window -l 1 \"mbsync geomail:INBOX; dwmstatus-refresh\";\
-tmux select-pane -l<enter>\
-<enter-command>set wait_key<enter>"'
+# rss link handling
+macro index,pager \ o "<enter-command>unset wait_key<enter>\
+<pipe-message>sed -n \'s/\^URL: //p\' | linkhandler<enter>\
+<enter-command>set wait_key<enter>N"'
# notmuch-mutt integration, from `man notmuch-mutt`
macro index L "<enter-command>set my_old_pipe_decode=\$pipe_decode \
diff --git a/.local/bin/comic b/.local/bin/comic
@@ -5,18 +5,22 @@ url="${1:-https://www.smbc-comics.com/}"
case "$url" in
*smbc*)
- f="$(curl -s --write-out "%{filename_effective}\n" -OL \
- "$(curl -s -L "$url" | \
- grep '.png' | sed 1q | sed 's/^.*https/https/;s/".*$//')")";;
+ f="$(curl --write-out "%{filename_effective}\n" -OL \
+ $(curl -L "$url" | \
+ grep '.png' | sed 1q | sed 's/^.*https/https/;s/".*$//'))";;
*jspowerhour*)
f="$(curl -s --write-out "%{filename_effective}\n" -OL \
- "$(curl -s -L "$url" | \
- grep '.png' | sed 1q | sed 's/^.*src="//;s/" .*//;s|^|https:|')")";;
+ $(curl -s -L "$url" | \
+ grep '.png' | sed 1q | sed 's/^.*src="//;s/" .*//;s|^|https:|'))";;
*xkcd*)
f="$(curl -s --write-out "%{filename_effective}\n" -OL \
- "$(curl -s -L "$url" | \
- grep 'Image URL' | sed 1q | sed 's/^.*https/https/;s/".*$//')")";;
+ $(curl -s -L "$url" | \
+ grep 'Image URL' | sed 1q | sed 's/^.*https/https/;s/".*$//'))";;
+ *)
+ (>&2 echo "unknown site")
+ return 1;;
esac
xdg-open "$f"
+sleep 1
rm "$f"
diff --git a/.local/bin/linkhandler b/.local/bin/linkhandler
@@ -2,14 +2,14 @@
mkdir -p ~/tmp
cd ~/tmp || exit 42
-for url in "$@"; do
- if [ -f "$url" ]; then
- setsid "$TERMINAL" -e "$EDITOR $url"
+handle_url() {
+ if [ -f "$1" ]; then
+ setsid "$TERMINAL" -e "$EDITOR $1"
exit 0;
fi
action="undefined"
- case "$url" in
+ case "$1" in
*.png|*.PNG|*.jpg|*.JPG|*.jpeg|*.JPEG|*.tif|*.TIF|*.bmp|*.BMP|*.pdf|*.PDF)
action="xdg-open" ;;
*youtube.com*|*youtu.be*)
@@ -23,39 +23,47 @@ for url in "$@"; do
case "$action" in
"open")
- nohup xdg-open "$url" >/dev/null 2>&1 & ;;
+ nohup xdg-open "$1" >/dev/null 2>&1 & ;;
"open (tbb)")
- nohup tor-browser "$url" >/dev/null 2>&1 & ;;
+ nohup tor-browser "$1" >/dev/null 2>&1 & ;;
"xclip")
- printf "%s" "$url" | xclip ;;
+ printf "%s" "$1" | xclip ;;
"bookmark")
description="$(echo "$(date), $hostname" | \
dmenu -p "description:")"
- nohup $TERMINAL bookmark "$url" "$description" >/dev/null 2>&1 & ;;
+ nohup $TERMINAL bookmark "$1" "$description" >/dev/null 2>&1 & ;;
"comic")
- nohup comic "$url" >/dev/null 2>&1 & ;;
+ nohup comic "$1" >/dev/null 2>&1 & ;;
"curl")
- echo "curl -LO '$url' >/dev/null" | at now;;
+ echo "curl -LO '$1' >/dev/null" | at now;;
"html to pdf")
out="$HOME/tmp/html_to_pdf_$(date +'%F-%T')".pdf && \
- wkhtmltopdf "$url" "$out" && \
+ wkhtmltopdf "$1" "$out" && \
notify-send "$(basename $out) complete" ;;
"sci-hub")
- echo "shdl --tor-socks --notify --open --reference '$url' >/dev/null" \
+ echo "shdl --tor-socks --notify --open --reference '$1' >/dev/null" \
| at now;;
"add bibref")
- echo "getdoi '$url' | getref --notify >> '$BIB'" | at now;;
+ echo "getdoi '$1' | getref --notify >> '$BIB'" | at now;;
"mpv")
- nohup mpv -quiet "$url" >/dev/null 2>&1 & ;;
+ nohup mpv -quiet "$1" >/dev/null 2>&1 & ;;
"xdg-open")
- f="$(curl -s --write-out "%{filename_effective}\n" -OL "$url")"
+ f="$(curl -s --write-out "%{filename_effective}\n" -OL "$1")"
nohup xdg-open "$f" >/dev/null 2>&1 & ;;
"youtube-dl")
- echo "youtube-dl -f 'best[height<=1080]+bestaudio' '$url' >/dev/null" | at now;;
+ echo "youtube-dl -f 'best[height<=1080]+bestaudio' '$1' >/dev/null" | at now;;
"youtube-dl-music")
- nohup $TERMINAL -e youtube-dl-music "$url" >/dev/null 2>&1 & ;;
+ nohup $TERMINAL -e youtube-dl-music "$1" >/dev/null 2>&1 & ;;
*)
notify-send "${0##/*}" "Error: Action not understood"
exit 1 ;;
esac
-done
+}
+
+if [ $# -lt 1 ]; then
+ handle_url "$(cat)"
+else
+ for url in "$@"; do
+ handle_url "$url"
+ done
+fi