Skip to content

Today I Learned (TIL)#

This is a second blog, intended for shorter posts about discoveries I make or insights I gain.

A tip for conveniently switching between Neovim configurations

Abstract

Introducing Neovim’s environment variable NVIM_APPNAME for switching between different configurations.

If you use Neovim as your text editor, then maybe my problem sounds familiar to you:

  • I’ve copied code snippets from various people and am hacking together the configuration that fits me perfectly, but it still has rough edges and some things are just broken because I don’t really know what I’m doing.
  • There are fantastic, pre-configured Neovim distributions like LazyVim, maintained by people who know what they’re doing, but they don’t include the customizations I picked up over the time.

Eventually, I will have my own tweaks and configurations sorted out, but I need a working—and not just working but beautiful and enabling—text editor today. I want to be able to switch between LazyVim (as my day-to-day text editor configuration) and my own custom configuration.

Today I learned about the environment variable NVIM_APPNAME that makes this much more convenient than what I’ve been doing until now.

A more readable alternative to SQL’s CASE expression

Abstract

Introducing SQL’s function decode as a more readable and maybe more performant alternative to the case-expression, usable when the conditions all have a certain structure.

For a certain kind of case-when-then-expression, you can use the SQL function decode as an alternative that I find more readable and that I prefer whenever I can.

Granted, the case expression is much more flexible than decode and can thus be used under many more circumstances, but it’s exactly the limits of decode for which I immediately valued it once I first heard of decode. The restrictions of decode mean that whenever I see decode being used, I know exactly what awaits me reading the coming code and, more importantly, what cannot await me. Whenever I see decode, I can be certain that it’s that particular use case.

At my workplace, I’m the code owner of much of our SQL code and I thus review a lot of SQL code that was written by other people. After I learned about SQL’s decode function, I taught it to my colleagues and am always grateful when they use it.

A time-saving way to re-run your last terminal command but with substituted parts

Abstract

Introducing the shell command fc and its option -s.

I already wrote two articles about the Z shell’s built-in r (with no or one argument and with two arguments) which really only is an alias for a particular use case of the command fc. So today, let’s stop scratching the surface that is the command r and dig deeper by examining the command fc. There’s a lot more to discover about that fc command.

A time-saving way to re-run your last terminal command

Abstract

Introducing zsh’s command r and how to re-create it in bash.

The Z shell has a built-in named r that optionally takes an argument, and re-runs/repeats

  • the last command in your history that begins with the given argument (if an argument was given).
  • the last command in your history, period (if no argument was given).

Example

Imagine you executed these commands:

pip install --upgrade pip
echo "I just upgraded pip."

Executing r pip would execute the last command in your history that begins with pip. In our case, it would run pip install --upgrade pip again.

Running simply r (without any argument) would run the last command again. In our case, it would run echo "I just upgraded pip." again.

A less-known way to undo/restore changes with git

Abstract

Introducing git checkout’s optional second argument, and the newer/safer alternatives to git checkout, git restore and git switch.

If you use git, then you probably know that you switch branches using the git checkout command:

git checkout my-branch

What not everybody knows is that you can pass the git checkout command a filename as a second argument. That way you can change the file to how it looked at the time of the first argument (a branch or a commit).

Your SSH config file might be misconfigured

Abstract

Setting the Host option in SSH’s configuration file the correct way.

I was getting a Permission denied (publickey) error after I migrated from GitHub to Codeberg, and could not push to my new git hosting service. Even though I configured my SSH setup for Codeberg exactly like I configured it for GitHub, which (still) worked. It turned out that my understanding of the SSH config file was wrong the entire time.

My SSH configuration had been wrong for years. I never noticed it because it nonetheless worked. I want to help you avoid making the same mistake I made.

In this post I’ll show you:

  • how I had SSH configured
  • what was wrong about it and why
  • why it worked nonetheless
  • how SSH is configured correctly

A time-saving way to change directory to sibling directories

Abstract

Introducing the shell variable CDPATH for more convenience when changing directories using cd.

How often do you execute cd ..? If you add .. to your shell’s environment variable CDPATH, then you won’t need to write cd .. so often anymore.

Imagine your ~/.config/ directory contains these subdirectories:

.
├── bash
├── git
├── nvim
└── zsh

You’re inside ~/.config/zsh/ and now would like to change directory to ~/.config/bash/. You’d probably do cd .. and then cd bash, right? Imagine you could omit the cd .. and do just cd bash. From within ~/.config/zsh/! Rather than from ~/.config/! By setting the variable CDPATH you can jump directly to siblings without having to visit the parent first.

Read on to find out more.