#!/bin/zsh DEPENDENCIES+=() REQUIRED_ENV+=() use system/config CHECK_ENVIRONMENT ##################################################################### SETUP_SYMLINKS() { while read SYMLINK do SETUP_SYMLINK $(echo $SYMLINK | awk '{print $1;}') $(echo $SYMLINK | awk '{print $2}') done < <(echo $SYMLINKS | sed -n '/^[^#]/p') } SETUP_SYMLINK() { [ ! $2 ] && FAIL 1 'must provide SOURCE_CONFIG and TARGET_CONFIG' local SOURCE_CONFIG="$1" local TARGET_CONFIG="$HOME/.config/$2" [ ! -f "$SOURCE_CONFIG" ] && [ ! -d "$SOURCE_CONFIG" ] && [ -f "$TARGET_CONFIG" ] && { INFO 'SOURCE_CONFIG is not tracked; copying from TARGET_CONFIG' mkdir -p "$(dirname "$SOURCE_CONFIG")" cp "$TARGET_CONFIG" "$SOURCE_CONFIG" } [ ! -f "$SOURCE_CONFIG" ] && [ ! -d "$SOURCE_CONFIG" ] && { WARNING "no such file or directory '$SOURCE_CONFIG'" return 0 } [ ! -d $(dirname "$TARGET_CONFIG") ] && mkdir -p $(dirname "$TARGET_CONFIG") [[ $SAFE_SYMLINKS -eq 1 ]] \ && mv "$TARGET_CONFIG" "$TARGET_CONFIG.bak" >/dev/null 2>&1 rm "$TARGET_CONFIG" >/dev/null 2>&1 ln -s "$SOURCE_CONFIG" "$TARGET_CONFIG" \ && SUCCESS "successfully linked '$(basename $(dirname $TARGET_CONFIG))/$(basename $TARGET_CONFIG)'" \ || FAIL 3 "failed to create link '$TARGET_CONFIG'" \ ; } ##################################################################### SETUP_SYMLINKS $@