Created
January 28, 2025 00:56
-
-
Save robfrawley/8aab9012d2ad97b273210d75de601a47 to your computer and use it in GitHub Desktop.
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/zsh | |
function main() { | |
#clear | |
local -a search_paths_listed=("${@}") | |
local search_paths_string | |
local search_paths_hashed | |
local output_files_script | |
local search_call_strings | |
local -a search_call_options=( | |
"$(command -v rmlint || printf -- 'rmlint')" | |
'--loud' '--loud' '--loud' | |
'--with-color' | |
'--progress' | |
'--rank-by' 'pOMa' | |
'--xattr' | |
'--size' '128K' | |
'--config' 'progressbar:fancy' | |
) | |
if [[ "${#search_paths_listed[@]}" == 0 ]]; then | |
search_paths_listed+=("$(pwd)") | |
fi | |
search_paths_string="${(@v)search_paths_listed}" | |
search_paths_hashed="$(printf -- "${search_paths_string}" | sha384sum | sed -E 's/^([a-zA-Z0-9]+).+$/\1/g')" | |
output_files_script="$(printf -- 'file-duplicate-remover_%s' "${search_paths_hashed}")" | |
search_call_options+=( | |
'--output' "pretty:stderr" | |
'--output' "csv:${output_files_script}.csv" | |
'--output' "json:${output_files_script}.json" | |
'--output' "py:${output_files_script}.py" | |
'--output' "sh:${output_files_script}.sh" | |
'--config' 'sh:symlink' | |
${(v)search_paths_listed} | |
) | |
printf '# Resolved configuration:\n' | |
printf ' • search_paths_string --> "%s"\n' "${search_paths_string}" | |
printf ' • search_paths_hashed --> "%s"\n' "${search_paths_hashed}" | |
printf ' • output_files_script --> "%s"\n' "${output_files_script}" | |
printf ' • search_paths_listed --> (%d entries)\n' "${#search_paths_listed[@]}" | |
for v in ${(v)search_paths_listed}; do | |
printf -- ' • "%s"\n' "${v}" | |
done | |
for v in ${(v)search_call_options}; do | |
search_call_strings+="$(printf -- ' "%s"' "${v}")" | |
done | |
search_call_strings="${search_call_strings:1}" | |
printf ' • search_call_strings --> ' "${search_call_strings}" | |
printf -- '%s' "${search_call_strings}" | fold -s -w $(($(tput cols) - 28)) | head -n1 | |
printf -- '%s' "${search_call_strings}" | fold -s -w $(($(tput cols) - 28)) | tail -n+2 | sed -E 's/^/ --> /g' | |
printf -- '\n\n' | |
printf -- '# Sleeping for 3 seconds (use CTRL+C to cancel) ...' | |
for i in $(seq 1 3); do | |
sleep 1 | |
printf -- ' %d ...' "${i}" | |
done | |
printf -- '\n\n' | |
sleep 1 | |
${(v)search_call_options} 2> "${output_files_script}.log" | |
printf -- '\n' | |
if [[ ${?} != 0 ]]; then | |
printf -- '! ERROR: Command "rmlint" did not exit properly!\n' | |
else | |
printf -- '# Outputs:\n' | |
printf -- ' • %s.csv\n' "${output_files_script}" | |
printf -- ' • %s.json\n' "${output_files_script}" | |
printf -- ' • %s.py\n' "${output_files_script}" | |
printf -- ' • %s.sh\n' "${output_files_script}" | |
printf -- ' • %s.log\n' "${output_files_script}" | |
printf -- '\n' | |
printf -- '# Basic Command:\n' | |
printf -- ' • %s.sh -x -c -k -d\n' "${output_files_script}" | |
fi | |
} | |
main "${@}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment