commit 96927cde7e4b20815ca77d4f952a894756907035
parent cffb6b39e987b80b3c4cacd8627d6c5bfc30a645
Author: William Casarin <jb55@jb55.com>
Date: Tue, 1 Feb 2022 08:54:22 -0800
updates bins
Diffstat:
19 files changed, 117 insertions(+), 40 deletions(-)
diff --git a/bin/feed b/bin/feed
diff --git a/bin/fuzz-edit-diff-line b/bin/fuzz-edit-diff-line
@@ -4,10 +4,12 @@ set -eou pipefail
cdup=$(git rev-parse --show-cdup)
-file_line=$(git diff "$@" |
+res=$(git diff "$@" |
showlinenum show_path=1 |
grep -E ':\+' |
- fzf --ansi |
- sed -n "s,^\([^:]\+\):\([^:]\+\).*,\"${cdup}\1\" +\2,p")
+ fzf --ansi)
-echo "edit $file_line"
+file_line=$(<<<"$res" sed -n "s,^\([^:]\+\):\([^:]\+\).*,\"${cdup}\1\" +\2,p")
+line=$(<<<"$res" sed -En "s,.*:\+(.*)$,\1,p")
+
+echo "edit $file_line # $line"
diff --git a/bin/fuzz-edit-file b/bin/fuzz-edit-file
@@ -6,4 +6,5 @@ if [ "$1" = "--dir" ]; then
shift
fi
file=$(rg --files | fuzzer "$@")
-echo $EDITOR \"$(readlink -f $file)\"
+
+echo $EDITOR \"$file\"
diff --git a/bin/fuzz-reader b/bin/fuzz-reader
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+BOOKS_DIR="${1:-$HOME/docs}"
+
+set -eou pipefail
+
+document=$(find "$BOOKS_DIR" \( -iname '*.txt' -o -iname '*.epub' -o -iname '*.pdf' -o -iname '*.djvu' -o -iname '*.md' -o -iname '*.mediawiki' \) -type f -printf '%T@\t%f\t%p\n' |
+ sort -rn |
+ cutt -f2- |
+ ct |
+ fzf |
+ awk '{print $2}')
+
+name="$(basename "$document")"
+noext="${name%.*}"
+
+wname "$noext"
+ext="$(extname "$document")"
+if [ "$ext" == ".txt" ] || [ "$ext" == ".md" ] || [ "$ext" == ".mediawiki" ]; then
+ echo lessr "$document"
+else
+ echo open "$document"
+fi
diff --git a/bin/fuzz-rss b/bin/fuzz-rss
@@ -11,6 +11,14 @@ opener="open"
if [[ $typ =~ "@blog" ]]; then
opener="plainweb"
+elif [[ $typ =~ "@pod" ]]; then
+ opener="mpv"
+elif [[ $typ =~ "@yt" ]]; then
+ opener="mpv"
+elif [[ $typ =~ "@pdf" ]]; then
+ opener="pdfget"
+elif [[ $typ =~ "@arxiv" ]]; then
+ opener="pdfget"
fi
echo $opener $link
diff --git a/bin/git-email-contacts b/bin/git-email-contacts
@@ -0,0 +1 @@
+/home/jb55/src/xonsh/bitcoin-contacts/git-email-contacts+
\ No newline at end of file
diff --git a/bin/howdoi b/bin/howdoi
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+/home/jb55/.nix-profile/bin/howdoi "$@" 2>/dev/null
diff --git a/bin/last_ss b/bin/last_ss
@@ -1,2 +1,2 @@
#!/usr/bin/env sh
-\ls -d -t -1 ~/var/img/ss/* | head -n1
+\ls -d -t -1 ${1:-~/var/img/ss}/* | head -n1
diff --git a/bin/mail-prpatch b/bin/mail-prpatch
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+set -eou pipefail
+
+args=$(
+tac |
+grep -E 'github\.com.*pull/' |
+head -n1 |
+sed -En 's,.*github.com/([^/]+)/([^/]+)/pull/([0-9]+).*,\3 \1/\2,p'
+)
+
+prpatch $args
diff --git a/bin/mail-prpatch-demo b/bin/mail-prpatch-demo
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+set -eou pipefail
+
+prpatch() {
+ id="$1"
+ project="$2"
+ curl -sL "https://github.com/${project}/pull/${id}.patch"
+}
+
+args=$(
+ grep -E 'github\.com.*pull/' |
+ head -n1 |
+ sed -En 's,.*github.com/([^/]+)/([^/]+)/pull/([0-9]+).*,\3 \1/\2,p'
+)
+
+prpatch $args
diff --git a/bin/notwget b/bin/notwget
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+wget -U definitely-not-wget "$@"
diff --git a/bin/pdfget b/bin/pdfget
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+set -eou pipefail
+
+fname="$HOME/dl/$(sha256sum <<<"$1" | cut -d" " -f1).pdf"
+
+if [ -f "$fname" ]; then
+ open "$fname"
+ exit 0
+fi
+
+curl -sL --user-agent definitely-not-curl "$@" > "$fname"
+
+printf "saved %s\n" "$fname" >&2
+open $fname
diff --git a/bin/prpatch b/bin/prpatch
@@ -1,6 +1,6 @@
#!/bin/sh
-set -eou pipefail
+set -eo pipefail
if [ -z "$1" ]; then
printf "usage: prpatch <id> [owner/project]\n"
diff --git a/bin/reader b/bin/reader
@@ -1,21 +1,2 @@
#!/usr/bin/env bash
-BOOKS_DIR="${1:-$HOME/docs}"
-
-set -eou pipefail
-
-document=$(find "$BOOKS_DIR" \( -iname '*.txt' -o -iname '*.epub' -o -iname '*.pdf' -o -iname '*.djvu' \) -type f -printf '%T@\t%f\t%p\n' |
- sort -rn |
- cutt -f2- |
- ct |
- fzf |
- awk '{print $2}')
-
-name="$(basename "$document")"
-noext="${name%.*}"
-
-wname "$noext"
-if [ $(extname "$document") == ".txt" ]; then
- lessr "$document"
-else
- open "$document"
-fi
+$(fuzz-reader "$@")
diff --git a/bin/rssfeed b/bin/rssfeed
@@ -16,7 +16,7 @@ then
link=$(cat <<EOF
(.comments | strings) //
(.link | strings) //
-(.enclosure | objects | ."@url") //
+(.enclosure | objects | ."@url")
EOF
)
@@ -24,7 +24,7 @@ else
link=$(cat <<EOF
(.enclosure | objects | ."@url") //
-(.link | strings) //
+(.link | strings)
EOF
)
@@ -54,22 +54,30 @@ def parse_date:
| "\(.year)-\(.month | month_to_num)-\(.day)T\(.h):\(.m):\(.s)Z"
| fromdateiso8601) //
- ((.published // ."dc:date") | strings | sub(".00:00$"; "Z") | fromdateiso8601)
+ (."dc:date"
+ | strings
+ | capture("^(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[0-9]{2})")
+ | "\(.year)-\(.month)-\(.day)T00:00:00Z"
+ | fromdateiso8601
+ ) //
+
+ ((.published // ."dc:date") | strings | sub(".00:00$"; "Z") | fromdateiso8601)
+
;
def parse_url:
- . |
- objects |
- $link
- (.link | objects | ."@href")
-
+ .
+ | objects
+ | ( ($link // (.link | objects | ."@href")) //
+ (.link[] | select(."@type" == "application/pdf") | ."@href")
+ )
;
-(.rss.channel.item // .feed.entry) |
+(.rss.channel.item // .feed.entry // ."rdf:RDF".item) |
.[] |
[(. | parse_date), "$name", .title, (. | parse_url), "$typ"] |
@tsv
EOF
)
-curl --compressed -sL "$1" | xq -rc "$jqs"
+curl --compressed -sL "$1" | xq -rc "$jqs" || (printf "failed fetching $name\n" >&2 ; exit 2)
diff --git a/bin/rssfeeds b/bin/rssfeeds
@@ -6,4 +6,4 @@ while IFS=$'\t' read -r name type url
do
echo rssfeed "$url" "$name" "$type"
done
-) < ~/dotfiles/rssfeeds | parallel | sort -n > ~/var/rss.tsv
+) < ~/dotfiles/rssfeeds | parallel -j20 | sort -n > ~/var/rss.tsv
diff --git a/bin/search-files b/bin/search-files
@@ -7,7 +7,8 @@ fi
export RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
export FZF_DEFAULT_COMMAND="$RG_PREFIX $@"
res=$(fzf --bind "change:reload:$RG_PREFIX {q} || true" --ansi --phony --query "$INITIAL_QUERY")
-file=$(readlink -f $(cut -d: -f1 <<<"$res"))
+#file=$(readlink -f $(cut -d: -f1 <<<"$res"))
+file=$(cut -d: -f1 <<<"$res")
line=$(cut -d: -f2 <<<"$res")
echo +$line \"$file\" "# $(cut -d: -f4- <<<"$res")"
diff --git a/bin/timer b/bin/timer
@@ -3,7 +3,7 @@
set -e
usage() {
- printf "usage: timer "food is ready!" 10min\n"
+ printf "usage: timer 'food is ready!' 10min\n"
exit 0
}
diff --git a/bin/yt-channelid b/bin/yt-channelid
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+printf 'https://www.youtube.com/feeds/videos.xml?channel_id='
+curl -sL "$1" | pup 'meta[itemprop="channelId"] attr{content}'