Configuration sharing with Dropbox, Part 3: Bash

1 minute read


In this article, I will explain how you can easily share shell scripts between your workstations. Some of these scripts, such as convenient aliases or a git color prompt script, have to be run each time you start your shell; others only have to be accessible from the PATH. Both cases are covered by this trick.

But first, you should read Part 0, if you haven’t done so already.

One-time set-up

  • Create a folder called bash inside your ~/Dropbox/config.
  • Create two subfolders: scripts and session.
    scripts will contain the scripts that need to be on the PATH; session will contain the scripts that have to run each time you open up a terminal.
  • Create the file in ~/Dropbox/config/bash. (Indeed; it shouldn’t be in scripts or session!) Make it executable. Its contents should be as follows:
  # Add the following line to ~/.bashrc:
  # . /path/to/this/script/ script_folder
  # For example:
  # . ~/Dropbox/config/bash/ session
  # Don't forget the dot!

  for f in `dirname ${BASH_SOURCE[0]}`/$1/*; do
    . $f

This file will iterate over all the files in the given directory; in this case, ~/Dropbox/config/bash/session/*, and execute them.

  • Finally, create a file called in the ~/Dropbox/config/bash/session folder. Again, don’t forget to make it executable. It should contain the following one-liner:
export PATH=$PATH:\`dirname ${BASH_SOURCE[0]}\`/../scripts

… which is how ~/Dropbox/config/bash/scripts/ ends up on the PATH.

Per computer set-up

On each computer, you need to add the following line to the end of your ~/.bashrc to make it all work:

. ~/Dropbox/config/bash/ session

Don’t forget the dot! It won’t work without it. And that’s all!


Comments from before

Hey, this is pretty cool when you have more than one Unix to work on. :)
Jan Ouwens
It is, isn't it!

BTW, I'm pretty sure you can make the git color prompt thingy in my next post work for HG as well :).
Actuallty, I'm now working with Bazaar. Which calls itself "bzr" on the command-line. Yeah, you've read it right. I keep an eye out for Mango as well, I'm pretty sure they are both following me...

Leave a Comment