dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 1e0c90366c3aae36d491eb82928c4d9011a758ec
parent 0f0a319a4f2917eb4378748683e58a86e9412ff1
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Tue, 25 Feb 2020 18:51:44 +0100

Support gopher upload

Diffstat:
M.local/bin/plumb | 18+++++++++++-------
M.local/bin/upload | 43+++++++++++++++++++++++++++++++++++++++++--
2 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/.local/bin/plumb b/.local/bin/plumb @@ -35,6 +35,10 @@ regexmatch() { printf '%s' "$1" | grep -E -q "$2" } +regeximatch() { + printf '%s' "$1" | grep -i -E -q "$2" +} + fetch() { _o="$(mktemp)" if type -v hurl >/dev/null 2>&1; then @@ -86,21 +90,21 @@ handle_target() { t="$(printf '%s' "$t" | sed 's/.*scholar_url?url\=//;s/&hl\=.*//')";; esac - if regexmatch "$t" '\.(mp4|mkv|webm|ogv|avi|ogg|ogv|gifv)$'; then + if regeximatch "$t" '\.(mp4|mkv|webm|avi|ogg|ogv|gifv)$'; then detach mpv "$t" - elif regexmatch "$t" '\.(png|jpg|jpeg|tif|bmp|gif)$'; then + elif regeximatch "$t" '\.(png|jpg|jpeg|tif|bmp|gif)$'; then sxiv "$(fetch "$t")" - elif regexmatch "$t" '\.(pdf|ps|epub|djvu)$'; then + elif regeximatch "$t" '\.(pdf|ps|epub|djvu)$'; then zathura "$(fetch "$t")" - elif regexmatch "$t" '(youtube\.|youtu\.be|vimeo\.com)'; then + elif regeximatch "$t" '(youtube\.|youtu\.be|vimeo\.com)'; then cd ~/tmp && detach youtube-dl "$t" - elif regexmatch "$t" '(smbc-comics\.com|xkcd\.com|jspowerhour\.com)'; then + 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" '^gopher://'; then + elif regeximatch "$t" '^gopher://'; then detach $TERMINAL sacc "$t" - elif regexmatch "$t" '^(http|https)://'; then + elif regeximatch "$t" '^(http|https)://'; then detach $BROWSER "$t" else die "unknown target type: $t" diff --git a/.local/bin/upload b/.local/bin/upload @@ -6,7 +6,11 @@ version=1.0 # Upload target host="adamsgaard.dk" user="ad" -remotedir="/var/www/domains/adamsgaard.dk/npub" +pubdir="pub" +nonpubdir="npub" +remote="/var/www/domains/adamsgaard.dk" +dir="${nonpubdir}" +remotedir="${remote}/${dir}" show_help() { echo "usage: ${0##*/} [OPTIONS] FILE1 [FILE2...[FILE N]]" @@ -25,6 +29,8 @@ show_help() { echo " -r, --resize if an image, resize FILES to fit 800x800 pixels" echo " without changing its width-to-height ratio" echo " -s, --sharpen if an image, sharpen all FILES" + echo " -p, --public operate on public file directory (/${pubdir})" + echo " -o, --gopher return gopher URI instead of http" echo " -g, --get get previously uploaded FILES instead of uploading" echo " -l, --list list previously uploaded files" echo " -d, --delete delete previously uploaded FILES instead of uploading" @@ -40,6 +46,14 @@ show_version() { echo "https://src.adamsgaard.dk/dotfiles" } +regexmatch() { + printf '%s' "$1" | grep -E -q "$2" +} + +regeximatch() { + printf '%s' "$1" | grep -i -E -q "$2" +} + check_if_image() { if [ -f "$1" ]; then identify "$1" >/dev/null 2>&1 || die "error: $1 is not an image" @@ -90,7 +104,18 @@ upload_file() { fi rsync -rz $progress --chmod=Fu=rw,Fog=r -e "ssh" "$infile" \ "${user}@${host}:${remotedir}/'$newbasename'" - url="https://$host/npub/${newbasename}" + if [ "$gopher" = 1 ]; then + if regeximatch "${basename}" '\.(png|jpg|jpeg|tif|bmp)$'; then + type=I + elif regeximatch "${basename}" '\.(pdf|ps|epub|mp4|mkv|webm|ogv|avi|ogg|gifv)$'; then + type=9 + else + type=0 + fi + url="gopher://${host}/${type}/${dir}/${newbasename}" + else + url="https://${host}/${dir}/${newbasename}" + fi if [ "$verbose" = 1 ]; then echo msg="Uploaded to $url (copied to clipboard)" @@ -132,9 +157,11 @@ notify=0 border=0 resize=0 sharpen=0 +public=0 get=0 delete=0 verbose=0 +gopher=0 while :; do case "$1" in -h|-\?|--help) @@ -160,6 +187,14 @@ while :; do -s|--sharpen) sharpen=1 ;; + -p|--public) + public=1 + dir="${pubdir}" + remotedir="${remote}/${dir}" + ;; + -o|--gopher) + gopher=1 + ;; -g|--get) get=1 ;; @@ -188,6 +223,10 @@ if [ $# -lt 1 ]; then exit 1 fi +if [ "$gopher" = 1 ] && [ "$public" = 0 ]; then + die "gopher (-o) requires public destination (-p)" +fi + if [ "$get" = 1 ] || [ "$delete" = 1 ]; then if [ "$get" = 1 ]; then for f in "$@"; do