#!/bin/sh set -eu DRY_RUN=false DEFAULT_GIT_USER="Fernando Schauenburg" DEFAULT_GIT_EMAIL="fernando@schauenburg.me" XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" DOTFILES_DIR="$(dirname "$(realpath "$0")")" DIRS=$(cat < $target" $DRY_RUN || rm -f "$1" fi ;; esac fi } file_link() { # Make sure $1 is a link to $2. target="$(realpath "$2")" if [ "$(readlink "$1")" = "$target" ]; then info "OK: $1" else warn "linking $1 -> $target" $DRY_RUN || ln -sf "$target" "$1" fi } file_content() { # Ensure $1 and $2 contents are equal, updating $1 if needed. if diff "$1" "$2" >/dev/null 2>&1; then info "OK: $1" else warn "overwriting $1 with $2:" cat "$2" $DRY_RUN || cp -f "$2" "$1" fi } task_gather_user_info() { heading "Gather user information" printf 'git name [%s]: ' "$DEFAULT_GIT_USER" read -r git_user printf 'git e-mail [%s]: ' "$DEFAULT_GIT_EMAIL" read -r git_email } task_remove_bash_profile() { heading "Remove pre-installed bash profile" for f in .bash_logout .profile; do file_absent "$HOME/$f" done } task_ensure_directories() { heading "Ensure existence of directories used by dotfiles" echo "$DIRS" | while read -r d; do directory_present "$d"; done } task_link_dotfiles() { heading "Link dotfiles" echo "$DOTFILES" | while read -r dest src; do file_link "$src" "$dest" done } task_deploy_templates() { heading "Deploy templates" temp_git="$(mktemp)" cat >"$temp_git" </dev/null 2>&1; then warn "Installing neovim plugins" $DRY_RUN || nvim -nes -u "$XDG_CONFIG_HOME/nvim/init.vim" -c 'PlugInstall | qall!' else error "neovim is not installed; skipping plugin installation..." fi } main() { $DRY_RUN && warn "Dry run: no changes will actually be made." task_gather_user_info task_remove_bash_profile task_ensure_directories task_link_dotfiles task_deploy_templates task_prune_broken_bin task_link_local_bin task_link_dircolors task_make_logins_silent task_install_nvim_plugins } main