.dots/scripts/merge.sh

23 lines
889 B
Bash
Raw Normal View History

2024-08-30 15:38:16 +02:00
#!/usr/bin/env zsh
# author: Daniel Sommer <daniel.sommer@velvettear.de>
# license: MIT
# merge files from two folders and cleanup the source
# get and check variables
[[ -z "$1" ]] && printf "error: no source directory specified!\n" >&2 && exit 1
[[ -z "$2" ]] && printf "error: no destination directory specified!\n" >&2 && exit 1
source="$(realpath $1)"
destination="$(realpath $2)"
[[ ! -d "$source" ]] && printf "error: source '"$source"' is not a valid or existing directory!\n" >&2 && exit 1
[[ ! -d "$destination" ]] && printf "error: destination '"$destination"' is not a valid or existing directory!\n" >&2 && exit 1
printf ">> merging directory '"$source"' into '"$destination"' with rsync...\n"
rsync -avh --remove-source-files --progress "$source/" "$destination"
find "$source" -mindepth 1 -type d -empty -delete
printf ">> merge finished after "$SECONDS" seconds!\n"