From 88bfcada3abb36cb8fa433535cdef9e3f41a1132 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 18 Nov 2023 23:47:15 +0100 Subject: Add a new blog post complaining about other people --- src/blog/extend/cleanup.sed.gsp | 6 + src/blog/extend/compose.sh.gsp | 3 + src/blog/extend/dmenu.sh.gsp | 1 + src/blog/extend/download.sh.gsp | 1 + src/blog/extend/index.gsp | 312 ++++++++++++++++++++++++++++++++++++++++ src/blog/extend/ls-1.sh.gsp | 6 + src/blog/extend/ls-2.sh.gsp | 2 + src/blog/extend/ls-3.sh.gsp | 6 + src/blog/extend/program.sh.gsp | 4 + src/blog/extend/unicode.jpg | Bin 0 -> 31647 bytes src/blog/extend/unicode.txt.gsp | 10 ++ src/blog/index.gsp | 1 + src/style.css | 5 + 13 files changed, 357 insertions(+) create mode 100644 src/blog/extend/cleanup.sed.gsp create mode 100644 src/blog/extend/compose.sh.gsp create mode 100644 src/blog/extend/dmenu.sh.gsp create mode 100644 src/blog/extend/download.sh.gsp create mode 100644 src/blog/extend/index.gsp create mode 100644 src/blog/extend/ls-1.sh.gsp create mode 100644 src/blog/extend/ls-2.sh.gsp create mode 100644 src/blog/extend/ls-3.sh.gsp create mode 100644 src/blog/extend/program.sh.gsp create mode 100644 src/blog/extend/unicode.jpg create mode 100644 src/blog/extend/unicode.txt.gsp diff --git a/src/blog/extend/cleanup.sed.gsp b/src/blog/extend/cleanup.sed.gsp new file mode 100644 index 0000000..7ec8721 --- /dev/null +++ b/src/blog/extend/cleanup.sed.gsp @@ -0,0 +1,6 @@ +@span .fn {-s}@span .op {-/}@span .str {-;[^;]*}@span .op {-/}@span .op {-/}@span .str {-2g} +@span .fn {-s}@span .op {-/}​@span .str {-\\<(.)([A-Z]*)}@span .op {-/}​@span .str {-\\1\\L\\2}@span .op {-/}@span .str {-2g} +@span .op {-/}@span .str {-^[^;]*;<}​@span .op {-/}@span .fn {-d} +@span .op {-/}@span .str {-Compatibility}@span .op {-/}@span .fn {-d} +@span .op {-/}@span .str {-Variation Selector}@span .op {-/}@span .fn {-d} +@span .fn {-s}@span .op {-/}@span .str {-[^;]*}@span .op {-/}​@span .str {-\\\\\\\\u&}@span .op {-/} diff --git a/src/blog/extend/compose.sh.gsp b/src/blog/extend/compose.sh.gsp new file mode 100644 index 0000000..c084b5c --- /dev/null +++ b/src/blog/extend/compose.sh.gsp @@ -0,0 +1,3 @@ +@span .fn {-yq} -0 @span .str {-'.mangoes.[].quote.content'} @span .op {-<}quotes.yml @span .op {-\\} +@span .op {-|} @span .fn {-shuf} -zn1 @span .op {-\\} +@span .op {-|} @span .fn {-tr} @span .str {-'\\0'} @span .str {-'\\n'} diff --git a/src/blog/extend/dmenu.sh.gsp b/src/blog/extend/dmenu.sh.gsp new file mode 100644 index 0000000..2993357 --- /dev/null +++ b/src/blog/extend/dmenu.sh.gsp @@ -0,0 +1 @@ +name@span .op {-=}@span .str {-"}@span .op {-$(}@span .fn {-cut} -d@span .str {-';'} -f2 UnicodeData.txt @span .op {-|} @span .fn {-dmenu}@span .op {-)}@span .str {-"} diff --git a/src/blog/extend/download.sh.gsp b/src/blog/extend/download.sh.gsp new file mode 100644 index 0000000..367fdfd --- /dev/null +++ b/src/blog/extend/download.sh.gsp @@ -0,0 +1 @@ +@span .fn {-wget} @span .str {-'https://www.unicode.org/Public/UNIDATA/UnicodeData.txt'} diff --git a/src/blog/extend/index.gsp b/src/blog/extend/index.gsp new file mode 100644 index 0000000..ce2b5fd --- /dev/null +++ b/src/blog/extend/index.gsp @@ -0,0 +1,312 @@ +html lang="en" { + head { m4_include(head.gsp) } + body { + header { + div { + h1 {-Dmenu is a Godsend} + m4_include(nav.gsp) + } + + figure .quote { + blockquote { + p {= + Because dwm is customized through editing its source code, it’s + pointless to make binary packages of it. This keeps its userbase + small and elitist. No novices asking stupid questions. + } + } + figcaption {-https://dwm.suckless.org} + } + } + + main { + h2 #simple {-Simple Software} + p {- + In a @a href="/blog/gsp" {-previous article} I talked a bit about + software simplicity, or perhaps maybe the lack of it that exists in the + world. One of my favorite parts of UNIX-like systems is the + composability of command-line tools. Instead of having giant monolithic + programs that do everything, you have various small domain-specific + tools that all use a common interface — standard-input and -output. The + following is a good example of this: + } + + figure { + pre {= m4_fmt_code(compose.sh.gsp) } + } + + p {- + I have a m4_abbr(YAML) file on my system with various fun quotes, and I + like to have a quote-of-the-day that’s displayed when I open a terminal. + I can make use of the @code{-yq} program which is specialized in + querying m4_abbr(YAML) files to extract the list of quotes from the + file. I can then use the @code{-shuf} program to shuffle the quotes and + pick one at random, and finally I can use the @code{-tr} program to + translate null-bytes to newlines. + } + + p {- + Notice how all three of these tools are very specialized to a specific + domain; they don’t try to reinvent the wheel, instead offloading the + tasks they aren’t specialized to do to other tools. @code{-yq} doesn’t + waste its time with functionality to shuffle lists of items because you + can do it with @code{-shuf} instead. This mindset of composability + allows you the user to create tools that are more powerful than they + could have been otherwise. Instead of hoping that all your tools offer + support for shuffling items @em{-and} hoping that they can shuffle + things in the specific way you like, you can just use the one single + shuffling tool @code{-shuf} everywhere. + } + + p {- + In my example I used @code{-shuf} to pick a random quote, but I could + similarly use it to pick a random song from a playlist, or to pick a + random image to use as a desktop wallpaper. + } + + p {- + So with the composability of the UNIX environment being such a great + thing, it blows my mind that people are still writing software such as + @code{-kitty} that try to do absolutely everything in one giant + monolithic program instead of keeping focused to the task at hand and + allowing the user to extend their tools to add in the functionality they + so desire. + } + + figure { + figcaption {-Kitty’s unicode input screen} + img + alt="Kitty’s Unicode Input" + src="unicode.jpg" + style="width: 100%;" + {} + } + + p {- + Some of you have surely already figured out what my issue is with what + Kitty has done here, and why I think this is shitty software design. + For those that haven’t, allow me to ask you a question: + @em{-what would be better than unicode input in your terminal?} + } + + p {- + The answer is simple: @em{-unicode input everywhere.} + } + + p {- + Why should you be limited to unicode input in your terminal? What if + you’re texting your friend or sending an email, and want to include a + unicode symbol such as ‘™’, or want to properly refer to a site you + visited such as Ta’ Ħaġrat? Perhaps you even have a friend whose + surname is Mäkelä. Or maybe — you just want to send your friends a + middle-finger emoji sometimes. + } + + p {- + Wouldn’t it be nice if you had a @em{-global} menu for unicode input? + Well turns out it’s actually really damn easy to do yourself, and + renders all that Kitty code absolutely useless. + } + + h2 #scripting {-Writing the Script} + p {- + The first thing you’re probably going to need if you want to have your + own unicode-input tool is a list of all the unicode characters out + there. Luckily for you, I already went through the hell that is the + @a href="https://unicode.org" {-Unicode website} to find it for you. + } + + figure { + pre {= m4_fmt_code(download.sh.gsp) } + } + + p {- + You can check out the file for yourself if you want. It’s got a bunch + of information in it — a lot of which is really useless for our + purposes. There are also a bunch of control characters and other things + in there that I personally don’t care for, so those can probably be + removed too. If it tickles your fancy, I’ve written a @code{-sed} + script to clean up the input into something a bit nicer: + } + + figure { + pre {= m4_fmt_code(cleanup.sed.gsp) } + } + + p {- + After processing, your unicode data file should look something like + this: + } + + figure { + pre {= m4_fmt_code(unicode.txt.gsp) } + } + + aside { + p {- + You know how I inserted that sample of my unicode data file you see + right above this? By using a small- and simple command-line tool in + the form of @code{-head} to grab the first 10 lines of the file, and + then using another small- and simple command-line tool in the form of + @code{-wl-copy} to copy those 10 lines to my clipboard. Take that + Kitty. + } + } + + p {- + Now that you have your data file, we can begin scripting. The first + thing we want is to get all of the names of the unicode characters. + Turns out that is a very easy task thanks to the @code{-cut} utility. + We can split each line on a semicolon and extract the second field with + a simple command, and then we can compose it together with @code{-dmenu} + or your preferred clone of it to present the user with a graphical list + of items they can pick from: + } + + figure { + pre {= m4_fmt_code(dmenu.sh.gsp) } + } + + p {- + Notice how we can simply compose @code{-cut} and @code{-dmenu} together, + and just assign the result to a variable. We can do this because these + are sane programs that read from standard-input, perform some simple, + basic task, and then print a result to standard-output. One tool to + parse a file, and another tool to let the user pick a selection. + } + + p {- + We have the users selection now, the @code{-$name} variable holds the + name of the unicode character that the user selected. All that we need + now is to actually get the unicode @em{-character} of our choosing. + Luckily this is @em{-also} incredibly easy thanks to composition: + } + + figure { + pre {= m4_fmt_code(program.sh.gsp) } + } + + p {- + Congratulations! That entire script, which can be easily condensed down + into only 2 lines of code is all you need to create a graphical + interface that allows you to pick a unicode character, and then copies + your selection to your clipboard — and it was all done by taking simple + tools and combining them to make a creater application. + } + + p {- + So next time you’re developing software and want to add a new feature, + just pause and think for a second. Do you @em{-need} that feature? Can + it be done in a better way? It is possible to generalize your feature + to where it is useful outside of just your specific application? Don’t + make the same mistake Kitty did. Allow me to leave you with this quote: + } + + figure .quote { + blockquote { + p {= + The talk reviews reasons for UNIX’s popularity and shows, using UCB + @code{-cat} as a primary example, how UNIX has grown fat. + @code{-cat} isn’t for printing files with line numbers, it isn’t for + compressing multiple blank lines, it’s not for looking at + non-printing ASCII characters, it’s for concatenating files. + } + p {= + We are reminded that @code{-ls} isn’t the place for code to break a + single column into multiple ones, and that @code{-mailnews} + shouldn’t have its own @code{-more} processing or joke encryption + code. + } + } + figcaption {-USENIX Summer Conference Proceedings, 1983} + } + + h2 #good-bad {-The Good, The Bad, and The Ugly} + p {- + I would like to take a moment to point out some examples of + composability done right, and some examples of features that are + actively harmful in the pursuit of the UNIX ideal. + } + + h3 {-Ls — Bad} + aside { + p {- + This is already referenced in the above quote, but I added that quote + after this section was already written. + } + } + + p {- + The @code{-ls} program is one of the most useful ones found in the UNIX + environment. It has a simple job to perform and it does it well. It + lists files in a directory. So what’s the issue then? Well let’s see + what happens when you combine @code{-ls} and @code{-cat}: + } + + figure { + pre {= m4_fmt_code(ls-1.sh.gsp) } + } + + p {- + Ok… that looks about right. We invoke @code{-ls} and we get a listing + of the current directory, newline-separated. Well look at what happens + when we don’t compose it with another command: + } + + figure { + pre {= m4_fmt_code(ls-2.sh.gsp) } + } + + p {- + Yeah… it decided to ‘prettify’ the output by putting everything on one + line. If the input contains enough items it columnates them really + nicely for you. Here’s an example of what it looks like when I run + @code{-ls} in my screenshots folder: + } + + figure { + pre {= m4_fmt_code(ls-3.sh.gsp) } + } + + p {- + Now don’t get me wrong, I like the fact that I can see more than one + item per-line. But why is this specific to @code{-ls}? It could + actually be really useful to be able to take arbitrary input and + columnate it in such a form for easier consumption. The @code{-column} + program does exist on Linux systems, but it is far inferior to what + @code{-ls} provides. In the ideal world, @code{-ls} would simply + display one filename per-line with a better @code{-column} command, and + you could compose the two to get a nicer viewing experience for your + files. + } + + h3 {-Tabbed — Good} + p {- + What is one thing that almost all your graphical applications have in + common? They all have tabs. Your web browser has tabs, your terminal + probably supports tabs (and if it doesn’t, I bet you use @code{-tmux}). + Your code editors have tabs, and even modern email-clients have tabs. + Now let me ask you: why do we always reinvent the tab? + } + + p {- + Suckless — the same people that brought us @code{-dmenu} — also created + a lesser-known application called @code{-tabbed}. You can + @a + href="https://tools.suckless.org/tabbed/" + target="_blank" + {-find it here}. + It’s quite a simple piece of software. You simply run it together with + another program (such as the @code{-st} terminal) and it adds + tab-support to it. Not only does this reduce code-duplication, but it + also is benefitial for you the software user as it means you get a + consistent UI with consistent-behavior and -key-bindings wherever you + go. + } + } + + hr{} + + footer { m4_footer } + } +} diff --git a/src/blog/extend/ls-1.sh.gsp b/src/blog/extend/ls-1.sh.gsp new file mode 100644 index 0000000..389a58d --- /dev/null +++ b/src/blog/extend/ls-1.sh.gsp @@ -0,0 +1,6 @@ +@span .p {-thomas} @span .pp {-~} @span .p {-〉}@span .fn {-ls} @span .op {-|} @span .fn {-cat} +code +doc +down +mail +media diff --git a/src/blog/extend/ls-2.sh.gsp b/src/blog/extend/ls-2.sh.gsp new file mode 100644 index 0000000..fd4fc09 --- /dev/null +++ b/src/blog/extend/ls-2.sh.gsp @@ -0,0 +1,2 @@ +@span .p {-thomas} @span .pp {-~} @span .p {-〉}@span .fn {-ls} +code doc down mail media diff --git a/src/blog/extend/ls-3.sh.gsp b/src/blog/extend/ls-3.sh.gsp new file mode 100644 index 0000000..5a436c8 --- /dev/null +++ b/src/blog/extend/ls-3.sh.gsp @@ -0,0 +1,6 @@ +@span .p {-thomas} @span .pp {-screen} @span .p {-〉}@span .fn {-ls} +… +2023-08-03_18:07:58.png 2023-10-05_16:08:17.png 2023-11-18_20:54:30.png +2023-08-04_16:17:22.png 2023-10-05_20:24:05.png 2023-11-18_21:07:07.png +2023-08-04_17:50:39.png 2023-10-05_20:24:21.png 2023-11-18_21:07:48.png +2023-08-05_16:05:07.png 2023-10-05_20:32:49.png 2023-11-18_21:07:57.png diff --git a/src/blog/extend/program.sh.gsp b/src/blog/extend/program.sh.gsp new file mode 100644 index 0000000..054a750 --- /dev/null +++ b/src/blog/extend/program.sh.gsp @@ -0,0 +1,4 @@ +name@span .op {-=}@span .str {-"}@span .op {-$(}@span .fn {-cut} -d@span .str {-';'} -f2 UnicodeData.txt @span .op {-|} @span .fn {-dmenu}@span .op {-)}@span .str {-"} +@span .fn {-awk} -vn=@span .str {-"$name"} -F@span .str {-';'} @span .str {-'$2 == n { print $1 \}'} UnicodeData.txt @span .op {-\\} +| @span .fn {-xargs} printf @span .op {-\\} +| @span .fn {-wl-copy} diff --git a/src/blog/extend/unicode.jpg b/src/blog/extend/unicode.jpg new file mode 100644 index 0000000..7f1f3b3 Binary files /dev/null and b/src/blog/extend/unicode.jpg differ diff --git a/src/blog/extend/unicode.txt.gsp b/src/blog/extend/unicode.txt.gsp new file mode 100644 index 0000000..dbc0da5 --- /dev/null +++ b/src/blog/extend/unicode.txt.gsp @@ -0,0 +1,10 @@ +\\\\u0020@span .op {-;}Space +\\\\u0021@span .op {-;}Exclamation Mark +\\\\u0022@span .op {-;}Quotation Mark +\\\\u0023@span .op {-;}Number Sign +\\\\u0024@span .op {-;}Dollar Sign +\\\\u0025@span .op {-;}Percent Sign +\\\\u0026@span .op {-;}Ampersand +\\\\u0027@span .op {-;}Apostrophe +\\\\u0028@span .op {-;}Left Parenthesis +\\\\u0029@span .op {-;}Right Parenthesis diff --git a/src/blog/index.gsp b/src/blog/index.gsp index 030ad3e..f014029 100644 --- a/src/blog/index.gsp +++ b/src/blog/index.gsp @@ -28,6 +28,7 @@ html lang="en" { p {-Posts:} ul { + m4_article(extend, {-Extensible Scripting}) m4_article(nvim-ts, {-Hacking with Tree-Sitter on Neovim}) m4_article(gsp, {-Writing an HTML Preprocessor (feat. Tree-Sitter)}) m4_article(fw-ec, {-Patching My Laptop’s Embedded Controller}) diff --git a/src/style.css b/src/style.css index 53d9499..842e95d 100644 --- a/src/style.css +++ b/src/style.css @@ -187,6 +187,10 @@ dl { .cnst { color: var(--blue); } .op { color: var(--lesser); } +/* Terminal prompt */ +.p { color: #24DFC4; font-weight: bold; } +.pp { font-weight: bold; } + .diff-ins { color: var(--green); } .diff-del { color: var(--red); } .diff-loc { color: var(--lesser); } @@ -274,6 +278,7 @@ dl { abbr.totp::before { content: 'Time-Based One-Time Password'; } abbr.uri::before { content: 'Uniform Resource Identifier'; } abbr.xml::before { content: 'Extensible Markup Language'; } + abbr.yaml::before { content: 'YAML Ain’t Markup Language™'; } } @media (max-width: 600px) { -- cgit v1.2.3