#! /usr/bin/env nix-shell #! nix-shell -i bash -p bash trashy fd ripgrep file directories=("$HOME/Pictures/To Organize/" "$HOME/Downloads/" "$HOME/Downloads/cache") replace_extension() { local file_basename file_basename=$(basename "$1") echo "${file_basename%.*}.$2" } generate_random_number() { local min=0 local max=9999999999 printf "%010d\n" $((min + RANDOM % max)) } test_name() { local random_number random_number=$(generate_random_number) while (($(fd "$random_number"* "$HOME/Pictures/" "$HOME/Downloads/" -tf | wc -l) > 0)); do echo "Conflicts found, generating a new filename" random_number=$(generate_random_number) echo "$random_number" done echo "$random_number" } while IFS= read -r file; do regex_str='source|tenor|media|duckduckgo\.com|giphy|' regex_str+='(? 0)); then while IFS= read -r file; do date=$(stat -c "%y" "$file" | rg -o "\d{4}-\d{2}-\d{2}") year=$(echo "$date" | rg -o "\d{4}") month=$(echo "$date" | rg -o "\d{4}-\d{2}" | rg -o --pcre2 "(?<=-)\d{2}") parent_dir=$(dirname "$(realpath "$file")") dest_dir=$(realpath "$parent_dir")/$year/$month echo "Moving screenshot $(basename "$file") into $dest_dir" mkdir -vp "$dest_dir" command mv -n "$file" "$dest_dir/" done < <(fd . "${classify_directories[@]}" --absolute-path -tf -d 1) fi # Where steam screenshots are stored, may need to replace with ur ID dir_steam=$XDG_DATA_HOME/Steam/userdata/107446271/760/remote declare -A games # Insert here new games, put between [] the ID of the game # You can find it by visiting the $dir_steam directory # the ID is simply the name of the folder in there. games+=( [386360]=Smite [960090]="Bloons Tower Defense 6" [648800]=Raft [262060]="Darkest Dungeon" [234140]="Mad Max" [433340]="Slime Rancher" [1190460]="Death Stranding" [1850570]="Death Stranding" [440900]="Conan Exiles" [679110]="Werewolf Apocalypse" [2221490]="The Division 2" ) for key in "${!games[@]}"; do # Modify this to store your screenshots somewhere else dir_dest=$(realpath "$HOME/Pictures/Screenshots/Games")/${games[$key]} dir_game=$(realpath "$dir_steam")/$key/screenshots # If there are not screenshots currently stored, why bother lol if ! [[ -d $dir_game ]]; then # continue fi # If screenshots exist however... if ! (($(fd . "$dir_game" -d 1 -tf | wc -l) > 0)); then continue fi # Create destination directory mkdir -vp "$dir_dest" echo "Moving ${games[$key]} screenshots..." fd . "$dir_game" -d 1 -tf -x mv -n {} "$dir_dest"/ # Delete thumnnails echo "Deleting ${games[$key]} thumbnails..." rm -rf "$dir_game"/thumbnails done # Clearing up empty directories fd . "$dir_steam" -td -te -x trash {} cyberpunk_dir=$HOME/Games/gog/cyberpunk-2077/drive_c/users/jawz/Pictures/"Cyberpunk 2077" if [[ -d $cyberpunk_dir ]]; then while IFS= read -r file; do echo "Moving cyberpunk screenshots $(basename "$file")" command mv -n "$file" "$HOME/Pictures/Screenshots/Games/Cyberpunk 2077/" done < <(fd . "$cyberpunk_dir" -tf) fi proton_dir=$HOME/.steam/steam/compatibilitytools.d if [[ -d "$proton_dir" ]]; then while IFS= read -r protonver; do lutrisdir=$XDG_DATA_HOME/lutris/runners/wine/$(basename "$protonver") if [ -d "$lutrisdir" ] && [ -L "$lutrisdir" ]; then continue fi echo "Symlink $lutrisdir doesn't exist, creating link..." ln -s "$(realpath "$protonver")"/files "$lutrisdir" done < <(fd . "$proton_dir" -d 1 -td) fi fd . "$XDG_DATA_HOME/lutris/runners/wine" -d1 -tl -Lx trash {} while IFS= read -r file; do ext=$(file --mime-type "$file" | rg -o '\w+$') correct_ext=${ext,,} filename=$(basename -- "$file") current_ext="${filename##*.}" filename="${filename%.*}" if ! echo "$correct_ext" | rg -q 'jpe|jpg|jpeg|png|gif|webp'; then continue fi if [ "$current_ext" == "$correct_ext" ]; then continue fi echo "The file $(basename "$file")" \ "will be renamed, the propper extension is $correct_ext" new_name="$filename".$correct_ext if command mv -n "$(dirname "$file")"/{"$(basename "$file")","$new_name"}; then continue fi file_hash="$(sha256sum "$file" | gawk '{ print $1 }')" if ! echo "$file_hash $(dirname "$file")/$new_name" | sha256sum -c; then continue fi echo "deleting duplicated: $file" rm "$file" done < <(fd . "${directories[@]}" -d 1 -tf) files_home_clean=(.pki HuionCore.pid DriverUI.pid huion.log) for file in "${files_home_clean[@]}"; do file=$HOME/$file if [ ! -e "$file" ]; then continue fi rm -rf "$file" done