I was recently looking for a solution to backup my configuration files (bash, vim, etc) using GitHub. After some looking around, I’ve compiled a pretty nice project for myself.
First, this script checks dependencies. My dependencies are git, ruby, vim, tree, rake, gem, bundle, and trash. You could check out the code and add any number of dependencies here. Rubygems and bundler are required because the script later installs all gems listed in Gemfile.
Next, the script copies ~/.bashrc to ~/.bashrc.local. This allows you to keep your current bash configuration as a ‘local-only’ config that doesn’t get copied or committed to github.
The script, as I copied most of bootstrap.sh and the rakefile from @gf3, expects the repository to be cloned to ~/.dotfiles. From there, it calls rake.
Rake looks at every file in ~/.dotfiles and copies the corresponding file relatively from ~/ to, essentially, ~/dotfiles-backup/`date`. I recommend first running the backup to make sure your files are properly backed up.
The script then calls ‘bundle install’ to install all gems. It then copies all files from ~/.dotfiles to replace those relative files that were previously backed up from ~/.
The post-install displays a message to remind you to edit .gitconfig and .hgrc.
Because I’ve done some copying and compiling, these are relative close to the three projects in the README for right now.
Here is an excerpt from the README:
$ tree ~/.bash /home/jim/.bash ├── aliases ├── completions ├── completion_scripts │ └── git_completion ├── config ├── functions ├── paths └── prompt
The above files are loaded by
.bashrc. The files are pretty self-explanatory, other than
prompt which colorizes the bash prompt with tweaks for git.
- cd : pushd
- bd : popd
- cd.. | .. : back one directory
- cd… | … : back two directories
- ^ up to five directories
- rm : trash
- GET | HEAD | POST | PUT | DELETE | TRACE | OPTIONS
- sets editor to vim
- sets English/UTF-8
- sets manpager
- sets commands to ignore in history
- sets noclobber (e.g. prevents
cat > IMPORTANT_FILEmistakes )
- sets nocaseglob (e.g.
ls ~/.B*will list contents of
The two functions,
c may not seem like much, but they simplify some commands. For example:
$ md projects; git clone [email protected]:jimschubert/dotfiles.git && cd dotfiles
In the above line,
md will create the projects directory and
cd into it.
c stands for ‘code’ and works like this:
jim at computer in ~ $ pwd /home/jim jim at computer in ~ $ c dotfiles ~/projects/dotfiles ~ jim at computer in ~/projects/dotfiles on master $
You can change it to whatever shortcut and issue
reload, which is also an alias from this setup.
Notice the color scheme and github branch notifications created by ~/.bash/prompt.