From bc7347633dd4f9f9337c77c27a83bbd7a73fb181 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 5 Mar 2023 23:25:54 -0600 Subject: Handle @ in composing twts --- twerk | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/twerk b/twerk index 8c9f65d..2cafd18 100755 --- a/twerk +++ b/twerk @@ -252,6 +252,7 @@ post() { printf 'Twt: ' >&2 read -r post + post="$(post_expand_ats "$post")" if printf '%s\n' "$post" | grep -qE '^[ \t\n]$' then @@ -264,6 +265,43 @@ post() { rm "$TWERK_CACHE/$TWERK_USER" remain } + +post_expand_ats() { + TWERK_POST="$TWERK_CACHE/:post:" + printf '%s\n' "$@" | + tr ' ' '\n' | + while read -r word; do + case "$word" in + @*) + url="$(grep "${word#@}" "$TWERK_FEEDS" | cut -d' ' -f1)" + if test -n "$url" + then + printf '@<%s %s> ' \ + "${word#@}" "$url" + else + printf '%s ' "$word" + fi + ;; + *) printf '%s ' "$word";; + esac + done > "$TWERK_POST" + echo >> "$TWERK_POST" + + if grep -q @ "$TWERK_POST" + then + cat "$TWERK_POST" >&2 + printf '%s\n' "Correct? [Y/n] " >&2 + read -r yn + case "$yn" in + n*|N*) + head -n1 "$TWERK_POST" >&2 + post + ;; + y*|Y*|'') ;; + *) return 3 ;; + esac + fi + head -n1 "$TWERK_POST" } refresh() { -- cgit 1.4.1-21-gabe81