From 56865870eced12c45891e46f8f93a71381452a6e Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Mon, 7 Feb 2022 20:14:24 +0100 Subject: [PATCH] install: convert to tabstop = 2 --- install.sh | 200 ++++++++++++++++++++++++++--------------------------- 1 file changed, 98 insertions(+), 102 deletions(-) diff --git a/install.sh b/install.sh index e8f0a38..0ed1276 100755 --- a/install.sh +++ b/install.sh @@ -9,59 +9,59 @@ GIT_USER="${GIT_USER:-Fernando Schauenburg}" GIT_EMAIL="${GIT_EMAIL:-fernando@schauenburg.me}" main() { - IS_DRY_RUN=yes - while getopts 'fht:' opt; do case "$opt" in - f) unset IS_DRY_RUN;; - t) TARGET="$OPTARG";; - h) usage; exit 0;; - *) usage; exit 1;; - esac done + IS_DRY_RUN=yes + while getopts 'fht:' opt; do case "$opt" in + f) unset IS_DRY_RUN;; + t) TARGET="$OPTARG";; + h) usage; exit 0;; + *) usage; exit 1;; + esac done - check_dependencies - greeting - make_dirs - stow_home - link_config - git_user_config - nvim_plugins + check_dependencies + greeting + make_dirs + stow_home + link_config + git_user_config + nvim_plugins } check_dependencies() { - for cmd in stow readlink; do - if ! command -v "$cmd" >/dev/null 2>&1; then - error "Dependency \`$cmd\` not found." - exit 1 - fi - done + for cmd in stow readlink; do + if ! command -v "$cmd" >/dev/null 2>&1; then + error "Dependency \`$cmd\` not found." + exit 1 + fi + done } greeting() { - dry_run && { - warn "Performing dry run (use -f to actually make changes)." - warn - } + dry_run && { + warn "Performing dry run (use -f to actually make changes)." + warn + } - info "Deploying dotfiles:" - info " Source: $cyan$DOTFILES$rst" - info " Target: $cyan$TARGET$rst" - info " Git user: $yellow$GIT_USER <$GIT_EMAIL>$rst" + info "Deploying dotfiles:" + info " Source: $cyan$DOTFILES$rst" + info " Target: $cyan$TARGET$rst" + info " Git user: $yellow$GIT_USER <$GIT_EMAIL>$rst" - if [ -t 0 -a -t 1 ]; then - info - info "Press ENTER to continue (CTRL-C to cancel)..." - read k - fi + if [ -t 0 -a -t 1 ]; then + info + info "Press ENTER to continue (CTRL-C to cancel)..." + read k + fi } make_dirs() { - heading 'create auxiliary directories' - while read item; do - dir="$TARGET/$item" - if [ ! -d "$dir" ]; then - echo "${yellow}MKDIR:$rst $dir" - dry_run || mkdir -p "$dir" - fi - done <$rst $dotfiles_config" - dry_run || ln -s "$dotfiles_config" "$link" + if [ "$(readlink "$link")" != "$dotfiles_config" ]; then + if [ -d "$link" ]; then + echo "${red}WARNING:$rst moving existing '$link' to '$backup'" + dry_run || mv "$link" "$backup" fi + + echo "${yellow}LINK:$rst $link $blue=>$rst $dotfiles_config" + dry_run || ln -s "$dotfiles_config" "$link" + fi } stow_home() { - heading 'stow home directory' - stow -v${IS_DRY_RUN:+n} --no-folding -d "$DOTFILES" -t "$TARGET" home 2>&1 \ - | sed -E -e "s/^([^:]+:)/$yellow\1$rst/" -e "s/=>/$blue=>$rst/" + heading 'stow home directory' + stow -v${IS_DRY_RUN:+n} --no-folding -d "$DOTFILES" -t "$TARGET" home 2>&1 \ + | sed -E -e "s/^([^:]+:)/$yellow\1$rst/" -e "s/=>/$blue=>$rst/" } git_user_config() { - heading 'git user configuration' - config_file="$TARGET/.local/etc/git/config.user" - temp_git="$(mktemp)" - cat >"$temp_git" <"$temp_git" </dev/null 2>&1; then - if [ -f "$config_file" ]; then - action=OVERWRITE - else - action=CREATE - fi - echo "$yellow$action:$rst $config_file with contents of $temp_git:" - echo "$cyan" - cat "$temp_git" - echo "$rst" - dry_run || cp -f "$temp_git" "$config_file" - fi + if ! diff "$config_file" "$temp_git" >/dev/null 2>&1; then + if [ -f "$config_file" ]; then action=OVERWRITE; else action=CREATE; fi + echo "$yellow$action:$rst $config_file with contents of $temp_git:" + echo "$cyan" + cat "$temp_git" + echo "$rst" + dry_run || cp -f "$temp_git" "$config_file" + fi } nvim_plugins() { - heading 'nvim plugins' - if command -v nvim >/dev/null 2>&1; then - dry_run || { - warn "installing neovim plugins..." - nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync' - } - else - error "neovim is not installed; skipping plugin installation..." - fi + heading 'nvim plugins' + if command -v nvim >/dev/null 2>&1; then + dry_run || { + warn "installing neovim plugins..." + nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync' + } + else + error "neovim is not installed; skipping plugin installation..." + fi } ############################################################################### @@ -143,31 +139,31 @@ nvim_plugins() { ############################################################################### if [ -t 1 ]; then - rst=$(tput sgr0) - red=$(tput setaf 1) - green=$(tput setaf 2) - yellow=$(tput setaf 3) - blue=$(tput setaf 4) - magenta=$(tput setaf 5) - cyan=$(tput setaf 6) + rst=$(tput sgr0) + red=$(tput setaf 1) + green=$(tput setaf 2) + yellow=$(tput setaf 3) + blue=$(tput setaf 4) + magenta=$(tput setaf 5) + cyan=$(tput setaf 6) else - rst='' - red='' - green='' - yellow='' - blue='' - magenta='' - cyan='' + rst='' + red='' + green='' + yellow='' + blue='' + magenta='' + cyan='' fi dry_run() { [ -n "$IS_DRY_RUN" ]; } usage() { - echo "Usage: $(basename $0) [-h] [-f] [-t ]" - echo "" - echo " -h print this help and exit" - echo " -f modify filesystem rather than dry run" - echo " -t set directory (default: \$HOME)" + echo "Usage: $(basename $0) [-h] [-f] [-t ]" + echo "" + echo " -h print this help and exit" + echo " -f modify filesystem rather than dry run" + echo " -t set directory (default: \$HOME)" } heading() { printf '%s\n' "${blue}===== $1 ==========${rst}"; }