summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xtwerk22
1 files changed, 19 insertions, 3 deletions
diff --git a/twerk b/twerk index 8fe163e..68f59d0 100755 --- a/twerk +++ b/twerk
@@ -94,6 +94,10 @@ main() {
94 read_posts "$TWERK_FILE" 94 read_posts "$TWERK_FILE"
95} 95}
96 96
97remain() {
98 _TWERK_INITIAL=false main "$TWERK_FEEDS"
99}
100
97### Library 101### Library
98 102
99fetch_posts() { 103fetch_posts() {
@@ -155,6 +159,11 @@ sort_posts() {
155 sort -r 159 sort -r
156} 160}
157 161
162struncate() {
163 printf '%s\n' "$1" |
164 dd ibs=1 count="$2" 2>/dev/null
165}
166
158format_posts() { 167format_posts() {
159 while IFS=' ' read -r date name url post 168 while IFS=' ' read -r date name url post
160 do 169 do
@@ -167,8 +176,8 @@ format_posts() {
167 fi 176 fi
168 177
169 printf "%${TWERK_DATE_WIDTH}s | %${TWERK_USER_WIDTH}s | " \ 178 printf "%${TWERK_DATE_WIDTH}s | %${TWERK_USER_WIDTH}s | " \
170 "$(echo "$date" | head -c$TWERK_DATE_WIDTH)" \ 179 "$(struncate "$date" "$TWERK_DATE_WIDTH")" \
171 "$(echo "$name" | head -c$TWERK_USER_WIDTH)" 180 "$(struncate "$name" "$TWERK_USER_WIDTH")"
172 181
173 export url name date post TWERK_WIDTH TWERK_HANG 182 export url name date post TWERK_WIDTH TWERK_HANG
174 export linewidth="$TWERK_HANG" 183 export linewidth="$TWERK_HANG"
@@ -244,11 +253,18 @@ post() {
244 printf 'Twt: ' >&2 253 printf 'Twt: ' >&2
245 read -r post 254 read -r post
246 255
256
257 if printf '%s\n' "$post" | grep -qE '^[ \t\n]$'
258 then
259 remain
260 fi
261
247 post="$(printf '%s\t%s\n' "$(date +'%FT%T%z')" "$post")" 262 post="$(printf '%s\t%s\n' "$(date +'%FT%T%z')" "$post")"
248 263
249 eval "printf '%s\n' \"\$post\" | $TWERK_POST_COMMAND" 264 eval "printf '%s\n' \"\$post\" | $TWERK_POST_COMMAND"
250 _TWERK_INITIAL=false main "$TWERK_FEEDS"
251 rm "$TWERK_CACHE/$TWERK_USER" 265 rm "$TWERK_CACHE/$TWERK_USER"
266 remain
267}
252} 268}
253 269
254refresh() { 270refresh() {