diff --git a/symclone.sh b/symclone.sh index e855fad..a5e6cfe 100755 --- a/symclone.sh +++ b/symclone.sh @@ -6,7 +6,15 @@ set -e SRC_DIR=_src.posix # Target directory (new structure with symlinks) -DEST_DIR="${1:?}" +DEST_DIR="${1}" + +is_cmd() { + type -p -- "${@}" 2> /dev/null 1> /dev/null +} +if is_cmd chezmoi && [ -z "$DEST_DIR" ]; then + DEST_DIR="$(chezmoi data | jq -r '.chezmoi.sourceDir | split("/") | last')" +fi +DEST_DIR="${DEST_DIR:?Must supply dest dir name}" # Check if both arguments are provided if [[ -z "$SRC_DIR" || -z "$DEST_DIR" ]]; then @@ -52,7 +60,8 @@ find "$SRC_DIR" -type f | while read -r file; do src_relative_path=$(relpath "$file" "$(dirname "$DEST_DIR/$target_file")") # Create the symlink with relative path - ln -vs "$src_relative_path" "$DEST_DIR/$target_file" + [ -L "$DEST_DIR/$target_file" ] || ! [ -e "$DEST_DIR/$target_file" ] \ + && ln ${FORCE} -vs "$src_relative_path" "$DEST_DIR/$target_file" done echo "Symbolic links created successfully in '$DEST_DIR'."