diff options
author | Case Duckworth | 2023-03-05 10:58:43 -0600 |
---|---|---|
committer | Case Duckworth | 2023-03-05 10:58:43 -0600 |
commit | e5ff7adaf1a2e5b3d9abd971fa8b48cc6d80465c (patch) | |
tree | a16d3b8d34431d800653563d9c34d8a6fc1d35c3 | |
parent | Initial commit (diff) | |
download | twerk-e5ff7adaf1a2e5b3d9abd971fa8b48cc6d80465c.tar.gz twerk-e5ff7adaf1a2e5b3d9abd971fa8b48cc6d80465c.zip |
Delete twerk.first
-rwxr-xr-x | twerk.first | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/twerk.first b/twerk.first deleted file mode 100755 index 9b43e3e..0000000 --- a/twerk.first +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | ## twerk: a twtxt client in sh | ||
3 | # by Case Duckworth | ||
4 | |||
5 | ### Entry point | ||
6 | |||
7 | usage() { | ||
8 | cat >&2 <<EOF | ||
9 | TWERK: a twtxt client | ||
10 | usage: twerk [options] [file] | ||
11 | |||
12 | options: | ||
13 | -h show this help and quit | ||
14 | -t include time in post date | ||
15 | -T don't include time in post date (default) | ||
16 | -n NUMBER limit posts to NUMBER (100) | ||
17 | -w WIDTH limit the width of the display (72) | ||
18 | -H WIDTH define the hanging indent of twts | ||
19 | -u WIDTH limit the width of the user display (12) | ||
20 | EOF | ||
21 | exit "${1:-0}" | ||
22 | } | ||
23 | |||
24 | configure() { | ||
25 | TWERK_INCLUDE_TIME=0 | ||
26 | TWERK_WIDTH="${COLUMNS:-72}" | ||
27 | TWERK_USER_WIDTH=12 | ||
28 | while getopts hn:w:H:t opt; do | ||
29 | case "$opt" in | ||
30 | h) usage ;; | ||
31 | n) TWERK_N="$OPTARG" ;; | ||
32 | w) TWERK_WIDTH="$OPTARG" ;; | ||
33 | H) TWERK_HANG="$OPTARG" ;; | ||
34 | u) TWERK_USER_WIDTH="$OPTARG" ;; | ||
35 | t) TWERK_INCLUDE_TIME=1 ;; | ||
36 | T) TWERK_INCLUDE_TIME=0 ;; | ||
37 | *) usage 1 ;; | ||
38 | esac | ||
39 | done | ||
40 | if test -z "$TWERK_HANG"; then | ||
41 | TWERK_HANG=$((TWERK_USER_WIDTH+(TWERK_INCLUDE_TIME*6)+10+3)) | ||
42 | fi | ||
43 | |||
44 | } | ||
45 | |||
46 | main() { | ||
47 | configure "$@"; shift "$((OPTIND - 1))" | ||
48 | cat "${@:--}" | | ||
49 | curl_from_file | ||
50 | } | ||
51 | |||
52 | ### Library | ||
53 | |||
54 | curl_from_file() { | ||
55 | while read -r url name; do | ||
56 | curl -sf "$url" | | ||
57 | filter_posts | | ||
58 | awk -v url="$url" -v name="$name" \ | ||
59 | '{ printf "%s\t%s\t%s\n", name, url, $0; }' | ||
60 | done | | ||
61 | sort_posts | | ||
62 | format_posts | ||
63 | } | ||
64 | |||
65 | filter_posts() { | ||
66 | filter_comments | limit_posts "${TWERK_N:-100}" | ||
67 | } | ||
68 | |||
69 | filter_comments() { | ||
70 | awk '/^[ \t]*#/{next;}/^$/{next;}{print;}' | ||
71 | } | ||
72 | |||
73 | limit_posts() { | ||
74 | head -n "$1" | ||
75 | } | ||
76 | |||
77 | |||
78 | sort_posts() { | ||
79 | sort -r | ||
80 | } | ||
81 | |||
82 | format_posts() { | ||
83 | awk \ | ||
84 | -v UW="$TWERK_USER_WIDTH" \ | ||
85 | -v IT="$TWERK_INCLUDE_TIME" \ | ||
86 | -v WIDTH="$TWERK_WIDTH" \ | ||
87 | -v HANG="$TWERK_HANG" \ | ||
88 | 'BEGIN {FS="\t";} | ||
89 | !IT { sub(/T.*$/, "", $3); } | ||
90 | IT { | ||
91 | sub(/+.*$/, "", $3); | ||
92 | sub(/T/, " ", $3); | ||
93 | sub(/:..$/,"",$3); | ||
94 | } | ||
95 | |||
96 | { printf("%s | %" UW "s | ", $3, substr($1,1,UW-1)); } | ||
97 | |||
98 | # wrap lines | ||
99 | { | ||
100 | w = HANG # width | ||
101 | ls = 0 # lines | ||
102 | split($2, words, /[ \t]/) | ||
103 | for (i=1; i<=length(words); i++) { | ||
104 | if (w+length(words[i]) >= WIDTH) { | ||
105 | print "" | ||
106 | w = 0 | ||
107 | if (++ls) { | ||
108 | printf "%" HANG "s ` ", "" | ||
109 | w += HANG + 2 | ||
110 | } | ||
111 | } | ||
112 | printf "%s ", words[i] | ||
113 | w += length(words[i]) | ||
114 | } | ||
115 | print "" | ||
116 | } | ||
117 | ' | ||
118 | } | ||
119 | |||
120 | ### | ||
121 | test -z "$DEBUG" || set -x | ||
122 | test -z "$SOURCE" && main "$@" | ||