23 Sep 2022, 00:00

Managing dotfiles in git

How to manage dotfiles in a bare git-repo

How to set up:

Initialize an empty git repo in a folder in $HOME:

1
git init --bare $HOME/.cfg

Now we want to set up an alias for git to work on this repo:

1
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME' 

We want to hide untraced files, so we explicitly choose which files to track:

1
config config --local status.showUntrackedFiles no

Make config persistent, I use zsh, so I add the alias to .zshrc

1
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.zshrc

now its time to add a few existing config files to the repo:

1
2
3
config add .zshrc
config add .vimrc
config commit

I created a github repo and pushed my config to github:

1
2
config remote add origin <github-repo-url>
config push

Now, time to check out my config on another machine. First, checkout the repo using the --bare option

1
git clone --bare <git-repo-url> $HOME/.cfg

Define the config-alias

1
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'

And last: Check out the repo

1
config checkout

12 Feb 2020, 00:00

Some useful GPG commands

Some useful gpg commands

I recently ran into a problem with some gpg encrypted file, where the files were encrypted with another key than they were supposed to. Therefore I had to reencrypt them with another key. Every time I run into an unusual task with OpenGPG I find myself banging my head into a wall of useless documentation. Here’s some of the useful commands I found which let me resolve the issue:

First I had to find out what keys the file was actually encrypted with.

gpg --list-packets file.gpg - lists contents of a gpg encrypted package - including the key IDs used for encrypting the file. (The man page is of course less useful, since it only says “List only the sequence of packets. This command is only useful for debugging.” - but I haven’t found another way to do what I want)

% gpg --pinentry-mode cancel --list-packets <file>.gpg 2>&1 - if you only want to see which keys a file is encrypted with. (note, it will list the keys to STDERR, so therefor I added the redirect to STDOUT so I could grep for the key I was looking for)

% gpg -k --keyid-format short and % gpg -k --keyid-format long - There is a long and short format for GPG keys. If you want to see the short or long format for the keyid when listing keys, add the —-keyid-format option.

Note: if you always want to print for instance long format, you could add keyid-format long to ~/.gnupg/gpg.conf

Want to know the fingerprint of the subkeys? Use gpg -K --with-subkey-fingerprint --keyid-format none

A few useful links: