diff --git a/sdata/subcmd-install/3.files-exp.yaml b/sdata/subcmd-install/3.files-exp.yaml index 5282e0594..63a0cad1f 100644 --- a/sdata/subcmd-install/3.files-exp.yaml +++ b/sdata/subcmd-install/3.files-exp.yaml @@ -20,6 +20,7 @@ patterns: - from: "dots/.config/fish" to: "$XDG_CONFIG_HOME/fish" mode: "sync" + excludes: ["conf.d"] condition: type: "shell" value: "fish" diff --git a/sdata/subcmd-install/3.files-legacy.sh b/sdata/subcmd-install/3.files-legacy.sh index 6ba8cefc2..98d792be8 100644 --- a/sdata/subcmd-install/3.files-legacy.sh +++ b/sdata/subcmd-install/3.files-legacy.sh @@ -30,7 +30,11 @@ esac case "${SKIP_FISH}" in true) sleep 0;; *) - install_dir__sync dots/.config/fish "$XDG_CONFIG_HOME"/fish + # Use rsync with exclude to preserve user's custom conf.d directory + if [ -d "$XDG_CONFIG_HOME"/fish ];then + warning_overwrite + fi + rsync_dir__sync_exclude dots/.config/fish "$XDG_CONFIG_HOME"/fish "conf.d" ;; esac diff --git a/sdata/subcmd-install/3.files.sh b/sdata/subcmd-install/3.files.sh index 41e9972d0..49490a49f 100644 --- a/sdata/subcmd-install/3.files.sh +++ b/sdata/subcmd-install/3.files.sh @@ -67,6 +67,22 @@ rsync_dir__sync(){ x mkdir -p "$(dirname ${INSTALLED_LISTFILE})" rsync -a --delete --out-format='%i %n' "$1"/ "$2"/ | awk -v d="$dest" '$1 ~ /^>/{ sub(/^[^ ]+ /,""); printf d "/" $0 "\n" }' >> "${INSTALLED_LISTFILE}" } +rsync_dir__sync_exclude(){ + # NOTE: This function is only for using in other functions + # Same as rsync_dir__sync but with exclude patterns support + # Usage: rsync_dir__sync_exclude [ ...] + local src="$1" + local dest_dir="$2" + shift 2 + local excludes=() + for pattern in "$@"; do + excludes+=(--exclude "$pattern") + done + x mkdir -p "$dest_dir" + local dest="$(realpath -se $dest_dir)" + x mkdir -p "$(dirname ${INSTALLED_LISTFILE})" + rsync -a --delete "${excludes[@]}" --out-format='%i %n' "$src"/ "$dest_dir"/ | awk -v d="$dest" '$1 ~ /^>/{ sub(/^[^ ]+ /,""); printf d "/" $0 "\n" }' >> "${INSTALLED_LISTFILE}" +} function install_file(){ # NOTE: Do not add prefix `v` or `x` when using this function local s=$1