ZSH And oh my ZSH
One of the common questions I am asked is why switch from Bash to Zsh... There are many reason's.. too many to explain. I've compiled a small list of tiny tip's. One's that are time saving and productive. This is not a shell scripting article. Its a day to day use of the shell article.
To install ZSH and oh my zsh take a look at your OS or do a quick google. Yum install zsh etc will work on centos/redhat/fedora.
Then head over to oh-my-zsh github and follow the instructions.
The small things
My favourite feature is the ability to have 2 prompts left and right. The built in git support (it can be done in BASH) and the various plugins that usually fill your needs. The ability to have complex prompts is awesome. I have the directory, virtualenv and git status on the left and the time on the right. See my ZSH theme here:
toothe.zsh-theme Its nice and simple but gives and overall Bash/ZSH crossover without being too complex.
Other people take it further with some great tutorials out there.
zsh promtp tips
If like me you spend half the day or more in the black window ZSH will make your day more productive and much more fun.
Changing Up directories
Changing directories (case and fuzzy matching)
Zsh has a nice features of automatically converting case.
/home/encodes/ProjecTs cd /home/encodes/p[tab]
On tab it will find any directories with lowercase p. If no lowercase p directories exist it will automatically convert. If there is upper and lowercase directories starting with p, two tabs will list them all.
ZSH will also use fuzzy matching to extend directories. sp
cd /h/enco/proj will expand to /home/encodes/Projects
This obviously works if there is only one match, but if there is multiple it will give you a list.
Open a file anywhere in the hierarchy.
This one i love. If your at the route of a project and you want to open a particular file you can do the following.
which will open and views.py no matter where it exists in the heirachy.
another nice little tip is using it to find a matching css rule or similiar ```bash cat **/*.css | grep '#rule'
List small files only / Date and other cool List commands.
Sometimes if you have a large directory you will want to just list tiny files (possible remains of old files, or images that you know have broken etc...
ls -l *(.L-50) # list file size less than 50 bytes (the . ignores directories) ls -l *(Lm+50) # list file size larger/greater than 50 mb ls -l *(m1) # list files modified exactly 1 day ago ls -l *(.m4) # as above but ignoring the directory. ls -lt **/*.py(.om[1,20]) # list 20 newest python (.py) files anywhere in directory hierarchy
There are so many things to look at with ZSH. One of the main problems is anyone new to bash/zsh doesn't always realise the power of the commands. If you want to take a look at a comprehensive list of ZSH shortcuts and tips head over to http://www.rayninfo.co.uk/tips/zshtips.html
I'll aim to write a ZSH scripting tutorial when I next have time.
Enjoy and let me know your favourite ZSH / oh-my-zsh features :)