Why Modular Programs Are the Best - Draft

The most amazing thing about the UNIX system is the use of pipes that combines programms. But this post is not about that.


Note: This post is a draft and also a living document. I may add or remove content at any time and could have some type errors, so I recommend archiving it if you are interested.

The most amazing thing about the UNIX system, in my opinion, is the use of UNIX pipeline to combine or chain programs. Some of the scripts in my fuzzel scripts project would've been a lot more complicated without it.

Adding the ability to interact with a program via other programs will make the developer's life easier by reducing the features they need to implement.

While the UNIX pipeline is arguably the most modular system in computers, this post is not about that. I want to talk about a few projects that allows the end users to essentially hack the program to improve their workflow, or even have some fun!

My Workflow

I am a programmer, so my eyes are glued to a computer screen most of the time as my work, hobby, and entertainment revolves around it. While many things in on this Earth are now run using computers, most people do not use it for as long as I do.

This means that I want to modify the computer I use a lot so that I don't feel hindered with it. If I want to do something regularly, I make sure that the amount of time I spend on it is reduced as much as possible.

Entertainment

I am starting with entertainment as this is what most people use a computer for. My entertainment with computer involves reading articles, playing games, and watching videos β€” in that order.

Modular Article Reading

I usually read articles through a feed/news reader program. Sometimes, the websites will not give me the complete text content in their feed. While this is a bit annoying, most of the readers are smart enough to download the complete content from the source website. But what about the links within the article?

While I avoid adding websites to my feed that have page size larger than doom, the articles I read may still have links to them, and I may want to open that link for better reference.

I read the feeds using Newsboat, it is a wonderful tool. And its built-in browser can handle opening most links in the feed, but it has trouble with some websites, because of this, I swap the in-built browser with my preferred terminal browser links.

This can be done by editing the ~/.config/newsboat/config file:

browser "links %u" # here %u stands for URL

But just changing the browser is not making a tool modular, Newsboat has the capability to define custom macros, and the set browser command can be used to run arbitrary commands in the shell. This is what make Newsboat a powerful tool.

The macros are typically stored to a key, usually a letter or a number is used for this purpose, but could be any key. To avoid Newsboat confusing it with built-in key binding, the macros are triggered by pressing the , key first followed by the macro key.

For example, to trigger a macro stored to the letter m, we will need to type ,m

And of course, the macro key can also be changed to something else if you want to!

Handling Troublesome Links

Some websites out there are unreadable with my terminal browser, like the ones that dynamically loads the text content or have unnecessary content that is not part of the article I am reading.

Lucky for us, my GUI browser of choice, Librewolf (Firefox-based), can open a link in the Reader View by prefixing the text about:reader?url= to the URL. For example, if you go to about:reader?url=http://codingotaku.com/blogs/modular-programs in any Firefox-based browser, you will be able to read this page in the reader view.

So I created a macro that will change my browser to Librewolf's reader view, opens the URL, and change the browser back to the links browser:

macro o set browser "librewolf about:reader?url=%u"; open-in-browser; set browser "links %u"

Now all I need to do is type ,o to see the article without clutter! Cool right?

Viewing Images

As I usually do not subscribe to feeds without text as the main content, it's rare for me to view images in it, this is one of the reasons why I chose Newsboat instead of other fancy tools.

But, I sometimes want to open images in the feed using my system's image viewer swayimg so I can zoom, copy, or even edit the image later. swayimg can run arbitrary commands just like Newsboat!

So I created a macro that does the following, in the order:

  1. Set the default browser as swayimg.
  2. Run a curl command using the swayimg's custom exec protocol to download the image and display it.
  3. After the image is displayed, I update the default browser back to Librewolf.

The Newsboat macro looks like the following:

macro i set browser "swayimg 'exec://curl -s %u'"; \
  open-in-browser; \
  set browser "links %u"

It might look complicated, but it's not much different than what a generic browser would do. The benefits are the following:

  • I don't download huge media unless I really want to do so.
  • As swayimg can also run custom commands, I can do more things with the image like sharing or editing it with a few keypress.

