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:
+54
-34
@@ -41,45 +41,70 @@ _SSR_MACKUP_SKIP=(
|
||||
.ssh .gnupg .aws .azure .gcloud .config/gcloud
|
||||
)
|
||||
|
||||
# Generate (or refresh) ~/.mackup/ssr-custom.cfg with:
|
||||
# 1. Curated entries that exist in $HOME and are not yet in the Mackup backup.
|
||||
# 2. Any dot-dir discovered in $HOME that is not in the skip list and not
|
||||
# already materialised in the Mackup backup directory.
|
||||
#
|
||||
# The file is picked up automatically by `mackup backup/restore`.
|
||||
# Idempotent: re-running overwrites the previous version.
|
||||
ssr::mackup::generate_custom_cfg() {
|
||||
local mackup_dir="$1" # the cloud Mackup backup directory
|
||||
local cfg_dir="$HOME/.mackup"
|
||||
local cfg_file="$cfg_dir/ssr-custom.cfg"
|
||||
# Derive a safe Mackup app-name and filename from a dot-path.
|
||||
# Examples: .claude → ssr-claude .config/gh → ssr-config-gh
|
||||
_ssr_mackup_cfg_name() {
|
||||
local path="$1"
|
||||
local name="${path#.}" # strip leading dot
|
||||
name="${name//\//-}" # slashes → dashes
|
||||
name="${name//_/-}" # underscores → dashes
|
||||
name="$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')"
|
||||
printf 'ssr-%s' "$name"
|
||||
}
|
||||
|
||||
# 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"
|
||||
|
||||
# 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[*]} "
|
||||
|
||||
# Helper: is <item> already in the Mackup backup?
|
||||
_in_backup() { [[ -e "$mackup_dir/$1" ]]; }
|
||||
|
||||
local -a items=()
|
||||
|
||||
# 1. Curated entries (exist on disk, not yet backed up).
|
||||
# 1. Curated + user-defined extras.
|
||||
local item
|
||||
for item in "${_SSR_MACKUP_CURATED[@]}" ${SSR_MACKUP_EXTRA_PATHS:-}; do
|
||||
[[ -e "$HOME/$item" ]] || continue
|
||||
_in_backup "$item" && continue
|
||||
[[ -e "$HOME/$item" ]] || continue
|
||||
_in_backup "$item" && continue
|
||||
items+=("$item")
|
||||
done
|
||||
|
||||
# 2. Auto-discover uncovered dot-dirs in $HOME.
|
||||
# 2. Auto-discover uncovered dot-dirs.
|
||||
local name
|
||||
while IFS= read -r dotdir; do
|
||||
name="${dotdir##*/}"
|
||||
# Skip if in the skip set.
|
||||
[[ "$skip_set" == *" $name "* ]] && continue
|
||||
# Skip if already in backup.
|
||||
_in_backup "$name" && continue
|
||||
# Skip if already in the curated list we built above.
|
||||
local dup=false
|
||||
for item in "${items[@]:-}"; do [[ "$item" == "$name" ]] && dup=true && break; done
|
||||
$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)
|
||||
|
||||
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
|
||||
fi
|
||||
|
||||
{
|
||||
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
|
||||
printf '%s\n' "$it"
|
||||
done
|
||||
} > "$cfg_file"
|
||||
local written=0 it
|
||||
for it in "${items[@]}"; do
|
||||
if _ssr_mackup_write_cfg "$cfg_dir" "$it"; then
|
||||
written=$((written + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user