Dotfiles: sync your linux configuraiton

Dotfiles are how you personalize and configure your system. Be it your bashrc file where you write your favorite aliases or run scripts, or your program's user configuration.

Instead of reconfiguring each of your machines independently, you could manually copy all dotfiles from one to another. Or... you could sync your dotfiles to github and use this simple script to link them in place.

Fast installation: recommended

This is the fastest option. You can get a copy of my dotfiles from github, simply clone this repository in any folder you want to store your dotfiles and run the bootstrap
script. I recommend clonning the repository into ~/.doftiles.

$ git clone ~/.dotfiles     # clone in ~/.dotfiles
$ cd ~/.dotfiles                                                          # cd to new folder
$ chmod +x ./bootstrap                                                    # make script executable
$ ./bootstrap                                                             # run script

Forked installation: sync your own dotfiles with github

Alternatively, if you wish to sync your dotfiles to github (in case you want to sync several machines), do the following:

"FORK" this repository on github. If you don't know what forking is, it basically creates a separate copy of a git project that does not sync with the original, but with itself instead. That is, you get a copy of my dotfiles on your github repository that you can change and update at your will. 
Then simply open up your favourite terminal an run clone your own repository. You need to replace "YOURGITHUBUSER" and enter the correct url to your forked project (you can find this info inside your github).

$ git clone ~/.dotfiles   # clone in ~/.dotfiles
git clone ~/.dotfiles # clone your dotfiles
cd ~/.dotfiles                                                          # cd to new folder
chmod +x ./bootstrap                                                    # make script executable
./bootstrap                                                             # run script

Now, if you want to update changes to your own dotfiles on github:

$ git clone ~/.dotfiles   # clone in ~/.dotfiles
cd ~/.dotfiles                                                          # cd to dotfiles folder
git add .                                                               # add changes
git commit -m "WRITE YOUR COMMENT HERE"                                 # commit changes
git push                                                                # run script

How to configure your dotfiles

In six simple steps you will be set up!

Because I know you wont read this ;) simply check out my configuration files and how I use them. Note that dell and light are the name of some of my machines.

When referring to the dotfile/ folder, it will be located wherever you have cloned this repository, which will be (if you did the fast installation) in ~/.doftiles. ~ denotes your user's home folder. For example /home/john/.dotfiles/

  1. Copy all files you want to symlink: copy them into dotfiles/symlink/. You may create subfolders as required

  2. Configure your symlinks: go to dotfiles/configuration/ and create a file named either default.conf or alternatively YOUR-HOSTS-NAME.conf.
    Dotfiles will always look for a configuration file with the same name as the hosts, and if it finds none it then looks for a default configuration file.

  3. Include additional configuration files: inside your main configuration file (created in step 2) you may add other configuration files using the include directive. You may specify a full path to the configuration path relative to dotfiles/configuration/.

  4. Create symlinks: simply write inside your configuration, in one line, where to create the symlink (full path) and which file to symlink to (path relative to dotfiles/symlink/).

  5. Execute bootstrap: the script may prompt you if any conflict is detected.

  6. Optionally create a backup of your dotfiles: either by pushing your fork to github or by simply copying your doftiles folder to a secure place. 

File and folder structure

  • this is the core of any dotfiles implementation. This script is in charge of linking all your actual dotfiles in place where the system expects to find them.

  • /configuration: searches for configuration files inside this folder. It will first search for a file with the same name as the host you are on, and if not found, it will search for a configuration file named default.conf. This is useful when you want slightly different configurations for different machines. Note that configuration files can "include" other configuration files for greater flexibility.

  • /symlink: store all dotfiles you want to be symlinked in this folder. All configuration files use these folder as symlink root.

  • /functions/: this folder contains some bash functions I like carrying arround, like for example colorizing your bash promt. You might delete the whole folder if you dont want it.

Special thanks

I used to fork [Zach Holman](' excellent [dotfiles]( in the past. But after some time following his example, I wrote my won implementation to better fit my own needs inspiring myself on his code.

I really liked the way how he prompted the user, so I learned how he did it from his source code and implemented it in this dotfile script.

No comments :

Post a Comment