Using bash to automate dotfiles

I want to create my own automatic dotfiles folder. (I will use git to use version control on my dotfiles, but that doesn't matter for the question)

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

I would also appreciate the following features, if possible.

  • Folders are associated only with a small link
  • My files may be in the dotfiles folder without the actual dot in the file name (e.g. ~/dotfiles/vimrc , rather than ~/dotfiles/.vimrc )
  • It should be able to ignore some files, such as my .git file, which is stored in the same folder.

Of course, if you already know the service that provides this, it is at least as good as providing some do-yourself commands. Please note that I specifically want it to be bash or something that most likely exists on all unix machines (so I think that commands using g ++ are fine).

+6
unix bash dotfiles
source share
5 answers

Try:

 ln -s ~/dotfiles/* ~ 

A loop should not be necessary. Of course, you can use find if you need something recursive.

Edit:

To make destination files hidden:

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

I'm not sure if I ask the question correctly, but if you are looking for symbolic links to dir content, try

 for f in `ls -1 .dotfiles` do ln -s .dotfiles/$f ~/$f done 

maybe it already does the trick

0
source share

For managing dotfiles, I really like Zach Holman's approach. I did the same with my points, which you can find here :)

https://github.com/rhacker/dotFiles

0
source share

Perhaps you are looking for a dotfiles manager, I recommend you check out the DFM (dotfiles manager). DFM solves the problem you have in a very clean way:

0
source share

Atlassian has a tutorial on using the git working tree instead of symbolic links . This approach uses:

  • the bare git repository in the side folder (e.g. $HOME/.cfg or $HOME/dotfiles ) and
  • a config bash alias for executing git commands that manage configuration files.

For example, you can run config status to check which files have changed, config checkout to get files in the repository, and config commit to update the repository. This requires only git and bash .

0
source share

All Articles