1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2025-02-05 07:43:22 -08:00

improve error handling

This commit is contained in:
Connor Olding 2021-07-31 13:24:39 -07:00
parent 4000e091a9
commit 762f7ffe35

11
install
View file

@ -4,6 +4,7 @@
VERBOSE=1 VERBOSE=1
NAME="$0"
[ -n "$ZSH_VERSION" -o -n "$BASH" ] || VERBOSE=0 # no colors for you [ -n "$ZSH_VERSION" -o -n "$BASH" ] || VERBOSE=0 # no colors for you
note() { note() {
@ -16,7 +17,7 @@ warn() {
} }
die() { die() {
warn "$@" warn "$NAME:" "$@"
exit 1 exit 1
} }
@ -118,12 +119,14 @@ softlink() {
fi fi
} }
which readlink >/dev/null || exit 1 # sanity check which readlink >/dev/null || die 'failed sanity check (check your $PATH)'
rc="$(readlink -f "$(dirname "$0")" )" rc="$(readlink -f "$(dirname "$NAME")" )"
cd "$HOME" || exit 1 [ -d "$rc" ] || die 'failed to determine rc directory'
cd "${HOME:?HOME variable empty or unset}" || die 'failed to change directory'
backup_dir="$rc/backup-$(date -u '+%s')" backup_dir="$rc/backup-$(date -u '+%s')"
[ ! -d "$backup_dir" ] || die 'backup directory already exists'
for f in .bashrc .zshrc .-shrc .prezto-compinit .ls_colors \ for f in .bashrc .zshrc .-shrc .prezto-compinit .ls_colors \
.vimrc .inputrc .Xresources .screenrc .tmux.conf; do .vimrc .inputrc .Xresources .screenrc .tmux.conf; do