Making PowerShell “Posh”
Back in the days when DOS and Windows were separate programs, the default Command Prompt didn’t look exactly the way that it does now. I can’t recall if it w...
While I don’t use Linux as my primary operating system, I do use it a lot both at home and at work. It can be frustrating to try to sync up configurations between different hosts or even just figuring out how to make a new laptop work like an old one. I remembered that some coworkers at my old job had some way of storing all of their dotfiles in Github to make this easier. It took a bit to figure out the best way to make this work.
First, I use a bare git repository. Bare repositories are typically used for sharing rather than working because they don’t store a working directory. In this case, we’re going to use it because we don’t need all of features of a full repo. We’re just making it easier for us to store these files and deploy them to other machines.
I’m going to create another post about my Raspberry Pi setup script that I use to set up a new pi. It includes the initial setup of the dotfiles repo on a new machine from an existing repo.
First, we have to create our bare repository. We have to change things around so that the working directly is the home directory and the git files are stored in a hidden folder (normally it’s the other way around), and we have to tell git not to show tracked files. We’ll do this as follows:
git init --bare $HOME/.cfg
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
config config --local status.showUntrackedFiles no
This also creates an alias config that we’ll use to interact with the repo. We’ll need to make this permanent by adding it to .bashrc as follows:
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bashrc
Once this is done, you can version the files in the home directory with normal git commands, except you use the config alias for this instead of git. For example:
config add .bashrc
config commit -m "Added config alias to .bashrc"
config push
You’ll need to push your repo to Github or whatever site you’re using. You’ll need the URL for your repo from there for the next steps.
config remote add origin <remote repository URL>
config push
Once you have your files in a git repository, you’ll need to manually create the alias to the config command that we created above. Note that you can also just add the –git-dir and –work-tree parameters to each command if you have your .bashrc in your repo and you don’t want to edit it manually. I have a script for deploying a new Raspberry Pi image that does this that I’ll cover in a later post. Either add those parameters or make sure this alias is defined in your current shell scope by running this command at the shell.
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
You’ll also need to add a .gitignore file to avoid weird recursion issues:
echo ".cfg" >> .gitignore
Next, clone the repo into a bare repository in a hidden “dot” directory:
git clone --bare <git-repo-url> $HOME/.cfg
Check out the repo. You may run into an error if you have existing files already in your home directory that are also in the repo. Git doesn’t like to overwrite files.
Finally, you’ll want to set the showUntrackedFiles flag to no for this repository. That way you won’t see every file in your home directory when you’re working with the repo:
config config --local status.showUntrackedFiles no
That’s it! I find this particularly helpful when I set up a new Raspberry Pi, but I also use it when I migrate to a new computer. I keep my .ssh/authorized_keys file in my repo so that when I change keys or add a new one, I just have to update the repo on all of my machines by running this:
config pull
Back in the days when DOS and Windows were separate programs, the default Command Prompt didn’t look exactly the way that it does now. I can’t recall if it w...
Sometimes it’s the little things…
As a Data Engineer using Mirth Connect, it’s often tricky to review my team’s merge requests because the merge request document contains the XML representati...
When dealing with Python dependencies, it’s sometimes necessary to determine if a given project is using a given version of a library. Since our team is usin...
A while ago, I wrote about using a bare git repository to manage my dotfiles. That worked somewhat well, but it had some shortcomings. Since, I’ve started us...
One of my current projects involves some improvements to code that I wrote last year – specifically enhancing the “Patient Identity Fixer”, which is my pet p...
To borrow from a favorite web comic: whenever I learn a new skill, I concoct elaborate fantasy scenarios where it lets me save the day. Actually, it feels li...
This one bugged me for a few days. I don’t think this script is the best solution to the problem at hand, but it was still fun to figure out.
My team at work has a custom FHIR resource that we work with often called an Operation Outcome. We generate one of these for nearly every record we process, ...
a.k.a. Why I Don’t Use Nano
COVID-19 has us many of us working from home. My husband and I are both fortunate enough to be in this group. However, as a teacher, his schedule is very pre...
When I set up a Raspberry Pi, there are a few things that I have to do right out of the gate to make things easier on myself. They involve putting a few file...
While I don’t use Linux as my primary operating system, I do use it a lot both at home and at work. It can be frustrating to try to sync up configurations be...
Anyone who knows my husband or me knows that we really like our cold brew, and they also know that we make our own at home. Nitro cold brew has become a bit ...
So you want to run an OpenVPN Server on a Raspberry Pi? I did too, but it wasn’t easy to figure out the first time. If you want to skip all of this and do it...