Watching Videos or Listening to Music

It is very rare for me to open a video link from a feed, but when I do, I try opening it using my video player mpv first. mpv can use youtube-dl to stream videos, and contrary to the name, youtube-dl can handle many websites other than YouTube.

Doing this is just as easy as replacing swayimg with mpv in my previous macro:

macro m set browser "mpv %u"; open-in-browser; set browser "links %u"

The same macro will work with music too, so I use the key m for media

Sending Myself Webmentions

If a feed I follow mentions my website, and they support IndieWeb, I can send myself a Webmention for that article. This can also be done by simple browser switching:

macro w set browser "curl -si https://codingotaku.com/webmention -d source=%u -d target=https://codingotaku.com"; \
  open-in-browser; \
  set browser "links %u"

This is not perfect as this needs additional info about which page is being mentioned, but I can do that from my website after receiving the mention, so this is good enough for me.

Opening Other Custom Protocols

If there are other types of links, such as mailto:, matrix:, etc., which are meant to open other specialized clients, I can do it using the links browser, but not for all protocols. So I set a macro that opens links using xdg-open, which can handle all types of links that are registered in my system.

macro d set browser "xdg-open %u"; open-in-browser; set browser "links %u"

I never had to use it, but it's a nice macro to have.

Why Not Just Use a Browser?

While reading this, you might have thought to yourself, why not just use a normal browser? Or a web-based feed reader which can do all these?

My Ideal feed reader should be able to do all these things and should have the capability to extend more. It doesn't need to be a terminal-based one like Newsboat, but I want it to also be lightweight, configurable, and work on my pure Wayland system. Everyone has their on criteria, and this is mine, and once configured, it just works.

Modular Video Watching

If you thought Newsboat is overly configurable, you are in for a treat! mpv is a program for watching videos, while it is keyboard-centric, there are some GUI frontends which make it easy to use without a keyboard. Anyway, mpv is heavily scriptable, and it can be scripted and extended using lua, javascript, VapourSynth, and even with C!

The community have created a wide range of scripts, it's just too long to list here, you can find most of them at the Awesome mpv repository. Some of the most popular ones are:

  • SmartSkip - Skip opening, intro, outro, preview. Jump to next and previous files, and save chapter changes!
  • mpv thumbnail script - show thumbnails superfast on hover.
  • mpv sponsorblock - skip sponsors in YouTube videos.
  • mpv cut - video cutting/clipping/slicing script.

mpv has support to watch streaming videos too, including YouTube! All you need is to install the yt-dlp program in your system.

Ever wanted to watch a video with your friends or family over the internet? I know I have, mpv can be integrated with SyncPlay to do this.

Once you get the hang of using mpv, you will try to use it everywhere, this is the reason for the large number of active community scripts. The modular nature makes it easy to integrate mpv to almost anything. Did you know that you can use mpv to stream from your camera?

Playlists

I have a list of songs, music, and videos that I like. And I also like storing them in a TSV (Tab Seperated Value) file with the name and the URL.

A playlist file will look something like this:

URL to YouTube	Song1 name
URL to Vimeo	Song2 name
File path	Song3 name
Directory path	Collection name

This might look weird for many, but it works better than using any apps, because I can store URL from multiple services, and also store a file, or directory path (collection) in it.

The song name is just for me to know what that URL is for. It is not realy needed if all I have are file and directory paths.

And to play that list without video, I just need to run cut -f1 playlist-name.tsv | mpv --video=no --playlist=-, this will play the songs in the same order as in the file.

To shuffle the playlist, I just need to insert the shuf tool in the script: cut -f1 playlist-name.tsv | shuf |mpv --video=no --playlist=-.

I use the cut tool to remove the song/collection name from the file, as it serves no purpose for mpv.

But if I am not storing the names in the file, the script will be much simpler, I could just create a list of paths/URLs in a text file and run mpv --video=no --playlist=playlist-file.txt.

This doesn't mean that I type the whole command all the time, I just have a script named playlist which just play the songs in random order. For what it does, it could just be an alias, but I want to improve it in the futre, so it is what it is for the time being.

