Last Updated: February 25, 2016
·
663
· dmitree

Make your life easier with zsh.

1) Usually we open files with commands like this:

$ vim filename.php
$ unzip file.zip

Thats fine, until you are doing it 100 times a day. With zsh you can specify default command for specific file types. Here is my example from ~/.zshrc file:

alias -s php=vim
alias -s html=vim
alias -s phtml=vim
alias -s css=vim
alias -s less=vim
alias -s js=vim
alias -s rb=vim
alias -s txt=vim
alias -s md=vim
alias -s srt=vim
alias -s json=vim

alias -s torrent=transmission-cli

alias -s mp4=mplayer
alias -s avi=mplayer
alias -s mkv=mplayer

alias -s zip=unzip

This list is incomplete, but you got the idea.

Now just by doing this, you will achieve same result:

$ filename.php
$ file.zip

2) alias -g:

alias -g G='| grep -i '
alias -g SU='-sub '
alias -g C='| reattach-to-user-namespace pbcopy'
alias -g T='| tail'
alias -g H='| head'

Here is mine humble list of -g aliases. So what it does? In my case capital G will allow me to write something like ls G foo instead of ls | grep -i foo. Pretty neat, huh?

3) Thats not it, lets save even more keystrokes with hash -d command:

hash -d dl=~/Downloads
hash -d b=~/bin
hash -d re=~/dev/repos
hash -d gi=~/dev/gists
hash -d db=~/Dropbox

What this will allow us to do is, when you type in dl , or ~dl or ~dl/ it will cd to Downloads folder.

You are wondering whats the difference between making regular alias and using this? Well, if you write ~dl/ and press tab, it will make auto complete of whats inside that directory.