DEV Community

Discussion on: How Do You Manage Dotfiles Across Environments and Machines

Collapse
 
autoferrit profile image
Shawn McElroy

I use stow. I have a repo where each folder in there, is a configuration for some thing. Like zsh, bash, vim, tmux, etc. Then I have a setup script that runs stow on everything i want to run it on. I also have a flag in there so if I run it as root, it installs only what root needs.

setup.sh

#!/usr/bin/env bash

git submodule init
git submodule update

base=(
    alacritty
    bash
    bin
    calcurse
    config
    gemrc
    nvim
    python
    ranger
    termite
    tmux
    trizen
    vifm
    w3m
    xonsh
    Xresources
    zsh
)

useronly=(
    cvim
    dunst
    fonts
    getkeys
    git
    gtk
    hyper 
    i3
    mpd
    mpv
    ncmpcpp
    node
    polybar
    rofi
    sxhkd
    sxiv
    transmission
    zathura
)

stowit() {
    usr=$1
    app=$2
    stow -v -R -t ${usr} ${app}
}

echo ""
echo "Stowing apps for user: ${whoami}"

for app in ${base[@]}; do
    stowit "${HOME}" $app 
done

for app in ${useronly[@]}; do
    if [[ ! "$(whoami)" = *"root"* ]]; then
        stowit "${HOME}" $app 
    fi
done

echo ""
echo "##### ALL DONE"

and each of those names like tmux is a folder in my repos dir. and when I install them I default to my home directory. so the command that is run equates to stow -v -R -t ${HOME} tmux for example. And the directory structure for each folder is like so:

 tmux
 ├── .tmux
 │  ├── .git
 │  ├── .tmux.conf
 │  ├── .tmux.conf.local
 │  ├── LICENSE.MIT
 │  ├── LICENSE.WTFPLv2
 │  └── README.md
 ├── .tmuxp
 │  ├── cs.yaml
 │  ├── rsk.old.yml
 │  └── rsk.yml
 ├── .tmux.conf
 └── .tmux.conf.local

so that will link the .tmux directory, into my $HOME directory. tmuxp is a python binary for managing preset tmux pane configs, like tmuxinator.

Lastly, in my .bashrc and .zshrc (i default to zsh) I check if the file $HOME/.env_secrets is available which will have api keys, and other secret keys and it NOT kept in git. This way i can manage secrets, db connections, etc. I would link mine, but it has stuff in it I dont want public. but if theres any part of the config you want to know about, just let me know.

I also have a _setup directory that has anything specific i want to run based on OS. such as installing applications. I run arch so I have a arch_setup.sh and an osx_setup.sh for installing things in homebrew. though that one is pretty out of date since i haven't updated it for osx in a while. As i have been using linux.

Now that I think about it, might be a good post to talk about how I have this setup. lol

One last thing, in the start of the setup script I make sure to get any submodules so I can pull in tmux/nvim configs I use that others make. that way I can still use them without maintaining them.

Collapse
 
moopet profile image
Ben Sinclair

Stow is great.

Collapse
 
rpalo profile image
Ryan Palo

Wow! There is a lot here. Thank you! I haven’t even heard of stow, I’ll look into it. Thanks for such a detailed answer!

Collapse
 
autoferrit profile image
Shawn McElroy

Of course. This "how to manage dotfiles" is a path I have treaded off an on for a long time. I have went through a handful of iterations. Sure there are tools out there that give you command line binaries to add/remove things in your env, but I found that they tend to over complicate things.