Improving upon the default Mac Terminal to increase Productivity and improve InterfaceSimple shell customisation techniquesKaran BhanotBlockedUnblockFollowFollowingMay 29Photo by Goran Ivos on UnsplashIf you’re like me, you work on many projects and each project could be located in different directories and may involve multiple branches.
Recently, I customised my terminal to make it more informative as well as much more easier to read and use.
In this article, I’ll walk you through the steps I took to customise the terminal to help me.
There are many ways you can go along but here I’m presenting the one I found the most simple and that fits my need the best.
In this article, we’ll go from here:Oldto here:NewInstall iTerm2iTerm2 extends the MacOS terminal and adds a number of useful features to it.
Two features I love include the ability to split panes vertically using Shell > Split Vertically with Current Profile (horizontally is also possible) and the multitude of options to configure this terminal.
There are other features too which you can find here.
Go to https://www.
Download the version located under Stable Releases.
It will download the zip file.
Extract the zip file and the new file will be visible as iTerm.
Just open this app and you’re inside iTerm2.
Two iTerm2 terminals opened side-by-sideChange shell to ZSHThe next step is to change our backend from bash to zsh.
In iTerm2, type the command which zsh.
You should see the output as /bin/zsh.
If nothing shows up, you’ll need to download it using brew install zsh.
Then type which zsh and see if you can see a new path as /usr/local/bin/zsh.
Next, type the command sudo vi /etc/shells and then enter your password.
The file will open.
Go into insert mode by pressing i on the keyboard.
Add the lines /bin/zsh and /usr/local/bin/zsh after the other shells.
Press escape to exit out of insert mode.
Once done, save the changes by typing :wq which refers to write and quit.
We can now switch to zsh.
Type the command chsh -s $(which zsh).
The shell is now changed to zsh.
Close iTerm2 and open it again.
Adding zsh to the list of shellsChanging the shell to zshInstalling Oh My ZshOh My Zsh works on top of zsh.
It provides us with a configuration file ~/.
zshrc and allows us to apply themes to make iTerm2 more attractive and usable.
The GitHub repo is available here.
Run the command sh -c “$(curl -fsSL https://raw.
sh)" to install the package.
Reopen iTerm2 and it will have Oh My Zsh enabled.
Installing Oh My ZshThere will be no visual difference right now but we’ll have the ~/.
zshrc file where we can make updates for iTerm2.
Using pluginsI’ll use three plugins, namely, git, syntax highlighting and suggestions.
Git is already included in the list of plugins so we won’t download it.
For the other two plugins, we’ll have to clone them in the right directory.
git clone https://github.
oh-my-zsh/custom}/plugins/zsh-syntax-highlightinggit clone https://github.
com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestionsInstalling pluginsOnce done, open the .
zshrc file by using the command open ~/.
Add the two plugin names zsh-syntax-highlighting and zsh-autosuggestions inside the parenthesis each in its own line after git.
Just save the file and we’re good to go.
Updated plugins to include the new pluginsReopen iTerm2 so that the new changes can take effect.
Taking a look at the image below, you can see that the text cd is now in a different colour and after writing the text Personal, it suggests the next folder Important Work.
The plugins are working perfectly.
Plugins in actionImplementing Powerline designWe’ll need to update the ~/.
zshrc file to show a powerline like design that also shows the branch we are in and if there are any changes in the branch.
zshrc file using open ~/.
Then change the ZSH_THEME to agnoster.
agnoster themeAs we can see, the whole path is visible and whenever we are inside a git repository, the current branch’s name is displayed.
For example, in the case above, I’m in the master branch.
If there are changes that are not yet commit, a dot will appear after the branch name.
Update colorsGiven that the text is not very readable due to the choice of colors, I decided to change the colors to a preset colour scheme.
When in an active iTerm2 window, go to the top corner and in iTerm2 select Preferences > Profiles > Colors.
In the window, at the bottom right under Color Presets.
select Tango Dark and the colors will get updated.
Select Tango Dark color presetUpdated colors for the shellAdd an intro messageJust for fun we can also add a message, each time we will open up a new iTerm2 window or tab.
I’ll show my name, date and a random fortune.
Install the fortune package which will help us display the random fortune using brew install fortune.
zshrc using open ~/.
Go to the end and type the following command which will display my name and the current date, each time I open iTerm2 window or tab.
echo "|| NAME: KARAN BHANOT|| DATE: $(date)|||| $(fortune)"Intro message addedConclusionFinally, we’re done.
We’ve done many modifications to our terminal and now it provides us with information as well as makes it appear more pleasing to the eyes.
Hope you liked this article.
Do share your ideas, thoughts and suggestions.
.. More details