How I Distributed my .bashrc on Windows and Automatically Synchronize it Across Multiple Machines

The .bashrc lies at the heart of most Linux people, but since Git Bash‘s come to Windows, I don’t see why we should be left out?

This article sketches a simple way of keeping your data in the cloud, such that a minimum is needed to get your favourite bash-setup on a new system!

Why would I want to do this?

Well, you might have a config you know you always want. Personally I’d like the bash to always start or capture my ssh-agent, and I don’t want to edit my .bashrc and tell my computer that, every time I format it, so I’ve added the code from https://help.github.com/articles/working-with-ssh-key-passphrases/ to my .bashrc and distributed that. So now I only need to tell my computer to actually use the distributed file.

The Setup

First of all, you need a cloud provider, I’m just using Dropbox for this, but you can really use anything you’d like.

  1. Create the distributed global config
    1. Go to the cloud-folder where you want to keep your configs,
    2. somewhere like D:/Dropbox/config
    3. create a file called .bashrc inside it,
    4. you might have difficulties with this on a Windows system, but
      1. $ cd /D/Dropbox/configs, and
      2. $ vim .bashrc
        will work tremendously, (after you’ve created the config folder of course.)
    5. Inhere, paste your settings, for now it can just be
  2. Create the distributed local config
    1. create a file called .bash_profile in the same folder
    2. Inhere, you paste the following
    3. Save it. This will
      1. Check whether the .bashrc file exists, and
      2. Source it, if it does, i.e. load it in the bash.
  3. Overwrite your local config with the distributed local config
    1. e.g. run the command,
      $ cp /D/Dropbox/config/.bash_profile ~/.bash_profile
      (You might wanna check if the ~/.bash_profile file exists already..), and
  4. Restart Git Bash

If you’ve carried out the steps correctly, you should see “.bashrc loaded” when it starts!

So what have we done?

  1. Created a distributed global config file, .bashrc, in Dropbox,
    – so we can make changes that are synchronized with all our computers!
  2. created a distributed local config file, .bash_profile, in Dropbox,
    – so we have an “include .bashrc” template, we can easily copy
  3. overwritten our actual local config file with the distributed local config file.
    – actually started using the distributed .bashrc file on our system.

Q. This seems like a lot of steps, why is this smart?
A. Well, the next time you get a new computer, you only have to carry out the last step above. (Given you’ve installed Dropbox of course….)

Q. But the last step is still a manual step! Why should 1 be better than 3 small steps if I have to spend 10 minutes setting it up, just to save 2 minutes when I’m using it?
A. Seriously?.. Throw the copy-code in a post-format-script.sh and your computer configures automatically. Anything else?

Q. This is genious! Wait, can I do this with other stuff as well?
A. Sure! Personally I’ve made my own Hub.Docker-like setup with Dropbox/Google Drive, selective-sync and portable apps. But that’s another story! – and also an unnecessary workaround since, Docker has now come to Windows. But for a time, it was actually pretty cool!

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *