dot

packages and services management
Log | Files | Refs | README

commit a720c7cf516bde281f9bdaee92626e4991080825
parent ec71e321942d43f6ed5f0661bd6f634ec5efccd2
Author: Josuah Demangeon <mail@josuah.net>
Date:   Tue, 13 Mar 2018 10:18:51 +0100

converted twt to mostly use awk

Diffstat:
Magenda/main | 7+++++++
Abin/.twt.swp | 0
Abin/io-agenda | 5+++++
Mbin/twt | 113+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
Mbin/xdg-open | 30++++++++++--------------------
Mpack/st/build | 6+++---
Mtwt | 2+-
7 files changed, 96 insertions(+), 67 deletions(-)

diff --git a/agenda/main b/agenda/main @@ -71,3 +71,10 @@ C:eat L:http://www.tavernedelamarine.com D:Bring all information regarding availability : +B:1521932400 +E:1521932400 +S:JNG birthday +C:family +L:St Marcel +D:Rapporter le répétiteur +: diff --git a/bin/.twt.swp b/bin/.twt.swp Binary files differ. diff --git a/bin/io-agenda b/bin/io-agenda @@ -0,0 +1,5 @@ +#!/bin/sh -e + +a="$(agenda | iomenu | cut -d ' ' -f 4-)" + +[ "$a" ] && $EDITOR "$a" diff --git a/bin/twt b/bin/twt @@ -2,9 +2,11 @@ # twtxt client in a single small POSIX shell script NICK='josuah' -TWT="$HOME/srv/twtxt.txt" +TWT_FEED="${TWT_FEED-$HOME/.config/twtxt.txt}" +TWT_CONF="${TWT_CONF-$HOME/.config/twt}" +TWT_PATH="${TWT_PATH-$HOME/.cache/twt}" -awk_line=' +show=' function leap(yrs) { @@ -43,6 +45,35 @@ function to_date(fmt, sec) return sprintf(fmt, yrs, mth, day, hrs, min, sec); } +function swap(array, a, b) +{ + tmp = array[a]; + array[a] = array[b]; + array[b] = tmp; +} + +function sort(array, beg, end) +{ + if (beg >= end) # end recursion + return; + + a = beg + 1; # #1 is the pivot + b = end; + while (a < b) { + while (a < b && array[a] <= array[beg]) # beg: skip lesser + a++; + while (a < b && array[b] > array[beg]) # end: skip greater + b--; + swap(array, a, b); # found 2 misplaced + } + + if (array[beg] > array[a]) # put the pivot back + swap(array, beg, a); + + sort(array, beg, a - 1); # sort lower half + sort(array, a, end); # sort higher half +} + function rfc3339(str) { yrs = substr(str, 1, 4); mth = substr(str, 6, 2); @@ -56,29 +87,32 @@ function rfc3339(str) { } BEGIN { - "date +%z" | getline local; - sub("..$", "", local); + "date +%z" | getline OFF; + sub("..$", "", OFF); } -/^20/ { - sec = rfc3339($1) + local * 3600; +/^[0-9]{4}/ { + sec = rfc3339($1) + OFF * 3600; sub("[^\t]*\t", "", $0); + gsub("\t", " ", $0); sub(".*/", "", FILENAME); - printf("%s", to_date("%04d/%02d/%02d %02d:%02d:%02d", sec)); - printf(" %s %s\n", FILENAME, $0); -}' + lines[++nb] = sprintf("%s\t%s\t%s", sec, FILENAME, $0); +} -awk_show=' -{ - printf("%-60s %s %s\n", $3, $1, $2); - sub("[^ ]+ [^ ]+ [^ ]+ +", "", $0); - for (text = $0; length(text) > 74; sub(" *", "", text)) { - line = substr(text, 1, 74); - sub(" +[^ ]*$", "", line); - text = substr(text, length(line) + 1); - printf(" %s\n", line); +END { + sort(lines, 1, nb); + for (i = 1; i < nb; i++) { + split(lines[i], twt, "\t"); + printf("%-60s %s\n", twt[2], + to_date("%04d/%02d/%02d %02d:%02d:%02d", twt[1])); + for (text = twt[3]; length(text) > 74; sub(" *", "", text)) { + line = substr(text, 1, 74); + sub(" +[^ ]*$", "", line); + text = substr(text, length(line) + 1); + printf(" %s\n", line); + } + printf(" %s\n\n", text); } - printf(" %s\n\n", text); }' err() @@ -87,8 +121,8 @@ err() exit 1 } -mkdir -p "$HOME/.cache/twt" -touch "$HOME/.config/twt" +mkdir -p "$TWT_PATH" "$(dirname "$TWT_CONF")" +touch "$TWT_CONF" case "$1" in (tweet) @@ -101,57 +135,50 @@ case "$1" in new=$(printf %s "$usr" | sed 's/[&/\]/\\&/g') usr=$(printf %s "$usr" | sed 's/./[&]/g') msg=$(printf %s "$msg" | sed "s/@$usr/@<$new $url>/") - done < "$HOME/.config/twt" + done < "$TWT_CONF" printf '%s\t%s\n' "$(date +'%Y-%m-%dT%T%z' | sed 's/..$/:&/')" "$msg" \ - >> "$TWT" + >> "$TWT_FEED" ;; (view) [ "$#" -ne 2 ] && exec "$0" - [ -f "$HOME/.cache/twt/$2" ] || - err "$2 feed not found, try update" + [ -f "$TWT_PATH/$2" ] || err "$2 feed not found, try update" - awk "$awk_line" "$HOME/.cache/twt/$2" | sort -r | - awk "$awk_show" | $PAGER + awk "$show" "$TWT_PATH/$2" ;; (timeline) [ "$#" -ne 1 ] && exec "$0" - ls "$HOME/.cache/twt"/* 2> /dev/null 1>&2 || - err 'no feed found, try to update' + ls "$TWT_PATH"/* 2> /dev/null 1>&2 || err 'no feed found, twt update' - awk "$awk_line" "$HOME/.cache/twt"/* | sort -r | - awk "$awk_show" | $PAGER + awk "$show" "$TWT_PATH"/* ;; (update) while read -r usr url do - curl -m 10 -#L "$url" > "$HOME/.cache/twt/$usr" || - rm "$HOME/.cache/twt/$usr" & - done < "$HOME/.config/twt" + curl -sLm 10 "$url" > "$TWT_PATH/$usr" || rm "$TWT_PATH/$usr" & + done < "$TWT_CONF" wait ;; (follow) [ "$#" -ne 3 ] && exec "$0" - sed 's/[[:space:]].*//' "$HOME/.config/twt" | grep -Fqx "$2" && + sed 's/[[:space:]].*//' "$TWT_CONF" | grep -Fqx "$2" && err "already following $2" - printf '%s\t%s\n' "$2" "$3" >> "$HOME/.config/twt" - sort -uo "$HOME/.config/twt" "$HOME/.config/twt" + printf '%s\t%s\n' "$2" "$3" >> "$TWT_CONF" + sort -uo "$TWT_CONF" "$TWT_CONF" ;; (unfollow) [ "$#" -ne 2 ] && exec "$0" - sed 's/[[:space:]].*//' "$HOME/.config/twt" | grep -Fqx "$2" || + sed 's/[[:space:]].*//' "$TWT_CONF" | grep -Fqx "$2" || err "not following $2" - sed "/^$(printf %s "$2" | sed 's/./[&]/g')[[:space:]]/ d" \ - "$HOME/.config/twt" | - sort -uo "$HOME/.config/twt" + sed "/^$(printf %s "$2" | sed 's/./[&]/g')[[:space:]]/ d" "$TWT_CONF" | + sort -uo "$TWT_CONF" ;; (following) [ "$#" -ne 1 ] && exec "$0" - sed -r 's/[[:space:]]/ /; s/(.{12}[^ ]*) */\1 @ /' \ - "$HOME/.config/twt" + sed -r 's/[[:space:]]/ /; s/(.{11}[^ ]*) */\1 @ /' "$TWT_CONF" ;; (*) printf 'usage: twt [tweet msg | view user | timeline | update\n' diff --git a/bin/xdg-open b/bin/xdg-open @@ -2,6 +2,11 @@ # override the xdg-open utility +[ "$DISPLAY" ] && case "$(tty)" in +(/dev/pts/*) ;; +(*) st -f terminus:pixelsize=16 -e "$0" "$@" ;; +esac + [ -h "$1" ] && set -- "$(readlink -f "$1")" [ -e "$1" ] && set -- "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" [ -d "$1" ] && set -- "$(cd "$1"; pwd)" @@ -154,7 +159,7 @@ case "$1" in curl -o "$file" "$1" exec "$0" "$file" else - exec firefox "$1" + exec chromium "$1" fi ;; esac @@ -168,7 +173,7 @@ case "$1" in printf '/j #%s\n' "$path" > "$HOME/var/irc/$host/in" ;; (news://*) - exec firefox "$1" + exec chromium "$1" ;; (sftp://*) [ "$port" = . ] && port='22' @@ -185,7 +190,7 @@ case "$1" in exec printf 'unsupported protocol\n' 1>&2 ;; (r/*) - exec firefox "http://reddit.com/$1" + exec chromium "http://reddit.com/$1" ;; (*\([0-9]\)|*\([0-9]p\)) exec man "${1%(*}" @@ -208,22 +213,7 @@ case "$1" in (*.gif) exec mplayer -loop 0 "$1" ;; -(*.opus) - exec opusdec "$1" - ;; -(*.mp3) - exec mpg123 "$1" - ;; -(*.flac) - flac -cd "$1" | $play - ;; -(*.ogg|*.vorbis) - oggdec -e 1 -o - "$1" | $play - ;; -(*.wav) - exec $play < "$1" - ;; -(*.webm|*.mp4|*.mkv|*.ogv|*.avi) +(*.opus|*.mp3|*.flac|*.ogg|*.vorbis|*.wav|*.webm|*.mp4|*.mkv|*.ogv|*.avi) exec ffplay "$1" ;; (*/music/*) @@ -239,7 +229,7 @@ case "$1" in exec radare2 "$1" ;; (*.html) - exec firefox "$1" + exec chromium "$1" ;; (*.tgz) mv "$1" "${1%.tgz}.tar.gz" diff --git a/pack/st/build b/pack/st/build @@ -2,8 +2,8 @@ THEME='helios_dark' -cp "$PKG/config.h" config.h -cp "$PKG/config.mk" config.mk -cp "$PKG/$THEME.h" colors.h +cp "$PACK/st/config.h" config.h +cp "$PACK/st/config.mk" config.mk +cp "$PACK/st/$THEME.h" colors.h make PREFIX="$OPT" install diff --git a/twt b/twt @@ -61,7 +61,7 @@ joachim https://joachimrobert.keybase.pub/twtxt.txt joachimesque http://twtxt.xyz/u/joachimesque.txt joel http://joeldueck.com/twtxt.txt jomo https://gist.githubusercontent.com/jomo/64d6bd1b95ec0a24612b/raw/twtxt.txt -josuah http://josuah.net/twtxt.txt +josuah http://josuah.net/0/twtxt.txt kas https://enotty.dk/twtxt.txt kasdk https://enotty.dk/kasdk.txt kdave https://kdave.github.io/twtxt.txt