diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/blog/extend/cleanup.sed | 6 | ||||
-rw-r--r-- | src/blog/extend/compose.sh | 3 | ||||
-rw-r--r-- | src/blog/extend/dmenu.sh | 1 | ||||
-rw-r--r-- | src/blog/extend/download.sh | 1 | ||||
-rw-r--r-- | src/blog/extend/index.gsp | 312 | ||||
-rw-r--r-- | src/blog/extend/ls-1.sh | 6 | ||||
-rw-r--r-- | src/blog/extend/ls-2.sh | 2 | ||||
-rw-r--r-- | src/blog/extend/ls-3.sh | 6 | ||||
-rw-r--r-- | src/blog/extend/program.sh | 6 | ||||
-rw-r--r-- | src/blog/extend/unicode.jpg | bin | 0 -> 31647 bytes | |||
-rw-r--r-- | src/blog/extend/unicode.txt | 10 | ||||
-rw-r--r-- | src/blog/index.gsp | 6 | ||||
-rw-r--r-- | src/style.css | 4 |
13 files changed, 358 insertions, 5 deletions
diff --git a/src/blog/extend/cleanup.sed b/src/blog/extend/cleanup.sed new file mode 100644 index 0000000..b3978bd --- /dev/null +++ b/src/blog/extend/cleanup.sed @@ -0,0 +1,6 @@ +s/;[^;]*//2g +s/\<(.)([A-Z]*)/\1\L\2/2g +/^[^;]*;</d +/Compatibility/d +/Variation Selector/d +s/[^;]*/\\\\u&/ diff --git a/src/blog/extend/compose.sh b/src/blog/extend/compose.sh new file mode 100644 index 0000000..be159bd --- /dev/null +++ b/src/blog/extend/compose.sh @@ -0,0 +1,3 @@ +yq -0 '.mangoes.[].quote.content' <quotes.yml \ +| shuf -zn1 \ +| tr '\0' '\n' diff --git a/src/blog/extend/dmenu.sh b/src/blog/extend/dmenu.sh new file mode 100644 index 0000000..5db5c36 --- /dev/null +++ b/src/blog/extend/dmenu.sh @@ -0,0 +1 @@ +name="$(cut -d';' -f2 UnicodeData.txt | dmenu)" diff --git a/src/blog/extend/download.sh b/src/blog/extend/download.sh new file mode 100644 index 0000000..59d6575 --- /dev/null +++ b/src/blog/extend/download.sh @@ -0,0 +1 @@ +$ wget '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..c0bf478 --- /dev/null +++ b/src/blog/extend/index.gsp @@ -0,0 +1,312 @@ +html lang="en" { + head { HEAD } + body { + header { + div .head { + h1 {-Dmenu is a Godsend} + INCLUDE(nav.gsp) + } + + figure .quote { + blockquote { + p {= + Because @code{-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 { FMT_CODE(compose.sh) } + } + + p {- + I have a 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 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 { FMT_CODE(download.sh) } + } + + 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 { FMT_CODE(cleanup.sed) } + } + + p {- + After processing, your unicode data file should look something like + this: + } + + figure { + pre { FMT_CODE(unicode.txt) } + } + + 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 { FMT_CODE(dmenu.sh) } + } + + 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 { FMT_CODE(program.sh) } + } + + 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 greater 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 { FMT_CODE(ls-1.sh) } + } + + 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 { FMT_CODE(ls-2.sh) } + } + + 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 { FMT_CODE(ls-3.sh) } + } + + 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 beneficial for you the software user as it means you get a + consistent UI with consistent-behavior and -key-bindings wherever you + go. + } + } + + footer { FOOT } + } +} diff --git a/src/blog/extend/ls-1.sh b/src/blog/extend/ls-1.sh new file mode 100644 index 0000000..623bd85 --- /dev/null +++ b/src/blog/extend/ls-1.sh @@ -0,0 +1,6 @@ +$ ls | cat +code +doc +down +mail +media diff --git a/src/blog/extend/ls-2.sh b/src/blog/extend/ls-2.sh new file mode 100644 index 0000000..6f70801 --- /dev/null +++ b/src/blog/extend/ls-2.sh @@ -0,0 +1,2 @@ +$ ls +code doc down mail media diff --git a/src/blog/extend/ls-3.sh b/src/blog/extend/ls-3.sh new file mode 100644 index 0000000..2e91b0d --- /dev/null +++ b/src/blog/extend/ls-3.sh @@ -0,0 +1,6 @@ +$ 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 b/src/blog/extend/program.sh new file mode 100644 index 0000000..da5d1a1 --- /dev/null +++ b/src/blog/extend/program.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +name="$(cut -d';' -f2 UnicodeData.txt | dmenu)" +awk -vn="$name" -F';' '$2 == n { print $1 }' UnicodeData.txt \ +| xargs printf \ +| wl-copy diff --git a/src/blog/extend/unicode.jpg b/src/blog/extend/unicode.jpg Binary files differnew file mode 100644 index 0000000..7f1f3b3 --- /dev/null +++ b/src/blog/extend/unicode.jpg diff --git a/src/blog/extend/unicode.txt b/src/blog/extend/unicode.txt new file mode 100644 index 0000000..5e1dff2 --- /dev/null +++ b/src/blog/extend/unicode.txt @@ -0,0 +1,10 @@ +\\u0020;Space +\\u0021;Exclamation Mark +\\u0022;Quotation Mark +\\u0023;Number Sign +\\u0024;Dollar Sign +\\u0025;Percent Sign +\\u0026;Ampersand +\\u0027;Apostrophe +\\u0028;Left Parenthesis +\\u0029;Right Parenthesis diff --git a/src/blog/index.gsp b/src/blog/index.gsp index e869c7e..a54e35b 100644 --- a/src/blog/index.gsp +++ b/src/blog/index.gsp @@ -28,11 +28,7 @@ html lang="en" { p {-Posts:} ul { - / ARTICLE(andy-val, {-Values in Andy}) - / ARTICLE(new-sh, {-Making a New Shell}) - / ARTICLE(extend, {-Extensible Scripting}) - / ARTICLE(fw-ec, {-Patching My Laptop’s Embedded Controller}) - + ARTICLE(extend, {-Extensible Scripting}) ARTICLE(grab, {-Making Grep Better}) ARTICLE(gsp, {-Writing an HTML Preprocessor (feat. Tree-Sitter)}) ARTICLE(nvim-ts, {-Hacking with Tree-Sitter on Neovim}) diff --git a/src/style.css b/src/style.css index fbeef58..0202e5c 100644 --- a/src/style.css +++ b/src/style.css @@ -125,3 +125,7 @@ ins { color: green; } del { color: red; } .hl-red { color: red; } + +aside { + font-style: italic; +} |