Snippets are one of my favorite parts of programming. The shear endless depth of command line tricks and customizations is so exciting! Here is a collection I maintain for myself to comeback to.

Also navigable by list of snippet types here.

diy git remote on nas storage -- 26.06.2022 %

Got a repo with sensitive data you don’t want to push to a remote server you don’t control? Have a NAS setup on our home network? Here is how to setup a folder on that NAS to act as a git remote.

*Step 1:

Change directorys to the NAS and clone the local folder with the –bare option.

$ cd /Volumes/travis/git
$ git clone --bare ~/.password-store

This creates /Volumes/travis/git/.password-store but without a working directory. Basically its just the /.git part of the repo.

Step 2:

Setup the NAS file path to be a git remote on the repo.

$ cd ~/.password-store
$ git remote add nas /Volumes/travis/git/

Step 3:

Done. Now jus push.

$ git push nas
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 10 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.30 KiB | 1.30 MiB/s, done.
\- [ git, nas ]

update npm packages to latest versions -- 15.06.2022 %

I was doing some housekeeping on a Node.JS project today. Wanted to update all the dependencies to their latest versions. At first I tried npm update but come to find out that is ment more for upgrading single packages and not major versions. In the end after some googling I found npm-check-updates.

To upgrade the dependencies of a project without installing anything else I ran:

$ npx npm-check-updates -u

It updated the package.json so it must be followed up by a:

$ npm i

Which will install the new packages and update the package-lock.json.


\- [ npm, js, node ]

sign git commits -- 08.06.2022 %

Who doesn’t want the cool “verified” badge in Gitlab.

coolness badge

coolness badge

To get this we must sign our commits via gpg.

Step 1: Figure out which key you are going to use

$ gpg --list-keys
pub   rsa3072 2020-01-01 [SC] [expires: 2030-01-01]
uid           [ultimate] Travis Shears <>
sub   rsa3072 2020-01-01 [E] [expires: 2030-01-01]

pub   rsa2048 2020-01-01 [SC] [expires: 2030-01-01]
uid           [ultimate] Travis Shears <>
sub   rsa2048 2020-01-01 [E] [expires: 2030-01-01]

In this case I’ll use key

Step two: Configure git to sign commits with the gpg key

Edit your ~/.gitconfig to look something like this

   name = Travis Shears
   email =
       gpgsign = true

We added the signingkey so git knows which key to use and we specified gpgsign so git knows we want to sign all commits.

Step three: Copy your public gpg key to clipboard


You can also do it with the email of the key

$ gpg --armor --export | pbcopy

Step four: Paste your public gpg key into settings page of your favorite version control site, ex: Github, Gitlab, Source Hut.


\- [ git, gpg ]

remap §/± to `/~ on max osx -- 05.06.2022 %

Got a new Macbook Pro with the start of my new job and I love it. Except. It did not come with and english keyboard. Now every time I try to type the backslash (`) or tilde (~) instead I get “§” or “±” 😔. Lucky for me there are a bunch of people with the same issue.

This base command to remap the key is:

$ hidutil property --set '{"UserKeyMapping":

but to make this survive a computer restart things get a little more complicated. For that you need you need a LaunchDaemon.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">


#/bin/sh -e

hidutil property --set '{"UserKeyMapping":


\- [ osx ]

fix git file mode changes -- 04.06.2022 %

Before changing laptops I backed up all my personal projects to my NAS. When I transfer them back the file modes got messed up and a git status returned this:

diff --git a/docker/Dockerfile b/docker/Dockerfile
old mode 100644
new mode 100755
diff --git a/lib/DeployTool/CLI.rakumod b/lib/DeployTool/CLI.rakumogpg --list-secret-keys --keyid-format LONG <EMAIL>d
old mode 100644
new mode 100755
diff --git a/lib/DeployTool/Config.rakumod b/lib/DeployTool/Config.rakumod
old mode 100644
new mode 100755

Git diff shell magic, thanks to Stanislav Khromov, to the rescue!

$ git diff -p -R --no-ext-diff --no-color \
    | grep -E "^(diff|(old|new) mode)" --color=never  \
    | git apply

This command uses git diff and some clever grep logic to swap the file modes back to what git remembers them as.

I also converted the snippet to a shell script here

source: Stanislav Khromov’s blog

\- [ git ]

trust gpg key -- 04.06.2022 %

Just moved computers and thus moved my pass store. After importing my gpg keys, explained in this snippet, I had to trust them in order to stop the annoying warnings everytime I created a new password.


\- [ gpg ]

per company git config -- 03.06.2022 %

Started new job this week and I wanted to have a seprate email on my work related repos then my personal ones. Cool thing is git supports conditional config file includes!


# per-user git config
name = Travis Shears
email =

[includeIf "gitdir:~/company-x/"]
  path = .gitconfig-company-x


# Company X spefic git config
name = Travis Shears
email =

Now any commits made under the directory ~/company-x will use the email and not my personal email.


\- [ git ]

ios xcode simulator dark mode -- 02.05.2022 %

Recently I was testing an IOS app on my wifes phone. The UI was completly broken. Turns out she had dark mode enabled. That led me down the path of adding dark mode support to the app. Which is testable via the Xcode simulator if you know how to enable it.

Command + Shift + A: Toggles dark mode


\- [ xcode ]

bash extract file name -- 17.03.2022 %

Comparing the following shows how to use basename to extract just the file name from a full path.

$ for file in ./content/**/*.md ; do echo $file ; done | head -10

$ for file in ./content/**/*.md ; do file=$(basename $file) && echo $file ; done
\- [ sh, bash ]

s3 move folder / rename folder -- 17.03.2022 %

Working on my Oblastle game today. In an effort to standardize the way I store images for the game in S3 I needed to move all the files with key image-service/images/oblastle/flags/ to /image-service/images/oblastle/flag/.

Here is how I did it:

$ aws s3 mv s3://travisshears.images/image-service/images/oblastle/flags/ s3://travisshears.images/image-service/images/oblastle/flag/ --recursive --profile personal


\- [ s3, aws ]