dot

packages and services management
Log | Files | Refs | README

commit a82aef4cbc7595a04009f9ef9b07765671bffdb5
parent 028a866687c204e0a828206a2d94d678ca35fb5f
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 29 Jan 2018 19:54:52 +0100

the shorter the better

Diffstat:
Mbin/clip | 12++++++------
Mbin/io | 22+++++++++++++---------
Rbin/listree -> bin/lt | 0
Mbin/twt | 78+++++++++++++++++++++++++++++++++++++++++-------------------------------------
4 files changed, 60 insertions(+), 52 deletions(-)

diff --git a/bin/clip b/bin/clip @@ -1,17 +1,17 @@ #!/bin/sh -e -CLIP=${CLIP:-$HOME/.cache/clip} +CLIP=${CLIP:-${HOME}/.cache/clip} -touch "$CLIP" -chmod 600 "$CLIP" +touch "${CLIP}" +chmod 600 "${CLIP}" -case $1 in +case "${1}" in (-i) shift - cat "$@" > "$CLIP" + cat "${@}" > "${CLIP}" ;; (-o) - cat "$CLIP" + cat "${CLIP}" ;; (*) echo 'usage: clip -i [file...]' diff --git a/bin/io b/bin/io @@ -2,17 +2,21 @@ export LC_COLLATE=C -cache=$HOME/.cache/find/ -mkdir -p "$cache" +cache="${HOME}/.cache/find" +mkdir -p "${cache}" -case $PWD in ($HOME/*) - dir=$(printf %s "${PWD##$HOME/}" | sed 's|/.*||') - find "$HOME/$dir" '(' -name .git -o -name CVS ')' -prune -o -print | +case "${PWD}" in ("${HOME}"/*) + dir=$(printf %s "${PWD##${HOME}/}" | sed 's|/.*||') + find "${HOME}/$dir" '(' -name .git -o -name CVS ')' -prune -o -print | sort > "$cache/$dir" esac -exec xdg-open "$(find "$HOME" -maxdepth 1 -mindepth 1 | sort | - cut -c $((${#HOME} + 2))- | xargs -I {} printf '%s/%s\n' "$cache" {} | - xargs -I {} cat "$cache" {} 2> /dev/null | cat - "$HOME/etc/lib/uri" | - iomenu -# | cut -f 2- +exec xdg-open "$(find "${HOME}" -maxdepth 1 -mindepth 1 | + sort | + cut -c $((${#HOME} + 2))- | + xargs -I {} printf '%s/%s\n' "$cache" {} | + xargs -I {} cat "${cache}" {} 2> /dev/null | + cat - "${HOME}/etc/lib/uri" | + iomenu -# | + cut -f 2- )" diff --git a/bin/listree b/bin/lt diff --git a/bin/twt b/bin/twt @@ -1,12 +1,13 @@ #!/bin/sh # twtxt client in a single small POSIX shell script -NICK=josuah -FEED=$HOME/srv/twtxt.txt -CONF=$HOME/.config/twt -CACHE=$HOME/.cache/twt +NICK='josuah' +FEED="${HOME}/srv/twtxt.txt" +CONF="${HOME}/.config/twt" +CACHE="${HOME}/.cache/twt" awk_line=' + function leap(yrs) { return (yrs % 4 == 0) && (yrs % 100 != 0) || (yrs % 400 == 0); @@ -84,67 +85,70 @@ awk_show=' err() { - printf 'Error: %s\n' "$1" + printf 'Error: %s\n' "${1}" exit 1 } -mkdir -p "$CACHE" -touch "$CONF" +mkdir -p "${CACHE}" +touch "${CONF}" -case "$1" in +case "${1}" in (tweet) - [ $# -ne 2 ] && exec "$0" + [ "${#}" -ne 2 ] && exec "${0}" - msg=$(printf %s "$2" | sed 's|[^ ]*://[^ ]*|@<&>|' | tr '\n' ' ') + msg=$(printf %s "${2}" | sed 's|[^ ]*://[^ ]*|@<&>|' | tr '\n' ' ') while read -r usr url do - url=$(printf %s "$url" | sed 's/[&/\]/\\&/g') - new=$(printf %s "$usr" | sed 's/[&/\]/\\&/g') - usr=$(printf %s "$usr" | sed 's/./[&]/g') - msg=$(printf %s "$msg" | sed "s/@$usr/@<$new $url>/") - done < "$CONF" - printf '%s\t%s\n' "$(date +'%Y-%m-%dT%T%z' | sed 's/..$/:&/')" "$msg" \ - >> "$FEED" + url=$(printf %s "${url}" | sed 's/[&/\]/\\&/g') + new=$(printf %s "${usr}" | sed 's/[&/\]/\\&/g') + usr=$(printf %s "${usr}" | sed 's/./[&]/g') + msg=$(printf %s "${msg}" | sed "s/@${usr}/@<${new} ${url}>/") + done < "${CONF}" + printf '%s\t%s\n' "$(date +'%Y-%m-%dT%T%z' | sed 's/..$/:&/')" "${msg}" \ + >> "${FEED}" ;; (view) - [ $# -ne 2 ] && exec "$0" - [ -f "$CACHE/$2" ] || err "$2 feed not found, try update" + [ "${#}" -ne 2 ] && exec "${0}" + [ -f "${CACHE}/${2}" ] || err "${2} feed not found, try update" - awk "$awk_line" "$CACHE/$2" | sort -r | awk "$awk_show" | $PAGER + awk "${awk_line}" "${CACHE}/${2}" | sort -r | awk "${awk_show}" | ${PAGER} ;; (timeline) - [ $# -ne 1 ] && exec "$0" - ls "$CACHE"/* 2> /dev/null 1>&2 || err 'no feed found, try to update' + [ "${#}" -ne 1 ] && exec "${0}" + ls "${CACHE}"/* 2> /dev/null 1>&2 || err 'no feed found, try to update' - awk "$awk_line" "$CACHE"/* | sort -r | awk "$awk_show" | $PAGER + awk "${awk_line}" "${CACHE}"/* | sort -r | awk "${awk_show}" | ${PAGER} ;; (update) while read -r usr url - do curl -m 10 -#L "$url" > "$CACHE/$usr" || rm "$CACHE/$usr" & - done < "$CONF" + do + curl -m 10 -#L "${url}" > "${CACHE}/${usr}" || + rm "${CACHE}/${usr}" & + done < "${CONF}" wait ;; (follow) - [ $# -ne 3 ] && exec "$0" + [ "${#}" -ne 3 ] && exec "${0}" - sed 's/[[:space:]].*//' "$CONF" | grep -Fqx "$2" && - err "already following $2" + sed 's/[[:space:]].*//' "${CONF}" | grep -Fqx "${2}" && + err "already following ${2}" - printf '%s\t%s\n' "$2" "$3" >> "$CONF" - sort -uo "$CONF" "$CONF" + printf '%s\t%s\n' "${2}" "${3}" >> "${CONF}" + sort -uo "${CONF}" "${CONF}" ;; (unfollow) - [ $# -ne 2 ] && exec "$0" - sed 's/[[:space:]].*//' "$CONF" | grep -Fqx "$2" || - err "not following $2" + [ "${#}" -ne 2 ] && exec "${0}" + sed 's/[[:space:]].*//' "${CONF}" | grep -Fqx "${2}" || + err "not following ${2}" - sed "/^$(printf %s "$2" | sed 's/./[&]/g')[[:space:]]/ d" "$CONF" | - sort -uo "$CONF" + sed "/^$(printf %s "${2}" | sed 's/./[&]/g')[[:space:]]/ d" "${CONF}" | + sort -uo "${CONF}" ;; (following) - [ $# -ne 1 ] && exec "$0" + [ "${#}" -ne 1 ] && exec "${0}" - sed -re's/[[:space:]]/ /' -e's/(.{12}[^ ]*) */\1 @ /' "$CONF" + sed -r's/[[:space:]]/ /; s/(.{12}[^ ]*) */\1 @ /' \ + "${CONF}" ;; (*) printf 'usage: twt [tweet msg | view user | timeline | update\n'