#!/usr/bin/env bash # # Install and setup dotfiles. # # Copyright (C) 2022 Rafael Cavalcanti # Licensed under GPLv3 set -euo pipefail readonly remote_repo="https://github.com/rc2dev/dotfiles.git" readonly local_repo="$HOME/.local/share/dotfiles/repo.git" readonly tmp_dest="$HOME/.dotfiles_tmp" log() { printf "%s\n" "$*" 1>&2 } if [[ ! -d "$local_repo" ]]; then mkdir -p "$(dirname "$local_repo")" # Clone first to a temporary dir, or git will fail on a non-empty home. git clone --separate-git-dir="$local_repo" "$remote_repo" "$tmp_dest" rsync --recursive --links --exclude '.git' "$tmp_dest/" "$HOME/" rm --recursive "$tmp_dest" fi export GIT_DIR="$local_repo" export GIT_WORK_TREE="$HOME" cd "$HOME" # To hide README and LICENSE log "Setting sparse checkout..." git config core.sparseCheckout true git sparse-checkout set '/*' '!/README.md' '!/LICENSE' log "Running workaround if sparse checkout failed..." git read-tree -mu HEAD # Necessary if submodule remote url changes log "Syncing submodules if already present..." git submodule sync log "Initializing submodules..." git submodule update --init --recursive # Needed for vim-fugitive's command log "Setting worktree..." git config core.worktree "$HOME" log "Setting path for repository config..." git config include.path ~/.config/dotfiles/config case $(hostname) in rd|x220) log "Enabling system user units for rd or x220..." systemctl --user enable ssh-agent.service ;; esac