DEV Community

Waylon Walker
Waylon Walker

Posted on • Originally published at waylonwalker.com

2 minutes to stow

Stow is an incredible way to manage your dotfiles. It works by managing symlinks between your dotfiles directory and the rest of the system. You can then make your dotfiles directory a git repo and have it version controlled. In my honest opinion, when I was trying to get started the docs straight into deep detail of things I frankly don't really care about and jumped right over how to use it.

When using stow its easiest to keep your dotfiles directory (you may name it what you want) in your home directory, with application directories inside of it.

Then each application directory should reflet the same diretory structure as you want in your home directory.

zsh

Here is a simple example with my zshrc.

mkdir ~/dotfiles cd ~/dotfiles mkdir zsh mv ~/.zshrc zsh stow --simulate zsh
Enter fullscreen mode Exit fullscreen mode

You can pass in the --simulate if you wish, it will tell you if there are going to be any more errors or not, but it wont give much more than that.

WARNING: in simulation mode so not modifying filesystem.
Enter fullscreen mode Exit fullscreen mode

Once your ready you can stow your zsh application.

stow zsh
Enter fullscreen mode Exit fullscreen mode

nvim

A slightly more complicated example is neovim since its diretory structure does not put configuration files directly in your home directory, but rather at a deeper level.

mkdir ~/dotfiles/nvim/.config/nvim/ -p cd ~/dotfiles mv ~/.config/nvim/ ~/dotfiles/nvim/.config/nvim/ stow zsh
Enter fullscreen mode Exit fullscreen mode

!notice how the nvim directory inside of dotfiles is structured like it would
be in your $HOME directory.

Top comments (4)

Collapse
 
grendel profile image
grendel

i just have my ~/.dot repository mirror the directory structure that it's supposed to have from $HOME, and run this script after i git pull (which i just realized i can invoke via post-merge git hook):

#!/bin/bash

cd "$(dirname -- "$0")"

warn="\033[33;1m"   # Bold Yellow
new="\033[32;1m"    # Bold Green
plain="\033[0m"     # Reset text style
cols=$(tput cols)


puts() {
    local -n color=$1; shift
    printf -- '%b%s%b\n' "$color" "$*" "$plain"
}


find . -type f \
        -not -name "$(basename -- "$0")" \
        -and -not -regex '.*/\(stay\|\.git\).*' \
        -printf '%P\n' \
        | while IFS= read -r file
do
    dest="$HOME/$file"

    mkdir -p -- "${dest%/*}" || continue

    if [[ ! -f $dest ]]; then
        puts new 'Creating $dest...'
        ln -- "$file" "$dest"
        continue
    fi

    if diff -- "$file" "$dest" >/dev/null; then
        ln -f -- "$file" "$dest"
        continue
    fi

    msg="- Updates to $file "
    printf -v bar '%*s' $(( cols - ${#msg} ))
    puts warn "$msg" "${bar// /–}"

    diff --color -u3 -- "$dest" "$file"

    printf %b "$warn"
        printf -v bar '%*s' $cols; printf '%s\n' "${bar// /_}"
        ln -i -- "$file" "$dest"
    printf %b "$plain"
done
Enter fullscreen mode Exit fullscreen mode

note: i also have a ~/.dot/stay directory, where i put things that i don't want to hardlink to anywhere

Collapse
 
shirobachi profile image
Shirobachi

O heard about this but I prefer bare repo, you may want Google this C:

Collapse
 
waylonwalker profile image
Waylon Walker

bare repos work as well. This is much easier for me.

Collapse
 
pandademic profile image
Pandademic

wow! that's cool