Move All Dotfiles Out of Root Directory
Asked Answered
S

2

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.

Squalor answered 28/6, 2015 at 19:13 Comment(4)
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/.<program>. Trying to subvert this is pushing a big stone uphill for no immediately obvious benefit.Mirza
@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.Squalor
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!Mirza
@NormanGray: Instead of linking them one by one, you can use something like homesick gem. It manages the git repo, and handles links for you.Tomtom
F
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
Frisbie answered 26/11, 2015 at 17:23 Comment(2)
I recently found an article that does exactly this: atlassian.com/git/tutorials/dotfilesSqualor
@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.Antispasmodic
W
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

Wasting answered 11/10, 2016 at 4:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.