Skip to content

Instantly share code, notes, and snippets.

@AbdallaZaki
Last active January 11, 2016 01:59
Show Gist options
  • Save AbdallaZaki/b14bbebe08adca5d9863 to your computer and use it in GitHub Desktop.
Save AbdallaZaki/b14bbebe08adca5d9863 to your computer and use it in GitHub Desktop.
#!/bin/bash
cd ~/Downloads
filetounrar=$(ls ./*.rar -t | head -n1)
function unrarmyfile ()
{
rar e "$filetounrar"
}
function userchoose ()
{
echo "[r]eplace [q]uit"
while read -r line ; do
if [ $line == "r" ]; then
unrarmyfile
elif [ $line == "q" ]; then
exit 1
else
userchoose
fi
done
}
if [[ -f "$filetounrar" ]] ; then
moviesfiles=$(rar lb "$filetounrar" | grep "\.\(mkv\|mp4\|rmvb\|flv\|mov\)$")
if [ -f $moviesfiles ]; then
userchoose
else
unrarmyfile
fi
if [ $? -eq 0 ] && [ ! -z "$moviesfiles" ]; then
if [ -z "$( pgrep totem )" ]; then
echo "$moviesfiles" | xargs -d "\n" totem &
else
echo "$moviesfiles" | xargs -d "\n" totem
fi
fi
else
echo "there is no file to unrar"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment