From a2d62b670d4fb61b92efd77d60b8a0b8a68250d7 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 6 Oct 2017 12:13:19 +0200 Subject: [PATCH] bootstrap & clean scripts: minor refactor --- bootstrap | 17 ++++++++++------- clean | 12 +++++++++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/bootstrap b/bootstrap index 483c6ef4..032560c2 100755 --- a/bootstrap +++ b/bootstrap @@ -7,10 +7,14 @@ # 2. run $topic/install the first time # 3. run $topic/update on consecutive runs +CWD="$(cd "$(dirname "$0")" && pwd)" +pushd "$CWD" >/dev/null set -e -source "$(cd $(dirname $0) && pwd -P)/shell/common.sh" shopt -s nullglob +# shellcheck source=shell/common.sh +source "shell/common.sh" + # blue="\033[34m" magenta="\033[35m" @@ -22,7 +26,7 @@ nc="\033[0m" # _run() { - local cmd="${@//$DOTFILES\//}" + local cmd="${*//$DOTFILES\//}" cmd="${cmd//$HOME/~}" local clr="" case $cmd in @@ -40,7 +44,7 @@ _link() { if [[ $yes ]]; then [[ $yes = 1 ]] && choice=y || choice=n else - read -n 1 -p "? ${1##*/} exists in $2 -- overwrite? [y/n] " choice + read -r -n 1 -p "? ${1##*/} exists in $2 -- overwrite? [y/n] " choice echo fi case $choice in @@ -57,6 +61,7 @@ _link() { ## +export SERVER= install=1 link=1 update=1 @@ -99,10 +104,8 @@ done shift $((OPTIND-1)) # -CWD=$(cd $(dirname $0) && pwd -P) -ENABLED_DIR="$CWD/.enabled.d" -pushd $CWD >/dev/null -for topic in ${@:-$(ls -1 "$ENABLED_DIR" | sed 's%_%/%')}; do +ENABLED_DIR=".enabled.d" +for topic in "${@:-$(ls -1 "$ENABLED_DIR" | sed 's%_%/%')}"; do [[ -d $topic ]] || continue echo -e "${green}${topic}${nc}" diff --git a/clean b/clean index 76d996cf..e0ffbbb1 100755 --- a/clean +++ b/clean @@ -8,7 +8,13 @@ # -d Do a dry run (only output commands, no changes) # -u Uninstall all enabled topics -_run() { [[ $DRYRUN ]] && echo "$@" || $@; } +_run() { + if [[ $DRYRUN ]]; then + echo "$@" + else + $@ + fi +} uninstall= while getopts du opt; do @@ -24,13 +30,13 @@ shift $((OPTIND-1)) # Remove enabled topics if [[ $uninstall ]]; then - _run rm -v "$(cd $(dirname $0) && pwd -P)"/.enabled.d/* + _run rm -v "$(cd "$(dirname "$0")" && pwd -P)"/.enabled.d/* fi # Remove dead links shopt -s nullglob links=( $HOME/.* $HOME/.*/* ) -for link in ${links[@]}; do +for link in "${links[@]}"; do if [[ -h "$link" && ! -e "$link" ]]; then _run rm -vf "$link" fi