ZSH Tip of the Day: #1
As you can see in my zsh repository on GitHub, I spend a lot of time playing around with my zsh configuration. I'm going to present some of my favourite tricks here on this blog. Today I'll show a very useful function that handles extraction of files. It serves two purposes: it both abstracts away the specific extraction command and deletes the archive file (if successfully extracted). I call it ed:
# Extract & Delete ed() { case ${1##*.} in tar) tar -xvf $1 ;; tgz|gz) tar -zxvf $1 ;; tbz|tbz2|bz2) tar -jxvf $1 ;; zip) unzip $1 ;; rar) unrar x $1 ;; esac || return 1 rm $1 }
This allows you to do stuff like ed latest.tar.gz, and it would
have the same effect as tar -zxvf latest.tar.gz; rm latest.tar.gz.
As you can see, it determines which extraction command to use based on the file
extension. I find that I almost always want to delete archive files
after I have extracted them, hence the deletion. Hope you'll find it useful as well!
NOTE: In order to make Jekyll handle the # in the title of this post, I had to create a small patch.