forked from Shinonome/dots-hyprland
Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
# TODO: add --exp-files-no-strict Ignore error when minor version number is not the same
|
# TODO: add --exp-files-no-strict Ignore error when minor version number is not the same
|
||||||
#
|
#
|
||||||
# Stage 2 todos:
|
# Stage 2 todos:
|
||||||
# TODO: Implement symlink (readable or non-readable) as sync mode
|
# TODO: Implement symlink (both read-write and read-only) as sync mode
|
||||||
# TODO: add --exp-file-reset-symlink Try to remove all symlink in .config and .local, which point to the local repo
|
# TODO: add --exp-file-reset-symlink Try to remove all symlink in .config and .local, which point to the local repo
|
||||||
# TODO: Update help and doc about `--exp-files` and the yaml config, including the possible values of mode.
|
# TODO: Update help and doc about `--exp-files` and the yaml config, including the possible values of mode.
|
||||||
#
|
#
|
||||||
@@ -167,113 +167,111 @@ for pattern in "${patterns[@]}"; do
|
|||||||
mode=$(echo "$pattern" | yq '.mode' - | envsubst)
|
mode=$(echo "$pattern" | yq '.mode' - | envsubst)
|
||||||
condition=$(echo "$pattern" | yq '.condition // "true"')
|
condition=$(echo "$pattern" | yq '.condition // "true"')
|
||||||
|
|
||||||
# Handle fontconfig fontset override
|
# Handle fontconfig fontset override
|
||||||
# If FONTSET_DIR_NAME is set and this is the fontconfig pattern, use the fontset instead
|
# If FONTSET_DIR_NAME is set and this is the fontconfig pattern, use the fontset instead
|
||||||
if [[ "$from" == "dots/.config/fontconfig" ]] && [[ -n "${FONTSET_DIR_NAME:-}" ]]; then
|
if [[ "$from" == "dots/.config/fontconfig" ]] && [[ -n "${FONTSET_DIR_NAME:-}" ]]; then
|
||||||
from="dots-extra/fontsets/${FONTSET_DIR_NAME}"
|
from="dots-extra/fontsets/${FONTSET_DIR_NAME}"
|
||||||
echo "Using fontset \"${FONTSET_DIR_NAME}\" for fontconfig"
|
echo "Using fontset \"${FONTSET_DIR_NAME}\" for fontconfig"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if pattern should be processed
|
# Check if pattern should be processed
|
||||||
if ! should_process_pattern "$pattern"; then
|
if ! should_process_pattern "$pattern"; then
|
||||||
# Format condition message nicely
|
# Format condition message nicely
|
||||||
if [[ "$condition" != "true" ]]; then
|
if [[ "$condition" != "true" ]]; then
|
||||||
cond_type=$(echo "$condition" | yq -r '.type // ""')
|
cond_type=$(echo "$condition" | yq -r '.type // ""')
|
||||||
cond_value=$(echo "$condition" | yq -r '.value // ""')
|
cond_value=$(echo "$condition" | yq -r '.value // ""')
|
||||||
if [[ -n "$cond_type" && -n "$cond_value" ]]; then
|
if [[ -n "$cond_type" && -n "$cond_value" ]]; then
|
||||||
echo "Skipping $from -> $to (condition not met: $cond_type == '$cond_value')"
|
echo "Skipping $from -> $to (condition not met: $cond_type == '$cond_value')"
|
||||||
else
|
|
||||||
echo "Skipping $from -> $to (condition not met)"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "Skipping $from -> $to (condition not met)"
|
echo "Skipping $from -> $to (condition not met)"
|
||||||
fi
|
fi
|
||||||
continue
|
else
|
||||||
|
echo "Skipping $from -> $to (condition not met)"
|
||||||
fi
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Processing: $from -> $to (mode: $mode)"
|
echo "Processing: $from -> $to (mode: $mode)"
|
||||||
|
|
||||||
# Build exclude arguments for rsync
|
# Build exclude arguments for rsync
|
||||||
excludes=()
|
excludes=()
|
||||||
if echo "$pattern" | yq -e '.excludes' >/dev/null 2>&1; then
|
if echo "$pattern" | yq -e '.excludes' >/dev/null 2>&1; then
|
||||||
while IFS= read -r exclude; do
|
while IFS= read -r exclude; do
|
||||||
excludes+=(--exclude "$exclude")
|
excludes+=(--exclude "$exclude")
|
||||||
done < <(echo "$pattern" | yq -r '.excludes[]')
|
done < <(echo "$pattern" | yq -r '.excludes[]')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if source exists
|
# Check if source exists
|
||||||
if [[ ! -e "$from" ]]; then
|
if [[ ! -e "$from" ]]; then
|
||||||
echo "Warning: Source does not exist: $from (skipping)"
|
echo "Warning: Source does not exist: $from (skipping)"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure destination directory exists for files
|
# Ensure destination directory exists for files
|
||||||
if [[ -f "$from" ]]; then
|
if [[ -f "$from" ]]; then
|
||||||
v mkdir -p "$(dirname "$to")"
|
v mkdir -p "$(dirname "$to")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Execute based on mode
|
# Execute based on mode
|
||||||
case $mode in
|
case $mode in
|
||||||
"sync")
|
"sync")
|
||||||
if [[ -d "$from" ]]; then
|
if [[ -d "$from" ]]; then
|
||||||
warning_rsync_delete
|
warning_rsync_delete
|
||||||
v rsync -av --delete "${excludes[@]}" "$from/" "$to/"
|
v rsync -av --delete "${excludes[@]}" "$from/" "$to/"
|
||||||
else
|
else
|
||||||
warning_rsync_normal
|
|
||||||
# For files, don't use trailing slash and don't use --delete
|
|
||||||
v rsync -av "${excludes[@]}" "$from" "$to"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
"soft")
|
|
||||||
warning_rsync_normal
|
warning_rsync_normal
|
||||||
if [[ -d "$from" ]]; then
|
# For files, don't use trailing slash and don't use --delete
|
||||||
v rsync -av "${excludes[@]}" "$from/" "$to/"
|
v rsync -av "${excludes[@]}" "$from" "$to"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"soft")
|
||||||
|
warning_rsync_normal
|
||||||
|
if [[ -d "$from" ]]; then
|
||||||
|
v rsync -av "${excludes[@]}" "$from/" "$to/"
|
||||||
|
else
|
||||||
|
# For files, don't use trailing slash
|
||||||
|
v rsync -av "${excludes[@]}" "$from" "$to"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"hard")
|
||||||
|
v cp -r "$from" "$to"
|
||||||
|
;;
|
||||||
|
"hard-backup")
|
||||||
|
if [[ -e "$to" ]]; then
|
||||||
|
if files_are_same "$from" "$to"; then
|
||||||
|
echo "Files are identical, skipping backup"
|
||||||
else
|
else
|
||||||
# For files, don't use trailing slash
|
backup_number=$(get_next_backup_number "$to")
|
||||||
v rsync -av "${excludes[@]}" "$from" "$to"
|
v mv "$to" "$to.old.$backup_number"
|
||||||
|
v cp -r "$from" "$to"
|
||||||
fi
|
fi
|
||||||
;;
|
else
|
||||||
"hard")
|
|
||||||
v cp -r "$from" "$to"
|
v cp -r "$from" "$to"
|
||||||
;;
|
fi
|
||||||
"hard-backup")
|
;;
|
||||||
if [[ -e "$to" ]]; then
|
"soft-backup")
|
||||||
if files_are_same "$from" "$to"; then
|
if [[ -e "$to" ]]; then
|
||||||
echo "Files are identical, skipping backup"
|
if files_are_same "$from" "$to"; then
|
||||||
else
|
echo "Files are identical, skipping backup"
|
||||||
backup_number=$(get_next_backup_number "$to")
|
|
||||||
v mv "$to" "$to.old.$backup_number"
|
|
||||||
v cp -r "$from" "$to"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
v cp -r "$from" "$to"
|
v cp -r "$from" "$to.new"
|
||||||
fi
|
fi
|
||||||
;;
|
else
|
||||||
"soft-backup")
|
v cp -r "$from" "$to"
|
||||||
if [[ -e "$to" ]]; then
|
fi
|
||||||
if files_are_same "$from" "$to"; then
|
;;
|
||||||
echo "Files are identical, skipping backup"
|
"skip")
|
||||||
else
|
echo "Skipping $from"
|
||||||
v cp -r "$from" "$to.new"
|
;;
|
||||||
fi
|
"skip-if-exists")
|
||||||
else
|
if [[ -e "$to" ]]; then
|
||||||
v cp -r "$from" "$to"
|
echo "Skipping $from (destination exists)"
|
||||||
fi
|
else
|
||||||
;;
|
v cp -r "$from" "$to"
|
||||||
"skip")
|
fi
|
||||||
echo "Skipping $from"
|
;;
|
||||||
;;
|
*)
|
||||||
"skip-if-exists")
|
echo "Unknown mode: $mode"
|
||||||
if [[ -e "$to" ]]; then
|
;;
|
||||||
echo "Skipping $from (destination exists)"
|
esac
|
||||||
else
|
done
|
||||||
v cp -r "$from" "$to"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unknown mode: $mode"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
#####################################################################################
|
|
||||||
|
|||||||
Reference in New Issue
Block a user