Search code examples
bashunixdotfiles

Using bash to automate dotfiles


I want to create my own automated dotfiles folder. (I'll be using git to use version control on my dotfiles, but that's irrelevant for the question)

What i simply want is to symbolically link all the files and folders in ~/dotfiles to my home folder. Being not good at all with bash I can't do this. Please help me with this.

I would also appreciate the following features if possible.

  • Folders are only shallowly linked
  • My files could be in the dotfiles folder without the actual dot in the file-name (like ~/dotfiles/vimrc rather than ~/dotfiles/.vimrc)
  • It should be able to ignore some files, like my .git file which are stored in the same folder

Of course if you already know a service providing this, that is at least as good as providing some do-myself commands. Note how I specifically want it to be bash or something that most likely exists on all unix machines (so i guess commands using g++ are fine).


Solution

  • Give this a try:

    ln -s ~/dotfiles/* ~
    

    There shouldn't be any need for a loop. Of course, you can use find if you need something recursive.

    Edit:

    To make the destination files hidden:

    for f in ~/dotfiles/*
    do
        ln -s "$f" "$HOME/.${f##*/}"
    done