-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspringclean
executable file
·62 lines (61 loc) · 1.59 KB
/
springclean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
#script to tidy up your downloads folder by moving different files to their designated folder
read -n1 -p "Ready to clean up your downloads? [Y/n]:" choice
if [[ $choice != 'Y' && $choice != 'y' ]]; then
exit
fi
cd ~/Downloads || exit
printf "\n===================\n"
for file in ./*; do
filename=$(basename "$file")
echo "File: $filename"
extension=${filename##*.} #get extension by removing longest *. match
case $extension in
pdf | epub | doc | docx | odf)
folder=~/Documents
;;
jpg | jpeg | png | svg)
folder=~/Pictures
;;
mp3)
folder=~/Music
;;
mp4)
folder=~/Videos
;;
*)
folder="[choose folder]"
;;
esac
read -n1 -p "==> [S]kip [M]ove to $folder [T]rash [E]xit" choice
case $choice in
S | s)
echo -ne "\r\033[K==> Skipped"
;;
M | m)
if [[ "$folder" == "[choose folder]" ]]; then
echo ""
read -p "Enter folder path: " folder
folder="${folder/#\~/$HOME}"
if [[ ! -d "$folder" ]]; then
echo "Not a valid path! Skipping..."
continue
fi
fi
mv "$file" "$folder" || continue
echo -ne "\r\033[K==> Moved to $folder"
;;
T | t)
gio trash "$file" || continue
echo -ne "\r\033[K==> Trashed"
;;
E | e)
echo -ne "\r\033[K==> Exiting..."
exit
;;
*)
echo -ne "\r\033[K==> Invalid input! Skipping..."
;;
esac
printf "\n===================\n"
done