💾 Archived View for idiomdrottning.org › cfgmagit captured on 2024-03-21 at 15:11:57. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

cfgmagit

A while ago, I got the suggestion to set up

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

so I could use config to save dotfiles and such without every app believing that my entire home directory is a git repository.

I can clone the dotfiles from elsewhere with git clone ~/.cfg, but in the directory I instead call config, like config add, config

commit etc.

I’ve also seen other names proposed for this repo dir, like .myconf or .dotfiles.git.

But since apps don’t believe that my entire home directory is a git repository, that includes magit and I sometimes wanna use magit to restore files or partially stage hunks or whatever. Things that are too time-consuming to do by hand.

So here’s a script that temporarily actually does make the home directory into that git repository, waits for you to be done with Magit, and then restores things.

This does clobber the ~/.git file or even breaks if that pathname is a directory or such, so don’t have that.

#!/bin/sh
echo "gitdir: $(realpath "$1")" > ~/.git
cd "$(realpath "$1")"
git config --unset core.bare
git config core.worktree ../
echo "Do your magit stuff! Then hit RET here when you're done."
read nothing
git config --unset core.worktree
git config core.bare true
rm ~/.git
cd -

Call it with your conf repo dir as an argument, in my case I’d call:

cfgmagit ~/.cfg

For a repo,

git clone https://idiomdrottning.org/cfgmagit