commit fb5591aad67962446929b727226fd0f91b746e01
parent 57b356d65876e3169111179d665f88a49aafd6ac
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Wed, 15 Apr 2020 11:04:12 +0200
Fetch content from onion addresses through torsocks
Diffstat:
M | .local/bin/plumb | | | 60 | ++++++++++++++++++++++++++++++++++++++---------------------- |
1 file changed, 38 insertions(+), 22 deletions(-)
diff --git a/.local/bin/plumb b/.local/bin/plumb
@@ -50,10 +50,13 @@ termopen() {
fetch() {
_o="$(mktemp)"
+ if regeximatch "$1" "\.onion"; then
+ prefix=torsocks
+ fi
if type -v hurl >/dev/null 2>&1; then
- hurl "$1" > "$_o"
+ $prefix hurl "$1" > "$_o"
elif type -v curl >/dev/null 2>&1; then
- curl -L "$1" > "$_o"
+ $prefix curl -L "$1" > "$_o"
else
die 'could not find hurl or curl'
fi
@@ -61,12 +64,15 @@ fetch() {
}
annotate_date_string() {
- sed 's/^\([0-9][0-9][0-9][0-9]\)\([0-1][0-9]\)\([0-3][0-9]\)/\1-\2-\3 /;s/T\([0-2][0-9]\)\([0-5][0-9]\)\([0-5][0-9]\)/\1:\2:\3/'
+ sed 's/^\([0-9][0-9][0-9][0-9]\)\([0-1][0-9]\)\([0-3][0-9]\)/\1-\2-\3 /
+ s/T\([0-2][0-9]\)\([0-5][0-9]\)\([0-5][0-9]\)/\1:\2:\3/'
}
handle_calendar_invite() {
- starttime="$(grep -E "DTSTART.*TZID" "$1" | sed 's/.*://' | annotate_date_string )"
- endtime="$(grep -E "DTEND.*TZID" "$1" | sed 's/.*://' | annotate_date_string )"
+ starttime="$(grep -E "DTSTART.*TZID" "$1" | sed 's/.*://' | \
+ annotate_date_string )"
+ endtime="$(grep -E "DTEND.*TZID" "$1" | sed 's/.*://' | \
+ annotate_date_string )"
tzone="$(grep -E "DTEND.*TZID" "$1" | sed 's/.*TZID=\(.*\):.*/\1/' )"
summary="$(grep -E "SUMMARY.*:" "$1" | sed 's/.*: *//' )"
@@ -79,12 +85,18 @@ handle_calendar_invite() {
read -r $REPLY
case "$REPLY" in
Y|y|YES|Yes|yes|myes)
- month="$(printf '%s' "$starttime" | sed 's/.*-\([0-1][0-9]\)-[0-3][0-9].*/\1/')"
- day="$(printf '%s' "$starttime" | sed 's/.*-[0-1][0-9]-\([0-3][0-9]\).*/\1/')"
- hour_start="$(printf '%s' "$starttime" | sed 's/.* \([0-2][0-9]\):[0-5][0-9].*/\1/')"
- min_start="$(printf '%s' "$starttime" | sed 's/.* [0-2][0-9]:\([0-5][0-9]\).*/\1/')"
- hour_end="$(printf '%s' "$endtime" | sed 's/.* \([0-2][0-9]\):[0-5][0-9].*/\1/')"
- min_end="$(printf '%s' "$endtime" | sed 's/.* [0-2][0-9]:\([0-5][0-9]\).*/\1/')"
+ month="$(printf '%s' "$starttime" | \
+ sed 's/.*-\([0-1][0-9]\)-[0-3][0-9].*/\1/')"
+ day="$(printf '%s' "$starttime" | \
+ sed 's/.*-[0-1][0-9]-\([0-3][0-9]\).*/\1/')"
+ hour_start="$(printf '%s' "$starttime" | \
+ sed 's/.* \([0-2][0-9]\):[0-5][0-9].*/\1/')"
+ min_start="$(printf '%s' "$starttime" | \
+ sed 's/.* [0-2][0-9]:\([0-5][0-9]\).*/\1/')"
+ hour_end="$(printf '%s' "$endtime" | \
+ sed 's/.* \([0-2][0-9]\):[0-5][0-9].*/\1/')"
+ min_end="$(printf '%s' "$endtime" | \
+ sed 's/.* [0-2][0-9]:\([0-5][0-9]\).*/\1/')"
printf '%s/%s\t%s:%s-%s:%s %s (%s)\n' "$month" "$day" \
"$hour_start" "$min_start" "$hour_end" "$min_end" \
"$summary" "$tzone" \
@@ -93,9 +105,6 @@ handle_calendar_invite() {
upload "$calendar" >/dev/null;;
*) exit;;
esac
-
- #notify-send "$1" "$(printf 'start: %s\nend: %s\n%s' "$starttime" "$endtime" "$tzone")"
- #termopen less "$1"
}
handle_target() {
@@ -142,14 +151,19 @@ handle_target() {
case "$t" in
*scholar.google.*)
- t="$(printf '%s' "$t" | sed 's/.*scholar_url?url\=//;s/&hl\=.*//')";;
+ t="$(printf '%s' "$t" | \
+ sed 's/.*scholar_url?url\=//;s/&hl\=.*//')";;
*the-cryosphere-discuss.net/tc-*/)
- a="$(printf '%s' "$t" | sed 's/.*\(tc-[0-9]*-[0-9]*\).*/\1/')"
+ a="$(printf '%s' "$t" | \
+ sed 's/.*\(tc-[0-9]*-[0-9]*\).*/\1/')"
t="${t}${a}.pdf";;
*the-cryosphere.net/*/*/*/)
- v="$(printf '%s' "$t" | sed 's,.*/\([0-9][0-9]\)/.*,\1,')"
- n="$(printf '%s' "$t" | sed 's,.*/[0-9][0-9]/\([0-9][0-9][0-9][0-9]\)/.*,\1,')"
- y="$(printf '%s' "$t" | sed 's,.*/\([0-9][0-9][0-9][0-9]\)/.*,\1,')"
+ v="$(printf '%s' "$t" | \
+ sed 's,.*/\([0-9][0-9]\)/.*,\1,')"
+ n="$(printf '%s' "$t" | \
+ sed 's,.*/[0-9][0-9]/\([0-9][0-9][0-9][0-9]\)/.*,\1,')"
+ y="$(printf '%s' "$t" | \
+ sed 's,.*/\([0-9][0-9][0-9][0-9]\)/.*,\1,')"
t="${t}tc-${v}-${n}-${y}.pdf";;
esac
@@ -164,13 +178,15 @@ handle_target() {
elif regeximatch "$t" '\.(pdf|ps|epub|djvu)$'; then
zathura "$(fetch "$t")"
elif regeximatch "$t" '(youtube\.|youtu\.be|vimeo\.com)'; then
- cd ~/tmp && detach youtube-dl -f '[height\<=?768][fps\<=?30]+bestaudio/best' "$t"
+ cd ~/tmp && detach youtube-dl \
+ -f '[height\<=?768][fps\<=?30]+bestaudio/best' "$t"
elif regeximatch "$t" '(smbc-comics\.com|xkcd\.com|jspowerhour\.com)'; then
cd /tmp && detach comic "$t"
elif regexmatch "$t" '10\.[0-9]*\/'; then
detach $BROWSER "https://doi.org/${t}"
elif regexmatch "$t" '\.(txt|patch|diff|rst|md)$'; then
- termopen less "$(fetch "$t")"
+ f="$(fetch "$t")"
+ termopen less "$f"
elif regeximatch "$t" '^gopher://' || \
{ regexmatch "$t" '^(0|1|3|7|9|g|I|h)' && \
[ "$(printf '%s' "$t" | awk -F'\t' '{print NF}')" -eq 4 ]; }; then
@@ -183,7 +199,7 @@ handle_target() {
port="$(printf '%s' "$t" | awk -F'\t' '{print $4}')"
t="${host}:${port}/${type}${path}"
fi
- if regeximatch "\.onion"; then
+ if regeximatch "$t" "\.onion"; then
termopen torsocks sacc "$t"
else
termopen sacc "$t"