feat: add utility to copy files and handle diffs based on user input
This commit is contained in:
parent
1d08869863
commit
64050ab9d3
1 changed files with 43 additions and 2 deletions
45
bootstrap.sh
Normal file → Executable file
45
bootstrap.sh
Normal file → Executable file
|
@ -41,6 +41,47 @@ pre_substep() {
|
|||
echo -e "\e[1m[$STEP_COUNT.$SUBSTEP_COUNT] <====== $1 =======>\e[0m"
|
||||
}
|
||||
|
||||
# Copies a file from $1 to $2.
|
||||
#
|
||||
# If $2 exists, checks if $1 == $2 and asks what to do.
|
||||
# From there, the user providing "O" will overwrite (proceed with copy),
|
||||
# "S" will skip the file and leave the destination as-is, and anyting else
|
||||
# will skip the copy altogether (i.e. "S").
|
||||
copy_file() {
|
||||
source_path=$1
|
||||
dest_path=$2
|
||||
|
||||
if [ ! -e "$dest_path" ]; then
|
||||
cp $source_path $dest_path
|
||||
echo "Copied $source_path > $dest_path"
|
||||
return 0
|
||||
fi
|
||||
|
||||
difference="$(diff $source_path $dest_path)"
|
||||
|
||||
if [ -z "$difference" ]; then
|
||||
echo "$dest_path already exists, but is the same as $source_path - skipping."
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Differences detected between $source_path and $dest_path:"
|
||||
diff --color $source_path $dest_path
|
||||
read -p "$dest_path already exists. What should be done? [O:overwrite,S:skip] " action
|
||||
|
||||
if [[ $action == "O" ]]; then
|
||||
cp $source_path $dest_path
|
||||
echo "Overwrote $source_path > $dest_path"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ $action == "S" ]]; then
|
||||
echo "Skipped and left $dest_path as is."
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Unrecognized action, doing nothing."
|
||||
}
|
||||
|
||||
##########################################################
|
||||
#
|
||||
# 2. Steps
|
||||
|
@ -113,10 +154,10 @@ install_and_configure_starship() {
|
|||
pre_substep "Copy configuration in configuration directory"
|
||||
STARSHIP_CONFIGURATION_PATH=~/.config/starship.toml
|
||||
if [ -f $STARSHIP_CONFIGURATION_PATH ]; then
|
||||
cp $STARSHIP_CONFIGURATION_PATH $STARSHIP_CONFIGURATION_PATH.old
|
||||
copy_file $STARSHIP_CONFIGURATION_PATH $STARSHIP_CONFIGURATION_PATH.old
|
||||
fi
|
||||
|
||||
cp ./files/starship.toml $STARSHIP_CONFIGURATION_PATH
|
||||
copy_file ./files/starship.toml $STARSHIP_CONFIGURATION_PATH
|
||||
}
|
||||
|
||||
install_nvm() {
|
||||
|
|
Loading…
Reference in a new issue