mpv is a monolithic tool, but it integrates well with other other tools that are unix-y. I may never use another media player unless I find them more efficient than mpv.

Modular Gaming

Like all entertainments, Games have been struck by a profit-driven mentality. Whether it is developing, publishing, or just playing, it is a bit difficult to find games that are friendly to the community. This means that extensible games are even harder to come by. Even for single player offline games.

But that does not stop us from developing modes, there are a lot of modes out there, even for the propriatory ones, which I do not want to link here.

Many Foss games support scripting to extend them, and also actively promote doing it. I'll list a few:

What I like about these games and engines is the ease of modifying the game without needing to reverse engineer a bunch of stuff, everything I need is documented well.

But these games and engines are still not as modular as the other tools that I use, and makes me lose my interest in tinkering with it after a while.

If you know of some good games that can be integrated with other tools in the system, let me know. What I like to do is interact with the operating system from within the game and vise versa. For example:

  • Getting the game notifications and achievements on my system's default notification program.
  • Ability to use the system menu (like fuzzel) program instead of the game's menu for navigation.
  • Adding quests to a To-Do list or a text file.
  • Using the system's text-to-speech engine to read dialogues out loud if the game doesn't have built in voice for characters.

The game itself should not do all these, but instead, it should provide an ability to interact with the game via configurable macros like what Newsboat does. Or it should have mpv like scriptability to do many more things that I have not thought of yet.

Hobbies

As I said in the My Workflow section, even my hobbies live inside a computer.

I create scripts, tools, and customise my system in my leisure time. I find it rewarding when I make things easier for myself to work with.

You can find most of my tools at my codeberg repositories. And most of my system customization in the dotfiles.

So What is Modular About Configuring System?

What I have is a well-integrated system that suites my taste, this is done so by connecting programs to each other. Such as Fuzzel, Foot, Emacs, Bash, jq, etc., Each with their own additional plugins, and each can replaced with another program without much hassle. well, may be not Emacs, but you can find replacements for all Emacs packages that I use as it's an extensible text editor.

I am underselling this section by not adding much here, but I have spent many years configuring my system that it is simply not possible to add all of it into a single post. Maybe I will do a series on it when I don't have anything else to share.

Work

TBA.

Non-modular Programs Are the Worst!

In my opinion, non-modular programs make things difficult over time. While one may be allured by the all-in-one programs that don't need much tinkering, the moment you need to do something that the program does not have a built-in way for, the more difficult your workflow will become.

While this is more true for proprietary programs, sometimes even an open-source program can also make things difficult by deliberately not making things configurable. For instance, the Android Open-Source Project (AOSP) does not have the ability to hide the navigation pill, and this makes other brands and custom ROMs do workarounds and their own patches to hide it.

Some VS Code extensions restrict themselves to work only with the official build of VS Code, crippling anyone who wants to build and use their own version of VS Code.

IPhone has no ability to permanently disable Bluetooth. And due to its non-modular and proprietary nature, you have no way to even workaround this.


Mentions

Looking for comments? This website uses webmention instead, the standard way for websites to talk to each other, you can either send me one through your website, or use the below form to submit your mention. If you do not own a website, send me an email instead.

Toggle the webmention form
All webmentions will be held for moderation by me before publishing it.

About me

Coding Otaku Logo

I'm Rahul Sivananda (he/him), the Internet knows me by the name Coding Otaku (they/them). I currently work as a Senior Software Engineer in London.

I care about Accessibility, Minimalism, and good User Experiences. I create small tools and scripts to make the life easy. If you need help or support with GNU/Linux system, or making your website accessible, you can reach out to me!

Following me

Subscribe to my web feeds if you like what I post and want to read them without visiting this website!

You can also find me on Mastodon, Codeberg, or Peertube.

Get my cURL card with curl -sL https://codingotaku.com/cc.

Supporting me

If you would like to help me to keep this site and my silly projects running, you can now donate to me through Liberapay or Stripe

Continue Reading

Like this post? there's more where that came from! Continue reading.

Recent Blogs

Subscribe via Atom or JSON feeds.