7

I'm am running macOS Sierra, and am in the process of moving all dotfiles into one directory. I have successfully exported many environment variables for various installations (vagrant, composer, oh-my-zsh etc) that allow me to install to a sub-directory of my choice.

Unfortunately, programs like npm, subversion, homestead, git, and others do not offer such configurations.

Dov Benyomin Sohacheski
  • 7,133
  • 7
  • 38
  • 64
  • 1
    Why are you trying to do this? It is a _very_ long standing unix convention (3 or 4 decades) that programs expect a configuration file or directory in `$HOME/.`. Trying to subvert this is pushing a big stone uphill for no immediately obvious benefit. – Norman Gray Jun 28 '15 at 20:15
  • @NormanGray Today, there are far more programs than before, completely bloating the `$HOME` directory. I want to keep all my settings and configurations in source control. – Dov Benyomin Sohacheski Jun 29 '15 at 13:12
  • I'd agree that keeping these files in source control is a reasonable goal. `rcs` might be the right tool for that, since it stores revisions 'in place'. Myself, I keep a few key dotfiles in a separate repository and link to them one by one from `$HOME`. I think there's no general solution. One possibility would be to redefine `$HOME` in a shell startup script, but that won't be bulletproof and _will_ have other consequences! – Norman Gray Jun 29 '15 at 14:05
  • 1
    @NormanGray: Instead of linking them one by one, you can use something like [homesick gem](https://github.com/technicalpickles/homesick). It manages the git repo, and handles links for you. – Amadan May 09 '16 at 07:51

2 Answers2

5

I use a dotfiles repository, where I keep my configuration files under git. The idea is not new. What I did is move them to another directory and them create a symlink to them in the home directory. It does not clean the home directory as you wanted, since it's the standard place for configuration files, as stated by Norman Gray, but at least you can version them and share them across machines.

Example:

cd ~
mkdir dotfiles
mv .gitconfig dotfiles/.gitconfig
ln -s ~/dotfiles/.gitconfig ~/.gitconfig
Community
  • 1
  • 1
Matjaž
  • 292
  • 6
  • 14
  • I recently found an article that does exactly this: https://www.atlassian.com/git/tutorials/dotfiles – Dov Benyomin Sohacheski Jul 29 '20 at 07:37
  • @DovBenyominSohacheski The article you linked is useful, but I believe the approach is different from @Matjaž's. Correct me if I'm wrong, but in your linked article, the `.cfg` file has set as its `--work-tree` the `$HOME` directory, where as in @Matjaž's post we're creating symlink in the `$HOME` directory to the config file where the work-tree is. – jimmy Aug 17 '22 at 14:37
3

Check out stow. That's what I use.

I have a ~/dotfiles/ directory which has folders in it like vim/ X/, etc.

Now for example vim/ will have a .vimrc file in it, and from ~/dotfiles I can run stow vim/ and it will automatically manage the symlinks to the home directory.

I can also run

cd ~/dotfiles
for folder in ./
  do [[ -d $folder ]] && stow -R $folder
done

To update all my dotfiles (the -R deletes old symlinks that don't exist anymore)

There is a good introduction here: http://brandon.invergo.net/news/2012-05-26-using-gnu-stow-to-manage-your-dotfiles.html

Radvendii
  • 41
  • 3