dotfiles/base/.config/systemd/user/autocategorize

90 lines
2.2 KiB
Plaintext
Raw Normal View History

2023-06-15 15:31:12 -05:00
#! /bin/sh
set -e
# Pull in user-dirs.dirs if it exists
userdirs="${XDG_CONFIG_DIR:-$HOME/.config}"/user-dirs.dirs
[ -f "$userdirs" ] && . "$userdirs"
# Obtain download directory from there, otherwise use default
downloaddir="${XDG_DOWNLOAD_DIR:-$HOME/Downloads}"
documentsdir="${XDG_DOCUMENTS_DIR:-$HOME/Documents}"
picturesdir="${XDG_PICTURES_DIR:-$HOME/Pictures}"
2024-01-18 20:06:58 -06:00
videosdir="${XDG_VIDEOS_DIR:-$HOME/Videos}"
2024-12-23 12:21:23 -06:00
# If we have Nextcloud installed, this will be our backups dir
backupsdir="${HOME}/Nextcloud/Backups"
2024-01-18 20:06:58 -06:00
# Take loose crap out of the home folder
echo "Sorting away videos from homedir..."
find "$HOME" \
-maxdepth 1 \
-type f \
\( \
-iname "*.mov" -or \
-iname "*.webm" -or \
-iname "*.mkv" -or \
-iname "*.mp4" \
\) \
-print \
-exec mv {} "$videosdir" \;
echo "Sorting away pictures from homedir..."
find "$HOME" \
-maxdepth 1 \
-type f \
\( \
-iname "*.jpg" -or \
-iname "*.jpeg" -or \
-iname "*.gif" -or \
-iname "*.png" -or \
-iname "*.webp" \
\) \
-print \
-exec mv {} "$picturesdir" \;
2023-06-15 15:31:12 -05:00
# Sort out downloads
[ -e "$downloaddir" ] && {
# Sort out epubs
if [ -d ~/Books ]; then
echo "Sorting out books..."
find "$downloaddir" \
-type f \
2024-01-18 20:06:58 -06:00
\( \
2023-06-15 15:31:12 -05:00
-iname "*.epub" -or \
-iname "*.mobi" \
2024-01-18 20:06:58 -06:00
\) \
2023-06-15 15:31:12 -05:00
-print \
-exec mv {} ~/Books \;
fi
2024-11-27 16:38:55 -06:00
# Remove RDP stuffs
echo "Removing RDP zone identifiers..."
find "$downloaddir" \
-type f -iname "*:Zone.Identifier" \
-print -delete
2023-06-15 15:31:12 -05:00
# Remove anything that's wicked old
echo "Removing ancient downloads..."
find "$downloaddir" \
-mtime +180 \
-print -delete
# Remove anything kinda old but really big
echo "Removing large downloads..."
find "$downloaddir" \
2024-09-14 13:31:30 -05:00
-mtime +30 -size +10M \
2023-06-15 15:31:12 -05:00
-print -delete
# Remove zips, but at a lower tolerance
echo "Removing old zips..."
find "$downloaddir" \
-mtime +30 -type f -iname "*.zip" \
-print -delete
2024-12-23 12:21:23 -06:00
# Sort out Super Turtle Idle automatic backups
[ -d "$backupsdir" ] && {
echo "Sorting out turtle backups..."
mkdir -p "$backupsdir/SuperTurtleIdle"
for file in "$downloaddir"/SuperSaveData-*.json; do
if [ -e "$file" ]; then
lastmod="$(stat -c %y -- "$file")"
echo "Moving backup from $lastmod"
mv "$file" "$backupsdir/SuperTurtleIdle/SuperSaveData-$lastmod.json"
fi
done
}
2023-06-15 15:31:12 -05:00
}