First commit
Clean Lightroom backup folders
This commit is contained in:
80
lightroom.command
Executable file
80
lightroom.command
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
italic="\033[3m"
|
||||
underline="\033[4m"
|
||||
ita_under="\033[3;4m"
|
||||
bgd="\033[1;4;31m"
|
||||
red="\033[1;31m"
|
||||
bold="\033[1m"
|
||||
box="\033[1;41m"
|
||||
reset="\033[0m"
|
||||
|
||||
# No distract mode (no user interaction)
|
||||
[[ $@ =~ "-nodistract" || $@ =~ "-n" ]] && no_distract=true || no_distract=false
|
||||
|
||||
command -v fd >/dev/null 2>&1 || { echo -e "${bold}Clean Lightroom backups${reset} require ${bold}fd${reset} but it's not installed.\nRun ${italic}(brew install fd)${reset}\nAborting..." >&2; exit 1; }
|
||||
|
||||
echo -e "${bold}+++ Clean Lightroom backups +++${reset}\n"
|
||||
|
||||
echo -e "${underline}Preferences:${reset}"
|
||||
|
||||
# Dossiers des catalogues Lightroom
|
||||
lightroom=/Users/bruno/Pictures/Lightroom
|
||||
echo "Catalog's folder: $lightroom"
|
||||
|
||||
# Liste des catalogues Lightroom
|
||||
catalogs=$(fd -I -t file '^.*.lrcat$' $lightroom)
|
||||
|
||||
# Laisser n backup
|
||||
n=2
|
||||
echo -e "Keep $n backups..."
|
||||
|
||||
echo -e "Backups with extra names like '2022-01-20 0926 MàJ 2021' won't be deleted ...\n"
|
||||
|
||||
while IFS= read -r line; do
|
||||
l="${line}"
|
||||
|
||||
catalog=$(basename "$l")
|
||||
echo -e "${bold}$catalog${reset}"
|
||||
folder=$(dirname "$l")
|
||||
|
||||
if [ -d "$folder/Backups" ]; then
|
||||
|
||||
backup=$(ls -t "$folder/Backups" | grep -v '[[:alpha:]]')
|
||||
echo -e "${underline}Availables backup:${reset}"
|
||||
echo "$backup"
|
||||
nb=$(echo "$backup" | wc -l)
|
||||
trash=$(echo "$backup" | tail -n $((nb-$n)))
|
||||
|
||||
if [ -n "$trash" ]; then
|
||||
while IFS= read -r z; do
|
||||
|
||||
x="$folder/Backups/${z}"
|
||||
|
||||
if [ -d "$x" ]; then
|
||||
|
||||
if [ $(ls -A "$x" | wc -l) -ne 0 ]; then
|
||||
|
||||
if [ "$no_distract" = false ]; then
|
||||
echo -e "${italic}Do you want to delete $x (y/n)?${reset}"
|
||||
read -u 1 answer
|
||||
if [[ $answer = y ]]; then
|
||||
rm -r "$x"
|
||||
fi
|
||||
else
|
||||
echo -e "${italic}Deleting $x ...${reset}"
|
||||
rm -r "$x"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
done <<< "$trash"
|
||||
|
||||
else
|
||||
echo "No backup folder to delete !"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
fi
|
||||
|
||||
done <<< "$catalogs"
|
||||
Reference in New Issue
Block a user