Skip to main content

text/README.md

1# text
3These are utilities for manipulating streams of text; I consider them in a similar category to Unix staples like <code>head</code> and <code>tail</code>.
5## The individual scripts
7<!-- [[[cog
9# This adds the root of the repo to the PATH, which has cog_helpers.py
10from os.path import abspath, dirname
11import sys
13sys.path.append(abspath(dirname(dirname("."))))
15import cog_helpers
17folder_name = "text"
19scripts = [
20 {
21 "usage": "body -n [LINENO] [PATH]",
22 "description": """
23 print the nth line of a file.
24 This is meant to fill a gap between the Unix utilities `head` and `tail`.
25 """,
26 },
27 {
28 "usage": "fix_whitespace [PATH]",
29 "description": """
30 when I copy/paste text into Obsidian from th web, this cleans up some of the extraneous whitespace.
31 """,
32 },
33 {
34 "usage": "longlines [PATH]",
35 "description": "print the line numbers of the longest lines in the file."
36 },
37 {
38 "usage": "midline [PATH]",
39 "description": "print the line in the middle of a file, e.g. if the file has 5 lines, it prints line 3"
40 },
41 {
42 "usage": "natsize.py < [NUMBER]",
43 "description": "prints a numeric file size as a human-readable string, e.g. `32036032` becomes `32.0 MB`",
44 },
45 {
46 "usage": "noplaylist.py < [URL]",
47 "description": "removes the `list` query parameter from a YouTube URL; I use it with `youtube-dl`",
48 },
49 {
50 "usage": "peek < SECRET",
51 "description": "show a few characters of a secret, without printing the whole value in plain text"
52 },
53 {
54 "name": "pp_xml.sh < [TEXT]",
55 "description": """
56 alias for <code>xmllint --format - | pygmentize -l xml</code>, which pretty-prints a blob of XML with coloured syntax highlighting.
57 """,
58 },
59 {
60 "name": "r",
61 "description": """
62 an alias for `rg`, aka <a href="https://geoff.greer.fm/ag/">the Silver Searcher</a>. (Yes, I really am too lazy to type two whole characters.)
63 """,
64 },
65 {
66 "usage": "recog",
67 "description": """
68 Find all the README files under the current folder, and process them using <a href="https://nedbatchelder.com/code/cog">Cog</a>.
69 """
70 },
71 {
72 "usage": "reverse < [PATH]",
73 "description": "prints the lines of text, but in reverse order.",
74 },
75 {
76 "usage": "sumsizes.py < [PATH]",
77 "description": """
78 prints a human-readable data size for the numbers passed on stdin.
80 $ echo -e '100\\n 201287\\n 3190817' | sumsizes
81 3.4MB
83 """
84 },
85 {
86 "usage": "tally < [PATH]",
87 "description": "prints a tally of lines in the given text.",
88 },
89 {
90 "usage": "vs [PATH]",
91 "description": "open a path in Visual Studio Code",
92 },
95cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
97]]]-->
98<dl>
99 <dt>
100 <a href="https://github.com/alexwlchan/scripts/blob/main/text/body">
101 <code>body -n [LINENO] [PATH]</code>
102 </a>
103 </dt>
104 <dd>
105 print the nth line of a file.
106 This is meant to fill a gap between the Unix utilities `head` and `tail`.
107 </dd>
109 <dt>
110 <a href="https://github.com/alexwlchan/scripts/blob/main/text/fix_whitespace">
111 <code>fix_whitespace [PATH]</code>
112 </a>
113 </dt>
114 <dd>
115 when I copy/paste text into Obsidian from th web, this cleans up some of the extraneous whitespace.
116 </dd>
118 <dt>
119 <a href="https://github.com/alexwlchan/scripts/blob/main/text/longlines">
120 <code>longlines [PATH]</code>
121 </a>
122 </dt>
123 <dd>
124 print the line numbers of the longest lines in the file.
125 </dd>
127 <dt>
128 <a href="https://github.com/alexwlchan/scripts/blob/main/text/midline">
129 <code>midline [PATH]</code>
130 </a>
131 </dt>
132 <dd>
133 print the line in the middle of a file, e.g. if the file has 5 lines, it prints line 3
134 </dd>
136 <dt>
137 <a href="https://github.com/alexwlchan/scripts/blob/main/text/natsize.py">
138 <code>natsize.py < [NUMBER]</code>
139 </a>
140 </dt>
141 <dd>
142 prints a numeric file size as a human-readable string, e.g. `32036032` becomes `32.0 MB`
143 </dd>
145 <dt>
146 <a href="https://github.com/alexwlchan/scripts/blob/main/text/noplaylist.py">
147 <code>noplaylist.py < [URL]</code>
148 </a>
149 </dt>
150 <dd>
151 removes the `list` query parameter from a YouTube URL; I use it with `youtube-dl`
152 </dd>
154 <dt>
155 <a href="https://github.com/alexwlchan/scripts/blob/main/text/peek">
156 <code>peek < SECRET</code>
157 </a>
158 </dt>
159 <dd>
160 show a few characters of a secret, without printing the whole value in plain text
161 </dd>
163 <dt>
164 <a href="https://github.com/alexwlchan/scripts/blob/main/text/pp_xml.sh">
165 <code>pp_xml.sh < [TEXT]</code>
166 </a>
167 </dt>
168 <dd>
169 alias for <code>xmllint --format - | pygmentize -l xml</code>, which pretty-prints a blob of XML with coloured syntax highlighting.
170 </dd>
172 <dt>
173 <a href="https://github.com/alexwlchan/scripts/blob/main/text/r">
174 <code>r</code>
175 </a>
176 </dt>
177 <dd>
178 an alias for `rg`, aka <a href="https://geoff.greer.fm/ag/">the Silver Searcher</a>. (Yes, I really am too lazy to type two whole characters.)
179 </dd>
181 <dt>
182 <a href="https://github.com/alexwlchan/scripts/blob/main/text/recog">
183 <code>recog</code>
184 </a>
185 </dt>
186 <dd>
187 Find all the README files under the current folder, and process them using <a href="https://nedbatchelder.com/code/cog">Cog</a>.
188 </dd>
190 <dt>
191 <a href="https://github.com/alexwlchan/scripts/blob/main/text/reverse">
192 <code>reverse < [PATH]</code>
193 </a>
194 </dt>
195 <dd>
196 prints the lines of text, but in reverse order.
197 </dd>
199 <dt>
200 <a href="https://github.com/alexwlchan/scripts/blob/main/text/sumsizes.py">
201 <code>sumsizes.py < [PATH]</code>
202 </a>
203 </dt>
204 <dd>
205 prints a human-readable data size for the numbers passed on stdin.
207 $ echo -e '100\n 201287\n 3190817' | sumsizes
208 3.4MB
209 </dd>
211 <dt>
212 <a href="https://github.com/alexwlchan/scripts/blob/main/text/tally">
213 <code>tally < [PATH]</code>
214 </a>
215 </dt>
216 <dd>
217 prints a tally of lines in the given text.
218 </dd>
220 <dt>
221 <a href="https://github.com/alexwlchan/scripts/blob/main/text/vs">
222 <code>vs [PATH]</code>
223 </a>
224 </dt>
225 <dd>
226 open a path in Visual Studio Code
227 </dd>
228</dl>
229<!-- [[[end]]] (sum: YMjzg7VZH5) -->