Last active
August 6, 2022 22:59
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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