7 ms·
Call me old fashioned but what's wrong with having a regular git repo anywhere you want with all of your dotfiles and them symlink those files to where they nee
by nickjj 6y ago
Call me old fashioned but what's wrong with having a regular git repo anywhere you want with all of your dotfiles and them symlink those files to where they need to go?
If you wanted to you could && a few symlinks and other commands into 1 copy / paste'able command to get up and running really quickly. It's also painless to manage secrets by sourcing in optional files. It also works nicely when you want files living across 2 systems (such as WSL 2 and Windows) where on a Windows box you consider certain Windows files dotfiles even though technically they exist elsewhere.
I've been managing my dotfiles like this for a few years and it seems to be working out well not just for myself but others who have want to use them either partially or in full. I open sourced them here: https://github.com/nickjj/dotfiles https://github.com/nickjj/dotfiles
I purposely broke up some of the commands because I know that not everyone will want a 100% replica of my dotfiles. Folks copy / paste only the commands they want.
- hxegon 6y agoThat's pretty much what this is. I have a git repo with one dir for everything that needs configuration. Whenever I spin up a vps/vm or what have you, git clone dotfiles; cd dotfiles and stow what I'm using on that machine. stow links based on the directory structure of the folder you're calling, so I don't have to worry about where things are, just stow fish; stow nvim There's no symlink script or adapter script to work with stow, everything 'just works' for me.
- ironmagma 6y agoNot sure if Stow fixes these, but here are some problems I've had with that setup: 1. If you want to delete a file, you have to delete it (rm) in one place and delete it another way in another place (git rm). 2. Adding a new file in-situ (in the home directory) requires some finessing to get it back into the git repo and symlinked properly. 3. No easy way to apply a rename operation. 4. After changing the checked out branch, there is no easy way to apply these changes to the home directory.
- cipherboy 6y ago> and delete it another way in another place (git rm). I use `rm` all the time in git repos... Just `git add` when it is time to stage changes.
- ironmagma 6y agoRight, but when you unlink it from your home directory, the file still exists in the git repo. So there is a manual synchronization that must happen between the two directories.
- coldtea 6y ago>Right, but when you unlink it from your home directory, the file still exists in the git repo. That's a feature.
- ironmagma 6y agoNot when you are looking for a workflow to make dealing with dotfiles faster and more painless. With the current (symlink based) setup, there is a hidden state you must hold in your head or else carefully inspect: the discrepancy between your git repo and your home directory. Maybe you forgot to link a dotfile, and that’s why your latest configuration doesn’t work. Ditto for unlinking a dotfile.
- Galanwe 6y agoIsn't that what -D, -S, and more simply -R do? I did not use stow 2.x, but my understanding is that running stow -R will allow you to remove previous dangling symlinks (during the unstow) and add missing symlinks (during the restow). Effectively allowing you to only manage a single state: your git repository.
- kelnos 6y agoI delete dotfiles so infrequently (once a year?) that this just isn't a problem for me. I also don't have all dotfiles under version control, just the ones I've essentially "built myself", so maybe that makes it easier.
- ljm 6y agoIf all your configs follow the XDG spec then you can turn ~/.config itself into the repo,and then use .gitignore as a whitelist: /* !git/config !tmux/tmux.conf I do this and clone my repo directly to .config on a new machine. The only hold out was tmux but that's solved by installing or compiling one of the recent versions released this year (3b/3c). I'll still use manual symlinks for things like bash, but they're outliers. Works great for me.
- midchildan 6y agoI believe Stow can fix everything except #2 [1], although I haven't actually used it before. But it's also easy to create your own "garbage collector" that cleans up dangling symlinks in your home directory. All you need to do is to keep track of symlinks you've installed with your setup script. This can be done by creating a symlink to the symlink you've installed, which acts as a "GC root." The next time you run the setup script, it would check those "GC roots" to see if they point to a valid file and remove any dangling symlinks. This is the approach I take for my own dotfiles. I seriously considered using Stow or the bare git approach before, but I decided against it because setting up my dotfiles involved more than just installing symlinks. I had to be able to download files (e.g., vim-plug), clone git repositories, change file permissions, and maintain files that's not meant to be linked into the home directory. I found the flexibility of a custom shell script most fit for my needs. [1]: The "Deleting Packages" section in https://linux.die.net/man/8/stow https://linux.die.net/man/8/stow
- db48x 6y ago> and then symlink those files to where they need to go? This is exactly what Stow does.
- rubyist5eva 6y agoStow does this, it also has a --dotfiles switch so you can save your files as `dot-vimrc`, `dot-bashrc`, etc... so you don't have a bunch of hidden files in your repo
- bbkane 6y agoToo bad that's broken for directory names: https://github.com/aspiers/stow/issues/33 https://github.com/aspiers/stow/issues/33
- adamspiers 6y agoStow maintainer here. Thanks for the nudge on that, and apologies for not doing a better job. I hadn't noticed that this issue affecting so many users. I have some downtime in the coming week or two so will look at this.
- bbkane 6y agoThank you! That fix will make my dotfiles repo look a lot nicer :)
- coldtea 6y ago>Call me old fashioned but what's wrong with having a regular git repo anywhere you want with all of your dotfiles and them symlink those files to where they need to go? Well, that's what you end up with. Stow just automates the "symlink those files part".
- kevin_thibedeau 6y agoMore importantly, Stow can intelligently convert a symlinked directory into a real one when a second package wants to share it.
- deleted 6y ago[deleted]
- tmpxgdqrcKFuG 6y agoYeah, I set it up with the Atlassian tutorial, https://www.atlassian.com/git/tutorials/dotfiles https://www.atlassian.com/git/tutorials/dotfiles, and store it in a git repo in Keybase.io
- kenrose 6y agoCall me old fashioned, but I remember using stow in 2003/2004, about a year before git existed. Yes though, use a repo for sync, but stow takes care of at linking your dot files in the right place.
- michaelpb 6y agoThat's what I do too. I even made a little Stow-inspired tool to help me, called "stowage", if you are curious: https://github.com/michaelpb/stowage https://github.com/michaelpb/stowage
- tambourine_man 6y agoI still remember when git was the hot new version control system, so old fashioned sounds funny to me.
- tpoacher 6y agoI had the same reaction. Stow was first released (v>1.0) in 1996, git in 2013. Yet git is the old-fashioned choice? hahah.
- gumby 6y agoYeah, the command is literally (cd ~; ln -s source-location/{.,}[A-z]* .) which is a lot easier than installing all that stuff.
- LucasLarson 6y agoIf we’re codegolfing dotfile setup, then really go crazy: `cd; ln -s source-location/{.,}[A-z]* .`
- JoshTriplett 6y ago> Call me old fashioned but what's wrong with having a regular git repo anywhere you want with all of your dotfiles and them symlink those files to where they need to go? I prefer to skip the symlinks, and just directly use the git repository as my home directory. (I have a sizable .gitignore for things I don't want to track.)
- yesbabyyes 6y agoI do the same, but I just have a single '*' in my .gitignore. The only drawback to the homedir-as-git-repo approach I've found is that you're always in a git repo, so you have to be careful not adding stuff which was really supposed to go in another repo.
- scaladev 6y agoHere's a better solution. https://www.atlassian.com/git/tutorials/dotfiles https://www.atlassian.com/git/tutorials/dotfiles TL;DR: alias dotfiles='/usr/bin/git --git-dir=$HOME/src/dotfiles --work-tree=$HOME' dotfiles add dotfiles commit ...
- StavrosK 6y agoI really like that solution, thanks. It also means I can easily move my current git dir to the new place and still have everything work. Does anyone know if syncing a git repo over Syncthing (or similar) is a good idea or whether there are likely to be conflicts? I don't know if git names its files such that conflicts aren't possible.
- yesbabyyes 6y agoBrilliant, thanks!
- JoshTriplett 6y ago> The only drawback to the homedir-as-git-repo approach I've found is that you're always in a git repo, so you have to be careful not adding stuff which was really supposed to go in another repo. I tend to always run "git status" before adding anything, which makes it fairly obvious what repository I'm in. (Or I'm working via fugitive in vim, which helps in the same way.)
- devy 6y ago> but what's wrong with having a regular git repo anywhere you want with all of your dotfiles and them symlink those files to where they need to go? Nothing wrong with tracking dotfiles with Git. It's probably the simplest and easiest approach without requiring any fancy tools other than Git. However, as mentioned in ArchLinux's wiki page, the disadvantage of Git approach is that "host-specific configuration generally requires merging changes into multiple branches."[1] [1]: https://wiki.archlinux.org/index.php/Dotfiles#Tracking_dotfiles_directly_with_Git https://wiki.archlinux.org/index.php/Dotfiles#Tracking_dotfi...
- deleted 6y ago[deleted]
- mssundaram 6y ago> If you wanted to you could && a few symlinks and other commands into 1 copy / paste'able command to get up and running really quickly Exactly! I do exactly that. I have an install.sh script that simply iterates over the files and directories in my dotfiles repo and does mkdir and ln
- freeCandy 6y agoI've been using bashdot(https://github.com/bashdot/bashdot https://github.com/bashdot/bashdot) does exactly this. It's a simple bash script that sets up symlinks for a given directory. It can also switch symlinks to different directories, so you could use that as swappable profiles.