.sh

Multi-shell dotfiles manager
Log | Files | Refs | README | LICENSE

commit 8b33f8d553b3dfca1929f8a6e0071bb11c23b781
parent 319ae5ee987aa73b127d01f31eb1710cfaf4dbdc
Author: Byron Torres <b@torresjrjr.com>
Date:   Thu, 18 Feb 2021 14:48:06 +0000

Improve sync_dotfile(), fix test bug, format code

Diffstat:
Mbin/sync | 13+++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/bin/sync b/bin/sync @@ -10,7 +10,7 @@ Creates symbolic links from ~ to corresponding shell dotfiles. " } -test -z "$1" || test "$1" -eq "-h" && { usage ; exit 1 ;} +test -z "$1" || test "$1" = "-h" && { usage ; exit 1 ;} test -z "$DOTSHELL" && { echo "Warning! \$DOTSHELL was not set. Setting to default." @@ -19,9 +19,10 @@ test -z "$DOTSHELL" && { echo "DOTSHELL=$DOTSHELL" sync_dotfile() { - test -L "$2" && rm -v "$2" + test "$1" = "$(readlink "$2")" && rm -v "$2" test -e "$2" && { - printf "\e[31mError:\e[0m non-link \e[1m$2\e[0m exists, skipping\n" 1>&2 + printf '\e[33mWarning:\e[0m \e[1m%s\e[0m is not link to \e[1m%s\e[0m, skipping\n' \ + "$2" "$1" 1>&2 return } ln -sv "$1" "$2" @@ -31,14 +32,14 @@ for shell in $@ do case $shell in sh) - sync_dotfile "$DOTSHELL/sh/.profile" "$HOME/.profile" + sync_dotfile "$DOTSHELL/sh/.profile" "$HOME/.profile" ;; bash) - sync_dotfile "$DOTSHELL/sh/.profile" "$HOME/.profile" + sync_dotfile "$DOTSHELL/sh/.profile" "$HOME/.profile" sync_dotfile "$DOTSHELL/bash/.bashrc" "$HOME/.bashrc" ;; zsh) - sync_dotfile "$DOTSHELL/zsh/.zshenv" "$HOME/.zshenv" + sync_dotfile "$DOTSHELL/zsh/.zshenv" "$HOME/.zshenv" ;; *) echo "shell '$shell' unrecognised"