feat: add copy_file case to handle backup-and-copy

This commit is contained in:
Marc 2024-02-25 22:33:54 -05:00
parent 64050ab9d3
commit 20218415b3
Signed by: marc
GPG key ID: 048E042F22B5DC79

View file

@ -66,7 +66,7 @@ copy_file() {
echo "Differences detected between $source_path and $dest_path:" echo "Differences detected between $source_path and $dest_path:"
diff --color $source_path $dest_path diff --color $source_path $dest_path
read -p "$dest_path already exists. What should be done? [O:overwrite,S:skip] " action read -p "$dest_path already exists. What should be done? [O:overwrite,S:skip,B:save backup and copy] " action
if [[ $action == "O" ]]; then if [[ $action == "O" ]]; then
cp $source_path $dest_path cp $source_path $dest_path
@ -79,6 +79,14 @@ copy_file() {
return 0 return 0
fi fi
if [[ $action == "B" ]]; then
cp $dest_path $dest_path.old
echo "Backed up $dest_path up to $dest_path.old"
cp $source_path $dest_path
echo "Overwrote $source_path > $dest_path"
return 0
fi
echo "Unrecognized action, doing nothing." echo "Unrecognized action, doing nothing."
} }
@ -152,12 +160,8 @@ install_and_configure_starship() {
fi fi
pre_substep "Copy configuration in configuration directory" pre_substep "Copy configuration in configuration directory"
STARSHIP_CONFIGURATION_PATH=~/.config/starship.toml
if [ -f $STARSHIP_CONFIGURATION_PATH ]; then
copy_file $STARSHIP_CONFIGURATION_PATH $STARSHIP_CONFIGURATION_PATH.old
fi
copy_file ./files/starship.toml $STARSHIP_CONFIGURATION_PATH copy_file ./files/starship.toml ~/.config/starship.toml
} }
install_nvm() { install_nvm() {