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.

git trim -- 23.02.2023 %

Easy clean up branches from local that are old or already merged on remote.

$ git trim -s -p
\- [ git ]

remove gps metadata from image -- 31.01.2023 %

Recently I noticed some of the images on my site had GPS metadata info. Thats not very private! So I did some googling and found this solution.

$ exiftool -GPS*= $(fd -e jpg -e png -e jpeg)


\- [ exiftool ]

update pleroma server -- 04.12.2022 %

I always forget how to upgrade my Pleroma servicer when a new version comes out so I’m writing it here. If you are unsure of what you are doing please consult the official docs.

My Pleroma instance:

Start by sshing into the server and switching to the pleroma user.

$ sudo su pleroma -s $SHELL 

Then stop the server request the update, migrate the db and start it again.

$ ./bin/pleroma stop
$ ./bin/pleroma_ctl update
$ ./bin/pleroma_ctl migrate
$ ./bin/pleroma daemon

Boom new version!

\- [ pleroma ]

discard unstaged changes -- 06.09.2022 %

Have a bunch of changes staged and want to drop the rest? Easy:

$ git restore .


\- [ git ]

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 ]