#!/usr/bin/env bash ############################################################################### # Install dotfiles as a bare git repository. Conflicting files found during # # installation are moved to $HOME/dotfiles.backup. # # Dependencies: git # ############################################################################### set -o errexit export GIT_WORK_TREE="$HOME" export GIT_DIR="$GIT_WORK_TREE/.dotfiles" backupdir="$GIT_WORK_TREE/dotfiles.backup" repository="https://github.com/potamides/dotfiles.git" exclude=(".gitmodules" "README.md" "LICENSE" ".local/bin/install-*") function clone(){ cd "$GIT_WORK_TREE" git clone --bare "$repository" "$GIT_DIR" } function backup(){ for file in $(git ls-tree -r --name-only HEAD); do if [[ -e "$file" ]]; then mkdir -p "$backupdir" mv "$file" "$backupdir" fi done } function install(){ git checkout git submodule update --init git config status.showUntrackedFiles no git config core.worktree "$GIT_WORK_TREE" git config alias.edit '!env -C "${GIT_PREFIX:-.}" $EDITOR' git sparse-checkout set "*" "${exclude[@]/#/\!}" --no-cone } clone backup install