Last Updated: December 31, 2020
·
28.85K
· encodes

ZSH / .oh-my-zsh My top tips for daily use

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

Instead of

cd ../../..

Use

cd ....

Changing directories (case and fuzzy matching)

Zsh has a nice features of automatically converting case.
e.g.

/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.
```bash
vi **/views.py
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

More commands.

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 :)

10 Responses
Add your response

Nice one, I'll be sure to use these in the future !!

over 1 year ago ·

Once you go zsh, you'll never go bashck.

over 1 year ago ·

You can navigate through the folders and without cd...

/etc ⏎

pwd

/etc

over 1 year ago ·

Shell porn

over 1 year ago ·

/etc ⏎
pwd

Oh…THIS is awesome. LOVE zsh!! Thanks for the tip!

I highly recommend .YADR (Yet Another Dotfile Repo) that includes zsh and much, much more … http://skwp.github.io/dotfiles/

over 1 year ago ·

Switching to oh-my-zsh was the easiest quick win in my productivity in my day-to-day work. Especially autocomplete on remote host over scp and every directory having its own history of commands!

over 1 year ago ·

I highly recommend "jump" plugin for faster shell navigation.

over 1 year ago ·

:-)

over 1 year ago ·

I think there is two markdown typos: "```bash" ;). But really nice article thanks!

over 1 year ago ·

You can do a marvel team up of fasd and zsh to do quick directory navigation. Don't let the initial installation put you off. It's really very useful. https://github.com/clvv/fasd

over 1 year ago ·