brisberg / dotfiles

Personal dotfile repository
MIT License
0 stars 0 forks source link

Add /bin directory with dotfiles-sync script #4

Open brisberg opened 2 years ago

brisberg commented 2 years ago

From the work dotfiles, add this to dotfiles/bin/dotfiles-sync

#!/usr/bin/zsh

# Ensure that local dotfiles have not been modified and synchronize them with
# the remote git repo

local error=false

if [[ ! -z $(git -C $DOTFILES status --porcelain) ]]; then
  echo "\033[0;31mError\033[0m: dotfiles has uncommited files"
  error=true
fi

local branch=$(git -C $DOTFILES rev-parse --abbrev-ref HEAD)
if [[ "$branch" != "$HOST_SHORT" ]]; then
  echo "\033[0;33mWarning\033[0m: dotfiles is not on the correct branch. ('$branch')"
  git -C $DOTFILES checkout $HOST_SHORT
fi

if [[ "$error" = false ]]; then
    echo "Syncing main dotfiles..."
    git -C $DOTFILES pull -r
    git -C $DOTFILES push
    sh $DOTFILES/install
    echo "...done"
fi

make sure to chmod +x bin/dotfiles-sync to make it executable, and make sure that the dotfiles bin directory is on the path

brisberg commented 2 years ago

I added the ~/bin directory already. Still need to copy in the dotfiles-sync script