mirror of
https://github.com/mintycube/dotfiles.git
synced 2024-10-22 14:05:41 +02:00
64 lines
1.2 KiB
Plaintext
64 lines
1.2 KiB
Plaintext
|
#!/usr/bin/env sh
|
||
|
|
||
|
# Auto organize files into respective folders using categories
|
||
|
|
||
|
organize() {
|
||
|
case "$(file -biL "$1")" in
|
||
|
*video*)
|
||
|
[ ! -d "Videos" ] && mkdir "Videos"
|
||
|
mv -- "$1" "Videos/$1"
|
||
|
printf "Moved %s to Videos\n" "$1"
|
||
|
;;
|
||
|
|
||
|
*audio*)
|
||
|
[ ! -d "Audios" ] && mkdir "Audios"
|
||
|
mv -- "$1" "Audios/$1"
|
||
|
printf "Moved %s to Audios\n" "$1"
|
||
|
;;
|
||
|
|
||
|
*image*)
|
||
|
[ ! -d "Images" ] && mkdir "Images"
|
||
|
mv -- "$1" "Images/$1"
|
||
|
printf "Moved %s to Images\n" "$1"
|
||
|
;;
|
||
|
|
||
|
*pdf* | *document* | *epub* | *djvu* | *cb*)
|
||
|
[ ! -d "Documents" ] && mkdir "Documents"
|
||
|
mv -- "$1" "Documents/$1"
|
||
|
printf "Moved %s to Documents\n" "$1"
|
||
|
;;
|
||
|
|
||
|
*text*)
|
||
|
[ ! -d "Plaintext" ] && mkdir "Plaintext"
|
||
|
mv -- "$1" "Plaintext/$1"
|
||
|
printf "Moved %s to Plaintext\n" "$1"
|
||
|
;;
|
||
|
|
||
|
*tar* | *xz* | *compress* | *7z* | *rar* | *zip*)
|
||
|
[ ! -d "Compressed" ] && mkdir "Compressed"
|
||
|
mv -- "$1" "Compressed/$1"
|
||
|
printf "Moved %s to Compressed\n" "$1"
|
||
|
;;
|
||
|
|
||
|
*binary*)
|
||
|
[ ! -d "Binaries" ] && mkdir "Binaries"
|
||
|
mv -- "$1" "Binaries/$1"
|
||
|
printf "Moved %s to Binaries\n" "$1"
|
||
|
;;
|
||
|
|
||
|
*)
|
||
|
[ ! -d "Others" ] && mkdir "Others"
|
||
|
mv -- "$1" "Others/$1"
|
||
|
printf "Moved %s to Others\n" "$1"
|
||
|
;;
|
||
|
esac
|
||
|
}
|
||
|
|
||
|
main() {
|
||
|
for file in *; do
|
||
|
[ -f "$file" ] && organize "$file"
|
||
|
done
|
||
|
}
|
||
|
|
||
|
main "$@"
|