fix(mackup): correct built-in coverage detection and per-item scan confirm
_ssr_mackup_declared_paths: - Fix wrong subdir: apps/ → applications/ (coverage was completely broken) - Use Mackup's bundled Python interpreter (not system python3) - Track xdg_configuration_files sections separately and prefix paths with .config/ so paths like gh/config.yml → .config/gh/config.yml are properly recognized as covering .config/gh _is_declared: - Use `command grep` to bypass colour aliases - Replace grep -E regex (dot-escaping issues) with bash glob: == "$p/"* - Applied to both lib/mackup.sh and bin/ssr-mackup _SSR_MACKUP_CURATED: - Remove entries now correctly detected as built-in covered: .claude (claude-code.cfg), .codex, .docker, .config/gh (github-cli xdg) - Keep .cursor (built-in covers Library/Application Support, not .cursor/) _SSR_MACKUP_SELECTIVE: - Remove entries for removed curated items ssr mackup scan: - Confirm each new item individually (y/n per candidate) - Confirm each stale removal individually - Show resolved sub-paths per item before asking Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+102
-61
@@ -37,7 +37,7 @@ EOF
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# scan — dry-run then confirm
|
||||
# scan — show each candidate and confirm per-item
|
||||
# ---------------------------------------------------------------------------
|
||||
cmd_scan() {
|
||||
local mackup_dir
|
||||
@@ -49,13 +49,27 @@ cmd_scan() {
|
||||
|
||||
local skip_set=" ${_SSR_MACKUP_SKIP[*]} "
|
||||
|
||||
_in_backup() { [[ -n "$mackup_dir" && -e "$mackup_dir/$1" ]]; }
|
||||
_is_declared() { printf '%s\n' "$declared" | grep -qxF "$1"; }
|
||||
|
||||
local declared
|
||||
declared="$(_ssr_mackup_declared_paths)"
|
||||
|
||||
# Collect candidate items (same logic as generate_custom_cfg).
|
||||
# Returns true when <path> is declared exactly OR when any built-in declares
|
||||
# a sub-path of <path> (e.g. .byobu/profile covers .byobu, .claude/settings
|
||||
# covers .claude, etc.).
|
||||
# Uses `command grep` (bypasses colour aliases) and a bash glob for the
|
||||
# prefix check (avoids regex escaping issues with dots in paths).
|
||||
_is_declared() {
|
||||
local p="$1" decl
|
||||
command grep -qxF "$p" <<< "$declared" && return 0
|
||||
while IFS= read -r decl; do
|
||||
[[ "$decl" == "$p/"* ]] && return 0
|
||||
done <<< "$declared"
|
||||
return 1
|
||||
}
|
||||
_in_backup() { [[ -n "$mackup_dir" && -e "$mackup_dir/$1" ]]; }
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Collect candidate items — same logic as generate_custom_cfg.
|
||||
# -----------------------------------------------------------------------
|
||||
local -a items=()
|
||||
local item
|
||||
for item in "${_SSR_MACKUP_CURATED[@]}" ${SSR_MACKUP_EXTRA_PATHS:-}; do
|
||||
@@ -76,83 +90,110 @@ cmd_scan() {
|
||||
items+=("$name")
|
||||
done < <(find "$HOME" -maxdepth 1 -mindepth 1 -name '.*' -type d 2>/dev/null | sort)
|
||||
|
||||
# Check existing stale duplicates.
|
||||
local -a to_remove=()
|
||||
# -----------------------------------------------------------------------
|
||||
# Stale ssr-*.cfg files: exist but now covered by a built-in definition.
|
||||
# -----------------------------------------------------------------------
|
||||
local -a stale_cfgs=()
|
||||
local stale_cfg stale_path
|
||||
for stale_cfg in "$cfg_dir"/ssr-*.cfg; do
|
||||
[[ -f "$stale_cfg" ]] || continue
|
||||
stale_path="$(awk '/^\[configuration_files\]/{f=1;next}/^\[/{f=0}f&&/^[^#[:space:]]/{print $1;exit}' "$stale_cfg")"
|
||||
_is_declared "$stale_path" && to_remove+=("$stale_cfg")
|
||||
_is_declared "$stale_path" && stale_cfgs+=("$stale_cfg")
|
||||
done
|
||||
|
||||
# Only suggest items that have NO cfg file yet.
|
||||
# Existing files are user-owned — edit them directly in ~/.mackup/.
|
||||
local -a to_write=()
|
||||
local -a cfg_paths=()
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Filter to NEW items only (user owns existing files).
|
||||
# -----------------------------------------------------------------------
|
||||
local -a new_items=()
|
||||
local -a new_cfgs=()
|
||||
local it app_name cfg_file
|
||||
for it in "${items[@]:-}"; do
|
||||
app_name="$(_ssr_mackup_cfg_name "$it")"
|
||||
cfg_file="$cfg_dir/${app_name}.cfg"
|
||||
[[ -f "$cfg_file" ]] && continue # user owns it — skip
|
||||
to_write+=("$it")
|
||||
cfg_paths+=("$cfg_file")
|
||||
[[ -f "$cfg_file" ]] && continue
|
||||
new_items+=("$it")
|
||||
new_cfgs+=("$cfg_file")
|
||||
done
|
||||
|
||||
# Nothing to do?
|
||||
if [[ ${#to_write[@]} -eq 0 && ${#to_remove[@]} -eq 0 ]]; then
|
||||
if [[ ${#new_items[@]} -eq 0 && ${#stale_cfgs[@]} -eq 0 ]]; then
|
||||
ssr::ok "All ~/.mackup/ssr-*.cfg files are up-to-date — nothing to do."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Show plan.
|
||||
if [[ ${#to_write[@]} -gt 0 ]]; then
|
||||
printf '\nSuggested Mackup app definitions:\n'
|
||||
local i
|
||||
for i in "${!to_write[@]}"; do
|
||||
local path="${cfg_paths[$i]##*/}"
|
||||
# Show resolved paths (selective default or whole dir).
|
||||
local resolved; resolved="$(_ssr_mackup_resolve_paths "${to_write[$i]}")"
|
||||
local line_count; line_count="$(printf '%s\n' "$resolved" | wc -l | tr -d ' ')"
|
||||
local paths_hint
|
||||
if [[ "$line_count" -eq 1 && "$resolved" == "${to_write[$i]}" ]]; then
|
||||
paths_hint="${to_write[$i]}/"
|
||||
else
|
||||
paths_hint="$line_count sub-path(s) of ${to_write[$i]}/"
|
||||
fi
|
||||
printf " \033[32mNEW\033[0m %-38s %s\n" \
|
||||
"~/.mackup/$path" "$paths_hint"
|
||||
done
|
||||
printf '\n\033[2mEdit the generated files directly in ~/.mackup/ to customise paths.\033[0m\n'
|
||||
fi
|
||||
|
||||
if [[ ${#to_remove[@]} -gt 0 ]]; then
|
||||
printf '\nStale duplicates to remove (now covered by built-in):\n'
|
||||
local f
|
||||
for f in "${to_remove[@]}"; do
|
||||
printf " \033[31mDEL\033[0m %s\n" "~/.mackup/${f##*/}"
|
||||
done
|
||||
fi
|
||||
printf '\n'
|
||||
local written=0 removed=0
|
||||
|
||||
# Confirm.
|
||||
local total=$(( ${#to_write[@]} + ${#to_remove[@]} ))
|
||||
ssr::confirm "Apply $total change(s)?" 60 || { printf 'Aborted.\n'; return 0; }
|
||||
# -----------------------------------------------------------------------
|
||||
# New files — confirm each individually.
|
||||
# -----------------------------------------------------------------------
|
||||
if [[ ${#new_items[@]} -gt 0 ]]; then
|
||||
printf '\033[1mNew Mackup app definitions\033[0m (%d candidate(s))\n\n' "${#new_items[@]}"
|
||||
|
||||
# Write new files (never overwrites existing ones).
|
||||
for it in "${to_write[@]:-}"; do
|
||||
_ssr_mackup_write_cfg "$cfg_dir" "$it"
|
||||
done
|
||||
local i
|
||||
for i in "${!new_items[@]}"; do
|
||||
it="${new_items[$i]}"
|
||||
cfg_file="${new_cfgs[$i]}"
|
||||
local cfg_name="${cfg_file##*/}"
|
||||
|
||||
# Remove stale duplicates.
|
||||
for f in "${to_remove[@]:-}"; do
|
||||
rm -f "$f"
|
||||
ssr::log "Removed stale: ${f##*/}"
|
||||
done
|
||||
# Resolved paths preview.
|
||||
local resolved; resolved="$(_ssr_mackup_resolve_paths "$it")"
|
||||
local line_count; line_count="$(printf '%s\n' "$resolved" | wc -l | tr -d ' ')"
|
||||
|
||||
ssr::ok "Done — ${#to_write[@]} written, ${#to_remove[@]} removed."
|
||||
printf '\nEdit ~/.mackup/ssr-*.cfg directly to customise paths.\n'
|
||||
printf 'Run \033[1mssr sync\033[0m to back up with the new definitions.\n\n'
|
||||
# Header for this item.
|
||||
printf ' \033[32m+\033[0m \033[1m~/.mackup/%s\033[0m\n' "$cfg_name"
|
||||
if [[ "$line_count" -eq 1 && "$resolved" == "$it" ]]; then
|
||||
printf ' backs up: ~/%s/ (whole directory)\n' "$it"
|
||||
else
|
||||
printf ' backs up: %d path(s) inside ~/%s/\n' "$line_count" "$it"
|
||||
printf '%s\n' "$resolved" | while IFS= read -r p; do
|
||||
printf ' · ~/%s\n' "$p"
|
||||
done
|
||||
fi
|
||||
printf '\n'
|
||||
|
||||
if ssr::confirm " Create ~/.mackup/$cfg_name?" 30; then
|
||||
_ssr_mackup_write_cfg "$cfg_dir" "$it"
|
||||
written=$((written + 1))
|
||||
printf ' \033[32m✓ written\033[0m\n\n'
|
||||
else
|
||||
printf ' skipped\n\n'
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Stale files — confirm each removal individually.
|
||||
# -----------------------------------------------------------------------
|
||||
if [[ ${#stale_cfgs[@]} -gt 0 ]]; then
|
||||
printf '\033[1mStale duplicates\033[0m (now covered by a Mackup built-in)\n\n'
|
||||
|
||||
local f
|
||||
for f in "${stale_cfgs[@]}"; do
|
||||
printf ' \033[31m-\033[0m \033[1m%s\033[0m\n' "~/.mackup/${f##*/}"
|
||||
# Show which built-in covers it.
|
||||
stale_path="$(awk '/^\[configuration_files\]/{f=1;next}/^\[/{f=0}f&&/^[^#[:space:]]/{print $1;exit}' "$f")"
|
||||
printf ' path \033[2m%s\033[0m is now declared by a built-in Mackup app\n\n' "$stale_path"
|
||||
|
||||
if ssr::confirm " Remove ${f##*/}?" 30; then
|
||||
rm -f "$f"
|
||||
removed=$((removed + 1))
|
||||
printf ' \033[31m✓ removed\033[0m\n\n'
|
||||
else
|
||||
printf ' skipped\n\n'
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Summary.
|
||||
# -----------------------------------------------------------------------
|
||||
if [[ $written -gt 0 || $removed -gt 0 ]]; then
|
||||
ssr::ok "Done — $written written, $removed removed."
|
||||
[[ $written -gt 0 ]] && printf '\nEdit ~/.mackup/ssr-*.cfg directly to adjust paths.\n'
|
||||
printf 'Run \033[1mssr sync\033[0m to back up with the updated definitions.\n\n'
|
||||
else
|
||||
printf 'Nothing applied.\n'
|
||||
fi
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user