refactor: one ~/.mackup/ssr-<name>.cfg per dot-dir instead of combined file
Each discovered dot-dir now gets its own Mackup app definition: .claude → ~/.mackup/ssr-claude.cfg .cursor → ~/.mackup/ssr-cursor.cfg .config/gh → ~/.mackup/ssr-config-gh.cfg … This matches Mackup's own convention, keeps definitions independent, and makes it easy to add/remove individual apps. The old combined ssr-custom.cfg is removed automatically on the next sync run. Files are written idempotently (skipped when content is unchanged). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+50
-30
@@ -41,29 +41,57 @@ _SSR_MACKUP_SKIP=(
|
|||||||
.ssh .gnupg .aws .azure .gcloud .config/gcloud
|
.ssh .gnupg .aws .azure .gcloud .config/gcloud
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate (or refresh) ~/.mackup/ssr-custom.cfg with:
|
# Derive a safe Mackup app-name and filename from a dot-path.
|
||||||
# 1. Curated entries that exist in $HOME and are not yet in the Mackup backup.
|
# Examples: .claude → ssr-claude .config/gh → ssr-config-gh
|
||||||
# 2. Any dot-dir discovered in $HOME that is not in the skip list and not
|
_ssr_mackup_cfg_name() {
|
||||||
# already materialised in the Mackup backup directory.
|
local path="$1"
|
||||||
#
|
local name="${path#.}" # strip leading dot
|
||||||
# The file is picked up automatically by `mackup backup/restore`.
|
name="${name//\//-}" # slashes → dashes
|
||||||
# Idempotent: re-running overwrites the previous version.
|
name="${name//_/-}" # underscores → dashes
|
||||||
ssr::mackup::generate_custom_cfg() {
|
name="$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')"
|
||||||
local mackup_dir="$1" # the cloud Mackup backup directory
|
printf 'ssr-%s' "$name"
|
||||||
local cfg_dir="$HOME/.mackup"
|
}
|
||||||
local cfg_file="$cfg_dir/ssr-custom.cfg"
|
|
||||||
|
|
||||||
|
# Write a single ~/.mackup/<name>.cfg for one dot-path.
|
||||||
|
# Skips writing if the file already exists and its content matches
|
||||||
|
# (idempotent on repeated syncs).
|
||||||
|
_ssr_mackup_write_cfg() {
|
||||||
|
local cfg_dir="$1" item="$2"
|
||||||
|
local app_name; app_name="$(_ssr_mackup_cfg_name "$item")"
|
||||||
|
local cfg_file="$cfg_dir/${app_name}.cfg"
|
||||||
|
|
||||||
|
local desired
|
||||||
|
desired="$(printf '[application]\nname = %s\n\n[configuration_files]\n%s\n' \
|
||||||
|
"$app_name" "$item")"
|
||||||
|
|
||||||
|
if [[ -f "$cfg_file" ]] && [[ "$(cat "$cfg_file")" == "$desired" ]]; then
|
||||||
|
return 0 # already up-to-date
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '%s\n' "$desired" > "$cfg_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Generate one ~/.mackup/ssr-<name>.cfg per uncovered dot-dir/file.
|
||||||
|
# 1. Curated entries that exist in $HOME and are not yet in the Mackup backup.
|
||||||
|
# 2. Auto-discovered dot-dirs in $HOME not in the skip list and not in backup.
|
||||||
|
#
|
||||||
|
# Removes the old combined ssr-custom.cfg if found (migration from old format).
|
||||||
|
# Each file is picked up automatically by `mackup backup/restore`.
|
||||||
|
ssr::mackup::generate_custom_cfg() {
|
||||||
|
local mackup_dir="$1"
|
||||||
|
local cfg_dir="$HOME/.mackup"
|
||||||
mkdir -p "$cfg_dir"
|
mkdir -p "$cfg_dir"
|
||||||
|
|
||||||
# Build a fast lookup set from the skip list.
|
# Remove legacy combined file if present.
|
||||||
|
[[ -f "$cfg_dir/ssr-custom.cfg" ]] && rm -f "$cfg_dir/ssr-custom.cfg"
|
||||||
|
|
||||||
local skip_set=" ${_SSR_MACKUP_SKIP[*]} "
|
local skip_set=" ${_SSR_MACKUP_SKIP[*]} "
|
||||||
|
|
||||||
# Helper: is <item> already in the Mackup backup?
|
|
||||||
_in_backup() { [[ -e "$mackup_dir/$1" ]]; }
|
_in_backup() { [[ -e "$mackup_dir/$1" ]]; }
|
||||||
|
|
||||||
local -a items=()
|
local -a items=()
|
||||||
|
|
||||||
# 1. Curated entries (exist on disk, not yet backed up).
|
# 1. Curated + user-defined extras.
|
||||||
local item
|
local item
|
||||||
for item in "${_SSR_MACKUP_CURATED[@]}" ${SSR_MACKUP_EXTRA_PATHS:-}; do
|
for item in "${_SSR_MACKUP_CURATED[@]}" ${SSR_MACKUP_EXTRA_PATHS:-}; do
|
||||||
[[ -e "$HOME/$item" ]] || continue
|
[[ -e "$HOME/$item" ]] || continue
|
||||||
@@ -71,15 +99,12 @@ ssr::mackup::generate_custom_cfg() {
|
|||||||
items+=("$item")
|
items+=("$item")
|
||||||
done
|
done
|
||||||
|
|
||||||
# 2. Auto-discover uncovered dot-dirs in $HOME.
|
# 2. Auto-discover uncovered dot-dirs.
|
||||||
local name
|
local name
|
||||||
while IFS= read -r dotdir; do
|
while IFS= read -r dotdir; do
|
||||||
name="${dotdir##*/}"
|
name="${dotdir##*/}"
|
||||||
# Skip if in the skip set.
|
|
||||||
[[ "$skip_set" == *" $name "* ]] && continue
|
[[ "$skip_set" == *" $name "* ]] && continue
|
||||||
# Skip if already in backup.
|
|
||||||
_in_backup "$name" && continue
|
_in_backup "$name" && continue
|
||||||
# Skip if already in the curated list we built above.
|
|
||||||
local dup=false
|
local dup=false
|
||||||
for item in "${items[@]:-}"; do [[ "$item" == "$name" ]] && dup=true && break; done
|
for item in "${items[@]:-}"; do [[ "$item" == "$name" ]] && dup=true && break; done
|
||||||
$dup && continue
|
$dup && continue
|
||||||
@@ -87,24 +112,19 @@ ssr::mackup::generate_custom_cfg() {
|
|||||||
done < <(find "$HOME" -maxdepth 1 -mindepth 1 -name '.*' -type d 2>/dev/null | sort)
|
done < <(find "$HOME" -maxdepth 1 -mindepth 1 -name '.*' -type d 2>/dev/null | sort)
|
||||||
|
|
||||||
if [[ ${#items[@]} -eq 0 ]]; then
|
if [[ ${#items[@]} -eq 0 ]]; then
|
||||||
ssr::log "No uncovered dot-dirs to add — ~/.mackup/ssr-custom.cfg not changed."
|
ssr::log "No uncovered dot-dirs — ~/.mackup/ssr-*.cfg unchanged."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
{
|
local written=0 it
|
||||||
printf '# Auto-generated by ssr sync (%s)\n' "$(date '+%Y-%m-%dT%H:%M:%S')"
|
|
||||||
printf '# Do not edit manually — regenerated on every sync.\n'
|
|
||||||
printf '# Add custom paths via SSR_MACKUP_EXTRA_PATHS in ssr.conf.\n\n'
|
|
||||||
printf '[application]\n'
|
|
||||||
printf 'name = ssr-custom\n\n'
|
|
||||||
printf '[configuration_files]\n'
|
|
||||||
local it
|
|
||||||
for it in "${items[@]}"; do
|
for it in "${items[@]}"; do
|
||||||
printf '%s\n' "$it"
|
if _ssr_mackup_write_cfg "$cfg_dir" "$it"; then
|
||||||
|
written=$((written + 1))
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
} > "$cfg_file"
|
|
||||||
|
|
||||||
ssr::ok "~/.mackup/ssr-custom.cfg: ${#items[@]} item(s) added → ${items[*]}"
|
ssr::ok "~/.mackup/ssr-*.cfg: ${#items[@]} app definitions written (${written} new/updated)"
|
||||||
|
ssr::log " → ${items[*]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
ssr::mackup::ensure_installed() {
|
ssr::mackup::ensure_installed() {
|
||||||
|
|||||||
Reference in New Issue
Block a user