Skip to content

Instantly share code, notes, and snippets.

@binarytemple
Forked from gburd/extract
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save binarytemple/4337496a171e67335bc1 to your computer and use it in GitHub Desktop.

Select an option

Save binarytemple/4337496a171e67335bc1 to your computer and use it in GitHub Desktop.
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 && cd $(basename "$1" .tar.bz2) ;;
*.tar.gz) tar xvzf $1 && cd $(basename "$1" .tar.gz) ;;
*.tar.xz) tar Jxvf $1 && cd $(basename "$1" .tar.xz) ;;
*.bz2) bunzip2 $1 && cd $(basename "$1" /bz2) ;;
*.rar) unrar x $1 && cd $(basename "$1" .rar) ;;
*.gz) gunzip $1 && cd $(basename "$1" .gz) ;;
*.tar) tar xvf $1 && cd $(basename "$1" .tar) ;;
*.tbz2) tar xvjf $1 && cd $(basename "$1" .tbz2) ;;
*.tgz) tar xvzf $1 && cd $(basename "$1" .tgz) ;;
*.zip) unzip $1 && cd $(basename "$1" .zip) ;;
*.Z) uncompress $1 && cd $(basename "$1" .Z) ;;
*.7z) 7z x $1 && cd $(basename "$1" .7z) ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
@binarytemple
Copy link
Author

mv archives.zsh ~/.zshrc.archives
echo "source ~/.zshrc.archives" >> ~/.zshrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment