citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

commit 217a486955378f6fb1034d76de552bb6e191e325
parent 904d4ce5b7932770c6115a2cb95a3837676e34dc
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  5 Dec 2021 19:43:08 -0800

bin: rss stuff, misc

Diffstat:
Abin/base64url | 5+++++
Abin/edit-diff-line | 3+++
Abin/fedi-timeline | 12++++++++++++
Abin/findex | 19+++++++++++++++++++
Abin/findimp | 8++++++++
Abin/fuzz-rss | 3+++
Abin/html2xml | 2++
Abin/jsfmt | 2++
Abin/marks | 4++++
Abin/rssfeed | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/rssfeeds | 9+++++++++
Abin/toggle-mic-mute | 3+++
Abin/toggle-mute | 11+++++++++++
Abin/vimless | 26++++++++++++++++++++++++++
Abin/zlibrary | 7+++++++
15 files changed, 168 insertions(+), 0 deletions(-)

diff --git a/bin/base64url b/bin/base64url @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eou pipefail + +base64 -w10000 "$@" | tr '/+' '_-' | tr -d '=' diff --git a/bin/edit-diff-line b/bin/edit-diff-line @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +eval "$(fuzz-edit-diff-line "$@")" diff --git a/bin/fedi-timeline b/bin/fedi-timeline @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eou pipefail + +timeline=${1:-home} + +curl -sL -H "Authorization: Bearer $FEDI_TOKEN" "$FEDI_ENDPOINT/api/v1/timelines/$timeline" | +jq -r '.[] | [.account.username, .content] | @tsv' | +sed 's,<[^>]*>,,g' | +column -t -s $'\t' | +sed 's,$,\n,g' | +less diff --git a/bin/findex b/bin/findex @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +if [ -z "$1" ]; then + printf 'usage: find-example <rg query>\n' + exit 1 +fi + +# cd to project root +cd $(git rev-parse --show-toplevel) + +rg "$1" | +grep -E '^[^:]+:.*$' | +cut -d: -f2- | +sort | +uniq -c | +sort -nr | +sed 's,^[[:space:]]*,,g;s,\(^[[:digit:]]\+\) ,\1\t,g' | +cut -d $'\t' --output-delimiter=$'\t' -f2- | +head -n5 diff --git a/bin/findimp b/bin/findimp @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +if [ -z "$1" ]; then + printf 'usage: find-import <import-name>\n' + exit 1 +fi + +findex 'import.*'"$1" diff --git a/bin/fuzz-rss b/bin/fuzz-rss @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -eou pipefail +echo open "$(rss)" diff --git a/bin/html2xml b/bin/html2xml @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +tidy -q -asxml --numeric-entities yes 2>/dev/null diff --git a/bin/jsfmt b/bin/jsfmt @@ -0,0 +1,2 @@ +#!/bin/sh +standardx --fix - diff --git a/bin/marks b/bin/marks @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -eou pipefail +url=$(<"$1" ct | fzf | awkp 2) +open "$url" diff --git a/bin/rssfeed b/bin/rssfeed @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -eou pipefail + +if [ -z "$1" ]; then + printf "usage: rssurl <some.link/rss.xml>\n" + exit 1 +fi + +name=${2:-feed} + +jqs=$(cat <<EOF +def month_to_num: + if . == "Jan" then "01" + elif . == "Feb" then "02" + elif . == "Mar" then "03" + elif . == "Apr" then "04" + elif . == "May" then "05" + elif . == "Jun" then "06" + elif . == "Jul" then "07" + elif . == "Aug" then "08" + elif . == "Sep" then "09" + elif . == "Oct" then "10" + elif . == "Nov" then "11" + elif . == "Dec" then "12" + else "01" + end +; + +def parse_date: + (.pubDate | strings | + capture("^[a-zA-Z]{3}, (?<day>[0-9]+) (?<month>[a-zA-Z]{3}) (?<year>[0-9]+) (?<h>[0-9]+):(?<m>[0-9]+):(?<s>[0-9]+)") + | "\(.year)-\(.month | month_to_num)-\(.day)T\(.h):\(.m):\(.s)Z" + | fromdateiso8601) // + + (.published | strings | sub(".00:00$"; "Z") | fromdateiso8601) +; + +def parse_url: + . | + objects | + (.link | strings) // + (.link | objects | ."@href") // + (.enclosure | objects | ."@url") +; + +(.rss.channel.item // .feed.entry) | +.[] | +[(. | parse_date), "$name", .title, (. | parse_url)] | +@tsv +EOF +) + +curl --compressed -sL "$1" | xq -rc "$jqs" diff --git a/bin/rssfeeds b/bin/rssfeeds @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -eou pipefail + +( +while IFS=$'\t' read -r name type url +do + echo rssfeed "$url" "$name" +done < ~/dotfiles/rssfeeds +) | parallel | sort -n > ~/var/rss.tsv diff --git a/bin/toggle-mic-mute b/bin/toggle-mic-mute @@ -0,0 +1,3 @@ +#!/bin/sh + +XF86AudioMicMute diff --git a/bin/toggle-mute b/bin/toggle-mute @@ -0,0 +1,11 @@ +#!/bin/sh + +muted=$(pamixer -t --get-mute) + +if [ "$muted" = "true" ]; then + notify-send "muted" +elif [ "$muted" = "false" ]; then + notify-send "un-muted" +else + notify-send "pamixer not found" +fi diff --git a/bin/vimless b/bin/vimless @@ -0,0 +1,26 @@ +#!/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/sh +# Shell script to start Vim with less.vim. +# Read stdin if no arguments were given and stdin was redirected. + +if test -t 1; then + if test $# = 0; then + if test -t 0; then + echo "Missing filename" 1>&2 + exit + fi + nvim -u /home/jb55/dotfiles/.vim/less.vim "$@" + else + nvim -u /home/jb55/dotfiles/.vim/less.vim - + fi +else + # Output is not a terminal, cat arguments or stdin + if test $# = 0; then + if test -t 0; then + echo "Missing filename" 1>&2 + exit + fi + cat + else + cat "$@" + fi +fi diff --git a/bin/zlibrary b/bin/zlibrary @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -eou pipefail + +query="$(sed 's, ,%20,g' <<<"$1")" + +curl --compressed -sL "https://ca1lib.org/s/$query"