From b1f7cdd3f5ad9350d6a2d6a725ac1274bb19bad0 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Thu, 22 Jul 2021 00:57:07 +0200 Subject: [PATCH] add verbosity control to install script --- install | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/install b/install index 6687991..6387d65 100755 --- a/install +++ b/install @@ -2,12 +2,17 @@ # this script is compatible with following shells: # dash, bash, zsh +VERBOSE=1 + +[ -n "$ZSH_VERSION" -o -n "$BASH" ] || VERBOSE=0 # no colors for you + note() { - printf "%s\n" "$@" + local IFS=" " + printf "%s\n" "$*" } warn() { - printf "%s\n" "$@" >&2 + note "$@" >&2 } die() { @@ -23,7 +28,6 @@ dotless() { else REPLY="$1" fi - #warn "$f -> $REPLY" } backup() { @@ -79,11 +83,11 @@ softlink_pseudo() { if [ -d "$d2" ]; then if [ "$d1" != ".vim/bundle" ]; then # buggy on Windows - #warn $'\e[34m / \e[0m' "$d1 $d2" + [ "${VERBOSE:-0}" -lt 1 ] || warn $'\e[34m / \e[0m' "$d1 $d2" softlink_pseudo "$d1" "$d2" fi elif [ -f "$d2" ]; then - #warn $'\e[34m * \e[0m' "$d1" + [ "${VERBOSE:-0}" -lt 1 ] || warn $'\e[34m * \e[0m' "$d1" hardlink "$d1" "$d2" else die "i don't know how to pseudo-symlink $d2" @@ -104,9 +108,12 @@ find_new_files() { if [ -d "$d2" ]; then find_new_files "$d1" "$d2" elif [ ! "$d1" -ef "$d2" ]; then - #warn "new destination file. consider manually moving it:" - #warn $'\e[32m + \e[0m' "$d1" - warn " + $d1" + if [ "${VERBOSE:-0}" -lt 1 ]; then + warn " + $d1" + else + #warn "new destination file. consider manually moving it:" + warn $'\e[32m + \e[0m' "$d1" + fi fi done }