split configs into two systems...
This commit is contained in:
140
workstation/scripts/tasks.sh
Executable file
140
workstation/scripts/tasks.sh
Executable file
@@ -0,0 +1,140 @@
|
||||
#! /usr/bin/env nix-shell
|
||||
#! nix-shell -i bash -p bash trashy fd ripgrep file
|
||||
|
||||
directories=("$HOME/Pictures/To Organize/" "$HOME/Downloads/")
|
||||
|
||||
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+='(?<!app)image|^download|unknown|zoom|'
|
||||
regex_str+='new_canvas|untitled|drawpile'
|
||||
if basename "$file" | rg --pcre2 -q "$regex_str"; then
|
||||
new_name=$(test_name)
|
||||
echo renaming
|
||||
echo "$file"
|
||||
echo into
|
||||
echo "$(dirname "$file")"/"$new_name"
|
||||
echo ---------------
|
||||
command mv -n "$(dirname "$file")"/{"$(basename "$file")","$new_name"}
|
||||
fi
|
||||
if basename "$file" | rg -q 'Screenshot_\d{8}'; then
|
||||
echo "moving screenshot $file into $HOME/Pictures/Screenshots/"
|
||||
command mv -n "$file" "$HOME/Pictures/Screenshots/"
|
||||
fi
|
||||
done < <(fd . "${directories[@]}" -d 1 -tf --absolute-path)
|
||||
|
||||
screenshots=$HOME/Pictures/Screenshots
|
||||
if (($(fd . "$screenshots" -tf -d 1 | wc -l) > 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}")
|
||||
dest_dir=$(realpath "$screenshots/$year/$month")
|
||||
echo "Moving screenshot $(basename "$file") into $dest_dir"
|
||||
mkdir -vp "$dest_dir"
|
||||
command mv -n "$file" "$dest_dir/"
|
||||
done < <(fd . "$screenshots" --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"
|
||||
)
|
||||
|
||||
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
|
||||
# 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
|
||||
fi
|
||||
done
|
||||
# Clearing up empty directories
|
||||
fd . "$dir_steam" -td -te -x trash {}
|
||||
|
||||
cyberpunk_dir=$HOME/Games/cyberpunk-2077/drive_c/users/jawz/Pictures/"Cyberpunk 2077"
|
||||
if [[ -d $cyberpunk_dir ]]; then
|
||||
while IFS= read -r file; do
|
||||
echo "Moving cyberpunk screenshots"
|
||||
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
|
||||
echo "Symlink $lutrisdir doesn't exist, creating link..."
|
||||
ln -s "$(realpath "$protonver")"/files "$lutrisdir"
|
||||
fi
|
||||
done < <(fd . "$proton_dir" -d 1 -td)
|
||||
fi
|
||||
fd . "$XDG_DATA_HOME/lutris/runners/wine" -d 1 -tl -x 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'; then
|
||||
if [ "$current_ext" != "$correct_ext" ]; then
|
||||
echo "The file $(basename "$file")" \
|
||||
"will be renamed, the propper extension is $correct_ext"
|
||||
new_name="$filename".$correct_ext
|
||||
command mv -n "$(dirname "$file")"/{"$(basename "$file")","$new_name"}
|
||||
fi
|
||||
fi
|
||||
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
|
||||
rm -rf "$file"
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user