Continuing Adventures In Linux

So it’s been a couple of months since I tried to switch to Linux as my primary daily driver at home. Unlike previous attempts at making the switch over the last 20 years, this one is going well! I’m doing a bit more productive work, am able to WFH successfully, and have had a ton of fun getting the environment setup just right for me. This quick post provides a bit of detail on some of the additions that I’ve made to my setup since switching.

Synchronising The Setups

Although I’m not running too many servers here at Grumpy Labs, I run enough Linux machines, including the little farm of Raspberry Pi workers, to warrant trying to standardise the environment I use on each of those machines. Up until now, I’ve done this manually, setting up the same .zshrc file on each machine as I set it up. This is vaguely error prone, somewhat randomly different each time, and just generally a bit time consuming and painful.

Having read a few of Jeff Geerling’s articles, I know he’s quite keen on Ansible for standardising a lot of his machine setups. I even tried setting this up myself (pro tip - don’t try setting it up on a RPi Zero with 512MB of RAM, it’s pretty slow). But in the end, I’m not really looking for something to automate setting up a whole machine from scratch, just keeping the interactive environment consistent.

To do this, I started using chezmoi, a useful little toolkit to allow simple merging of common dotfile changes across machines. It was easy to setup, and I initally took a copy of the main files from my primary server, then deployed them to the Linux desktop. Naturally, some of the changes that were merged into the .zshrc file weren’t applicable to the new machine, so it was a good opportunity to target certain entries to specific machines. I then committed this back and reapplied them on the original server. For anyone still on the fence about how easy this is to use, and how useful it is, please take the plunge and just give it a go.

Replacing Some Old Software

It never really occurred to me, but when I randomly stumbled across modern-unix, it hit me like a pigeon in the face. Most of the commands I’ve gotten used to in the Linux space are, conceptually, old. As in, really really old (yes yes yes, even older than me!). Some of the functions have been around since the first version of AT&T UNIX, which makes them officially older than me. It may be hard to believe, but there has been some improvements in UX over the last fifty years. This is why it’s surprising that I didn’t think of looking at modern alternatives sooner.

The Modern Unix listing provides a lot of great alternatives to commonly used commands. The ones I’ve rolled out onto my local machine have been:

  • eza - ls replacement.
  • zoxide - clever cd replacement that uses fuzzy matching to take you quickly to commonly used directories.
  • tldr - neat man replacement.
  • ripgrep - the blindingly fast Rust implementation of grep.
  • bat - highlighted version of cat.
  • fd - simplified find.
  • procs - much nicer-looking ps.
  • dust - du with graphs!
  • gping - ping but with a helpful graph-based display.
  • glances - super detailed info on your system.
  • ag - The Silver Searcher - fast code-specific search.

The installation options varied a bit for different tools. Several of these are Rust projects installable via cargo, others came as distribution-based packages, and others were installed via pip. I wrote a script, intended to be run on any machine that I setup, that performs some brief checks that the various tools (cargo, pip3, virtualenv) are installed, then goes through and installs each program. It installs them all to the user’s local folder. This can be re-run whenever needed to pull down the latest changes.

An interesting aspect of the installation script is the need to determine the latest version of the fzf fuzzy matcher used by oxide. fzf isn’t available in my package manager, so rather than hardcoding a specific version number, I used lastversion, a neat python package that takes care of working out the path to the latest release file from a remote repository (many are supported, including GitHub and GitLab) for your architecture (or in fact any one of a number of different filter types that you can ask it to apply):

wget -qO- `lastversion --assets --filter linux_amd64 junegunn/fzf` | tar xvz

To go alongside the installation script, I used a standard pattern in my .zshrc file. For each of the listed programs, I check for its presence on the system, then if found, alias the original program to *old_<program_name>*, then alias the new program to the original program name. This looks something like

if command -v procs &> /dev/null
    alias old_ps=`which ps`
    alias ps="procs -c always --tree"

I do it this way so that I can use chezmoi to apply the changes to multiple machines, even if they don’t have the replacement programs available.

Modern equivalents to old tools have completely changed the way I work in the terminal. Output is colour-coordinated (no more greyscale squinting), the graphs in duf now make it easy to spot the worst offenders in terms of disk space (which helped me quickly clear some issues with one of the servers running out of room due to a netdata config issue), and brought lots of nice little quality of life improvements. I’m just genuinely surprised that these tools haven’t had more press, so this is me doing my small part.

Prompty McPromptFace

While oh-my-zsh has a pretty reasonable default command line prompt, it wasn’t until reading an article on nushell (something I’ve been considering tinkering with) that I realised that I might want something more. The article mentioned in passing something called Oh My Posh. It is, frankly, a terrible name, but when I looked at what it was doing, I was suitable intrigued.

Briefly, OMP allows you to define fancy command line prompts that are then translated to work with a variety of different shells. The prompts are defined using something they call segments - small units that each provide a particular bit of data for display in the shell. There are lots of different segments provided, including basic things like path, time, user/session details, and git details, as well as more advanced segments showing language-specific details for the directory you’re in, timing information for the last command you ran, cloud provider details and more.

The segments are combined together using a configuration file. JSON, YAML or TOML formats are supported. Different colours and visual styles of segments are available, giving you an enormous amount of flexibility in how your prompt looks. There are quite a few pre-defined themes on the OMP website, some of which seem to stretch across the entire terminal width! I’ve gone for a slightly simpler one, it helped that tiwahu supports Rust context information without any adjustment needed.

If you’ve clicked on any of the links for this piece though, you’ll have noticed some funky shapes in the sample screenshots:

Tiwahu theme for Oh My Posh
The Tiwahu theme - nice, clean and informative

Where do those funky symbols come from? The answer is the delightfully named NerdFonts concept. These are variations on existing developer-focused fonts, but with additional glyphs embedded to provide richer visualisations. OMP ensures that if you have a nerd font installed for your terminal, it will use these glyphs, otherwise it will fall back to a simpler, more text-based, display.

In a similar way to the modern unix tools defined above, OMP has given command prompts a modern spin, with the output being something we couldn’t have imagined at the start of the Linux era. It sounds silly, but I find using the terminal much more enjoyable now that I have more context to hand at all times. Definitely worth trying out.

Roll With It

The last thing that I like about Linux is the regular small updates to individual components. While this isn’t anything new or groundbreaking, it’s nice to see small improvements coming through regularly, rather than the chunkier updates I’ve become used to in Windows-land. They also don’t choose to reboot your machine at random intervals, which is admittedly a low bar to overcome and should be the baseline. Still, it’s worth highlighting how nice this is in terms of the overall feel and experience.

All in all, I’m still very much enjoying the Linux experience. Aside from a couple of things I’ve had to log back into Windows for (Media Monkey, I’m looking at you!), it’s been a seamless transition, and with the changes that I’ve described here, I’ve found that it’s actually exceeded my expectations. This makes me one fairly happy Metal Guy. Don’t worry though, regular grumps will resume in the future.