Using ZSH functions to improve your terminal experience

José Ney Guerrero
DAK42
Published in
1 min readNov 12, 2018

The shell I love is zsh and it brings some functions that we can use to change the behavior of the shell, in this case I’m going to use two hook functions:

  • chpwd (is executed whenever the current working directory is changed)
  • precmd (is executed before each prompt)

How many times you’ve done cd something and immediately run ls to list the files in the new current directory, using chpwd is so easy to automate this, adding to your .zshrc file:

function chpwd() {
ls -la
}

Now each time you change your current working directory, it will execute the code inside the function.

I’ve made a program that shows me a random quote in the terminal, now if I wanted to show a quote in the terminal every time the prompt is shown, I could do:

function precmd() {
quote -n
}

There is a list of more functions that you can use, just take a look at the docs http://zsh.sourceforge.net/Doc/Release/Functions.html

--

--