mirror of
https://github.com/basecamp/omarchy.git
synced 2025-08-04 07:39:24 +00:00
Show diff when making a backup and clarify the implementation
This commit is contained in:
@ -4,7 +4,7 @@
|
|||||||
config_file=$1
|
config_file=$1
|
||||||
|
|
||||||
if [[ -z "$config_file" ]]; then
|
if [[ -z "$config_file" ]]; then
|
||||||
cat << USAGE
|
cat <<USAGE
|
||||||
Usage: $0 [config_file]
|
Usage: $0 [config_file]
|
||||||
|
|
||||||
Must provide a file path from the .config directory to be refreshed.
|
Must provide a file path from the .config directory to be refreshed.
|
||||||
@ -16,15 +16,20 @@ USAGE
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Backup the destination file (with timestamp) to avoid clobbering (Ex: hyprlock.conf.bak.1753817951)
|
# Backup the destination file (with timestamp) to avoid clobbering (Ex: hyprlock.conf.bak.1753817951)
|
||||||
backup_file="${HOME}/.config/${config_file}.bak.$(date +%s)"
|
user_config_file="${HOME}/.config/$config_file"
|
||||||
cp -f "${HOME}/.config/${config_file}" "$backup_file" 2>/dev/null
|
default_config_file="${HOME}/.local/share/omarchy/config/$config_file"
|
||||||
|
backup_config_file="$user_config_file.bak.$(date +%s)"
|
||||||
|
|
||||||
# Deploy the source file
|
# Create preliminary backup
|
||||||
cp -f "${HOME}/.local/share/omarchy/config/${config_file}" "${HOME}/.config/${config_file}" 2>/dev/null
|
cp -f "$user_config_file" "$backup_config_file" 2>/dev/null
|
||||||
|
|
||||||
|
# Replace config with new default
|
||||||
|
cp -f "$default_config_file" "$user_config_file" 2>/dev/null
|
||||||
|
|
||||||
# Compare and delete/inform accordingly
|
# Compare and delete/inform accordingly
|
||||||
if cmp -s "${HOME}/.config/${config_file}" "$backup_file"; then
|
if cmp -s "$user_config_file" "$backup_config_file"; then
|
||||||
rm $backup_file
|
rm "$backup_config_file"
|
||||||
else
|
else
|
||||||
echo -e "\e[31mExisting "${HOME}/.config/${config_file}" replaced with new Omarchy default, but ${backup_file} file was made.\e[0m"
|
echo -e "\e[31mReplaced $user_config_file with new Omarchy default.\nSaved backup as ${backup_config_file}.\n\n\e[32mChanges:\e[0m"
|
||||||
|
diff "$user_config_file" "$backup_config_file"
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user