Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thierrymarianne/526afeaba10431fc57b9d63ce90b1031 to your computer and use it in GitHub Desktop.
Save thierrymarianne/526afeaba10431fc57b9d63ce90b1031 to your computer and use it in GitHub Desktop.
Code excerpt used in the context of a screencast series entitled "Solving issues with tools running in a shell"
#!/usr/bin/env bash
set -Eeo pipefail
#
# ```
# spot-differences-between-directories "$(pwd)/backup" "$(pwd)/ill-fated-directory"
# ```
#
function spot-differences-between-directories() {
local backup_directory
backup_directory="${1}"
local target_dir
target_dir="${2}"
if [ -z "${backup_directory}" ] || [ ! -d "${backup_directory}" ]; then
printf 'A %s is expected as %s.%s' 'non-empty string' 'backup directory' $'\n'
return 1
fi
if [ -z "${target_dir}" ] || \
[ ! -d "${target_dir}" ]; then
printf 'A %s is expected as %s.%s' 'non-empty string' \
'directory where files have been deleted' $'\n'
return 1
fi
local output_missing_file
output_missing_file='file_path='"${target_dir}"'/{} && [ -e ${file_path} ] || echo "${file_path}"'
(
cd "${backup_directory}" || exit
local exclusion_pattern
exclusion_pattern='.*\(.htacc\|\.xml\|\.md\|docs\|Tests\|node_modules\|vendor\).*'
find ./ \
-not -regex "${exclusion_pattern}" \
-exec bash -c "${output_missing_file}" \;
)
}
alias spot-differences-between-directories='spot_differences_between_directories'
set +Eeo pipefail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment