The terminal is a powerful tool. It's useful for many tasks, from creating, copying, moving and deleting files, to executing scripts and running programs. However, its default settings are not particularly user-friendly, and as software engineers we're used to our code editors helping us out.
Don't despair! With some simple changes you can drastically improve the zsh terminal experience by adding two super useful features - autosuggestions and syntax highlighting. And if you've just got a new MacBook like me then this is the perfect time to level up your setup!
Follow these simple steps to get set up:
Use Homebrew to install zsh plugins
- Install zsh-autosuggestions
- Install zsh-syntax-highlighting
brew install zsh-autosuggestions brew install zsh-syntax-highlighting
More plugins, including these two, can be found in the zsh community project repo on Github.
* This step assumes you already have Homebrew installed. I'll do a post on this soon! If you don't use Homebrew then check out the docs linked above for alternative ways to install.
Add to your
If it doesn't already exist, create this file in the root of your user directory. The easiest way to do this is to run
Add the following lines to the
.zshrc file to import the code for the plugins
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
For more information about this file and other zsh configuration files, see this post.
Active the zsh changes
For your changes to take effect either restart your terminal window or run this command to
force zsh to reload its sources in
And that's it! 🎉
Try it out for yourself. Now when you type in the terminal you should see syntax
highlighting. Let's take the
mkdir test command for example.
m shows in red to highlight this is not a valid command.
Continuing to type
mkdir turns it green, highlighting that this is a valid command! Complete
running this command with
Now this command has been run, the next time we type
m the auto-suggestions has remembered
the previous command and suggests it to us. Just hit the right arrow to auto-complete
I hope this small change facilitates your workflow and makes using your zsh terminal shell more enjoyable!
For even more options to enhance your terminal check out projects like oh-my-zsh and the Fish shell. However, the simple changes outlined in this post are a great addition to level up your terminal experience.