Skip to content

Instantly share code, notes, and snippets.

@antonva
Created January 23, 2015 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonva/5f29b6d65948c8fd2ac9 to your computer and use it in GitHub Desktop.
Save antonva/5f29b6d65948c8fd2ac9 to your computer and use it in GitHub Desktop.
#!/usr/bin/bash
#Copyright (C) <2014> <Anton Vilhelm Ásgeirsson>
#
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
# Extensions handled by homecleaner:
# .torrent
# .mp3/.ogg/.flac/.wav
# .pdf
# .html/.css
# .xls/.xlsx
# .zip/.rar/.tar/.gz/.bz2/.7z
#.torrent
# Checks for files with '.torrent' extension in ~/Downloads/ and handles them appropriaetly
TORRENTS=$(ls -1 ~/Downloads/*.torrent 2>/dev/null | wc -l)
if [ $TORRENTS != 0 ]; then
if [ ! -d ~/Torrents/ ]; then
mkdir ~/Torrents/
echo "Created ~/Torrents/"
fi
mv ~/Downloads/*.torrent ~/Torrents/
echo "[+] moved .torrent files."
else
echo "[-] no .torrent files found."
fi
# .mp3/.ogg/.flac/.wav
AUDIO=$(ls -1 ~/Downloads/*.{mp3,ogg,flac,wav} 2>/dev/null | wc -l)
if [ $AUDIO != 0 ]; then
if [ ! -d ~/Downloads/Audio/ ]; then
mkdir ~/Downloads/Audio/
echo "Created ~/Downloads/Audio/"
fi
mv ~/Downloads/*.{mp3,ogg,flac,wav} ~/Downloads/Audio/
fi
# .pdf/.txt/.doc(x)/.xls(x)/.conf
TEXT=$(ls -1 ~/Downloads/*.{pdf,txt,doc,docx,xls,csv,conf} 2>/dev/null | wc -l)
if [ $TEXT != 0 ]; then
if [ ! -d ~/Downloads/Text/ ]; then
mkdir ~/Downloads/Text/
echo "Created ~/Downloads/Text/"
fi
mv ~/Downloads/*.{pdf,txt,doc,docx,xls,csv,conf} ~/Downloads/Text/ > /dev/null 2>&1
fi
# .html/.css
# .xls/.xlsx
# .zip/.rar/.tar/.gz/.bz2/.7z
ARCHIVES=$(ls -1 ~/Downloads/*.{zip,rar,tar,gz,bz2,7z} 2>/dev/null | wc -l)
if [ $ARCHIVES != 0 ]; then
if [ ! -d ~/Downloads/Archives/ ]; then
mkdir ~/Downloads/Archives/
echo "Created ~/Downloads/Archives/"
fi
mv ~/Downloads/*.{zip,rar,tar,gz,bz2,7z} ~/Downloads/Archives/
fi
#.avi/.mov/.mp4/.mkv/.webm
VIDEOS=$(ls -1 ~/Downloads/*.{avi,mov,mp4,mkv,webm} 2>/dev/null | wc -l)
if [ $VIDEOS != 0 ]; then
if [ ! -d ~/Downloads/Videos/ ]; then
mkdir ~/Downloads/Videos/
echo "Created ~/Downloads/Videos/"
fi
mv ~/Downloads/*.{avi,mov,mp4,mkv,webm} ~/Downloads/Videos/ > /dev/null 2>&1
fi
#.jpg/.jpeg/.png/.gif/.bmp/.cr2/.CR2/.tiff
IMAGES=$(ls -1 ~/Downloads/*.{jpg,jpeg,png,gif,bmp,tiff,cr2,CR2} 2>/dev/null | wc -l)
if [ $IMAGES != 0 ]; then
if [ ! -d ~/Downloads/Images/ ]; then
mkdir ~/Downloads/Images/
echo "Created ~/Downloads/Images/"
fi
mv ~/Downloads/*.{jpg,jpeg,png,gif,bmp,tiuff,cr2,CR2} ~/Downloads/Images/ > /dev/null 2>&1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment