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
9# This adds the root of the repo to the PATH, which has cog_helpers.py
10from os.path import abspath, dirname
13sys.path.append(abspath(dirname(dirname("."))))
21 "usage": "body -n [LINENO] [PATH]",
23 print the nth line of a file.
24 This is meant to fill a gap between the Unix utilities
`head` and
`tail`.
28 "usage": "fix_whitespace [PATH]",
30 when I copy/paste text into Obsidian from th web, this cleans up some of the extraneous whitespace.
34 "usage": "longlines [PATH]",
35 "description": "print the line numbers of the longest lines in the file."
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"
42 "usage": "natsize.py < [NUMBER]",
43 "description": "prints a numeric file size as a human-readable string, e.g.
`32036032` becomes
`32.0 MB`",
46 "usage": "noplaylist.py < [URL]",
47 "description": "removes the
`list` query parameter from a YouTube URL; I use it with
`youtube-dl`",
50 "usage": "peek < SECRET",
51 "description": "show a few characters of a secret, without printing the whole value in plain text"
54 "name": "pp_xml.sh < [TEXT]",
56 alias for <code>xmllint --format - | pygmentize -l xml</code>, which pretty-prints a blob of XML with coloured syntax highlighting.
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.)
68 Find all the README files under the current folder, and process them using <a href="https://nedbatchelder.com/code/cog">Cog</a>.
72 "usage": "reverse < [PATH]",
73 "description": "prints the lines of text, but in reverse order.",
76 "usage": "sumsizes.py < [PATH]",
78 prints a human-readable data size for the numbers passed on stdin.
80 $ echo -e '100\\n 201287\\n 3190817' | sumsizes
86 "usage": "tally < [PATH]",
87 "description": "prints a tally of lines in the given text.",
91 "description": "open a path in Visual Studio Code",
95cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
100 <a href="https://github.com/alexwlchan/scripts/blob/main/text/body">
101 <code>body -n [LINENO] [PATH]</code>
105 print the nth line of a file.
106 This is meant to fill a gap between the Unix utilities
`head` and
`tail`.
110 <a href="https://github.com/alexwlchan/scripts/blob/main/text/fix_whitespace">
111 <code>fix_whitespace [PATH]</code>
115 when I copy/paste text into Obsidian from th web, this cleans up some of the extraneous whitespace.
119 <a href="https://github.com/alexwlchan/scripts/blob/main/text/longlines">
120 <code>longlines [PATH]</code>
124 print the line numbers of the longest lines in the file.
128 <a href="https://github.com/alexwlchan/scripts/blob/main/text/midline">
129 <code>midline [PATH]</code>
133 print the line in the middle of a file, e.g. if the file has 5 lines, it prints line 3
137 <a href="https://github.com/alexwlchan/scripts/blob/main/text/natsize.py">
138 <code>natsize.py < [NUMBER]</code>
142 prints a numeric file size as a human-readable string, e.g.
`32036032` becomes
`32.0 MB`
146 <a href="https://github.com/alexwlchan/scripts/blob/main/text/noplaylist.py">
147 <code>noplaylist.py < [URL]</code>
151 removes the
`list` query parameter from a YouTube URL; I use it with
`youtube-dl`
155 <a href="https://github.com/alexwlchan/scripts/blob/main/text/peek">
156 <code>peek < SECRET</code>
160 show a few characters of a secret, without printing the whole value in plain text
164 <a href="https://github.com/alexwlchan/scripts/blob/main/text/pp_xml.sh">
165 <code>pp_xml.sh < [TEXT]</code>
169 alias for <code>xmllint --format - | pygmentize -l xml</code>, which pretty-prints a blob of XML with coloured syntax highlighting.
173 <a href="https://github.com/alexwlchan/scripts/blob/main/text/r">
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.)
182 <a href="https://github.com/alexwlchan/scripts/blob/main/text/recog">
187 Find all the README files under the current folder, and process them using <a href="https://nedbatchelder.com/code/cog">Cog</a>.
191 <a href="https://github.com/alexwlchan/scripts/blob/main/text/reverse">
192 <code>reverse < [PATH]</code>
196 prints the lines of text, but in reverse order.
200 <a href="https://github.com/alexwlchan/scripts/blob/main/text/sumsizes.py">
201 <code>sumsizes.py < [PATH]</code>
205 prints a human-readable data size for the numbers passed on stdin.
207 $ echo -e '100\n 201287\n 3190817' | sumsizes
212 <a href="https://github.com/alexwlchan/scripts/blob/main/text/tally">
213 <code>tally < [PATH]</code>
217 prints a tally of lines in the given text.
221 <a href="https://github.com/alexwlchan/scripts/blob/main/text/vs">
222 <code>vs [PATH]</code>
226 open a path in Visual Studio Code
229<!-- [[[end]]] (sum: YMjzg7VZH5) -->