diff options
author | Case Duckworth | 2023-03-05 23:25:37 -0600 |
---|---|---|
committer | Case Duckworth | 2023-03-05 23:25:37 -0600 |
commit | aaa3c23a80b01e443c7715c87ef13bda7784e3b1 (patch) | |
tree | ee8a03bf613d2f2fe6b46a207427e49d6f02c247 | |
parent | Add user option (diff) | |
download | twerk-aaa3c23a80b01e443c7715c87ef13bda7784e3b1.tar.gz twerk-aaa3c23a80b01e443c7715c87ef13bda7784e3b1.zip |
Add functions
-rwxr-xr-x | twerk | 22 |
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 | ||
97 | remain() { | ||
98 | _TWERK_INITIAL=false main "$TWERK_FEEDS" | ||
99 | } | ||
100 | |||
97 | ### Library | 101 | ### Library |
98 | 102 | ||
99 | fetch_posts() { | 103 | fetch_posts() { |
@@ -155,6 +159,11 @@ sort_posts() { | |||
155 | sort -r | 159 | sort -r |
156 | } | 160 | } |
157 | 161 | ||
162 | struncate() { | ||
163 | printf '%s\n' "$1" | | ||
164 | dd ibs=1 count="$2" 2>/dev/null | ||
165 | } | ||
166 | |||
158 | format_posts() { | 167 | format_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 | ||
254 | refresh() { | 270 | refresh() { |