The terminal is a very crucial tool for any developer so it is really important to have a really nice terminal which makes a developer’s life easy. We will setup our mac terminal to be super easy for developers by installing and configuring the below tools
Homebrew
Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS operating system and Linux. It allows you to install, uninstall, and update command-line tools and Mac applications.
To install it, open the terminal, and run this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Make sure everything is up to date.
$ brew update
iTerm2
iTerm2 is an open source replacement for Apple’s Terminal. It’s highly customizable and comes with a lot of useful features.
To install iTerm2, open the terminal and run:
$ brew cask install iterm2
Zsh (skip – macOS Catalina users)
macOS Catalina comes with pre-installed and configured Zsh as the default terminal, so you don’t need to perform this step if you have macOS Catalina.
To install Zsh, open iTerm2 and run
$ brew install zsh
To set zsh as your default shell, execute the following.
$ sudo sh -c "echo $(which zsh) >> /etc/shells" && chsh -s $(which zsh)
Oh My Zsh
Oh-My-Zsh is an open source, community-driven framework for managing your ZSH configuration. It comes bundled with a ton of helpful functions, helpers, plugins, themes.
To install Oh My Zsh, run:
$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Using a Custom Theme
“Oh My ZSH” comes with tons of pre-built themes but to install another theme not pre-installed, clone the repository into custom/themes
directory. In this scenario, we’ll install a custom theme named powerlevel10k, it’s fast, it’s really well integrated with Git, it supports icons, and a lot more.
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
Then, select this theme in your ~/.zshrc
ZSH_THEME="powerlevel10k/powerlevel10k"
Update your changes by running the command source ~/.zshrc
When running for the 1st time it will prompt you to configure various options
Zsh plugins
Zsh has a great feature of adding plugins. Plugins add more functionalities like autocomplete, syntax suggestions, etc.
Installing Custom Plugins
There are a few very famous and must-have custom plugins that really make our life easy. To install a custom plugin we need to git clone the plugin repo to ~/.oh-my-zsh/custom/plugins and add the plugin name to the plugins section in ~/.zshrc
file.
1. Syntax Highlighting Plugin
This package provides syntax highlighting for the shell zsh. It enables the highlighting of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before running them, particularly in catching syntax errors.
Clone the repository in oh-my-zsh’s plugins directory:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Activate the plugin in ~/.zshrc
:
plugins=( [plugins...] zsh-syntax-highlighting)
Source ~/.zshrc
to take changes into account:
source ~/.zshrc
2. Auto Suggestion Plugin
It suggests commands as you type based on history and completions.
Clone the repository in oh-my-zsh’s plugins directory:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Activate the plugin in ~/.zshrc
:
plugins=( [plugins...] zsh-autosuggestions)
Source ~/.zshrc
to take changes into account:
source ~/.zshrc
3. History Search Plugin
Type in any part of any command from your history, and then press chosen keys, such as the UP(⬆️) and Down(⬇️) arrows, to cycle through matches.
Clone the repository in oh-my-zsh’s plugins directory:
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
Activate the plugin in ~/.zshrc
:
plugins=( [plugins...] history-substring-search)
Also, you need to map your arrow keys. Add the following either after the plugins section or at the end in your ~/.zshrc
file
bindkey '^[OA' history-substring-search-up
bindkey '^[OB' history-substring-search-down
Source ~/.zshrc
to take changes into account:
source ~/.zshrc
So after adding above plugins this is how my plugins section in ~/.zshrc file looks now.
plugins=(
zsh-syntax-highlighting
zsh-autosuggestions
zsh-history-substring-search
)
Installing pre-built plugins
Zsh also comes with some pre-installed plugins, so can just activate them by naming it in the plugins section inside your ~/.zshrc
file. Below are the suggested plugins and to view the complete list of built-in plugins.
- alias-finder: This plugin searches the defined aliases and outputs any that match the command inputted. This makes learning new aliases easier.
- autojump: A cd command that learns – easily navigate directories from the command line.
- brew: The plugin adds several aliases for common brew commands
- common-aliases: This plugin creates helpful shortcut aliases for many commonly used commands
- copydir: Copies the path of your current folder to the system clipboard
- copyfile: Puts the contents of a file in your system clipboard so you can paste it anywhere
- extract: This plugin defines a function called extract that extracts the archive file you pass it, and it supports a wide variety of archive file types
- git-auto-fetch: Automatically fetches all changes from all remotes while you are working in the git-initialized directory.
- git: Provides many aliases and a few useful functions
- npx: This plugin automatically registers the npx command-not-found handler if npx exists in your $PATH
- npm: The npm plugin provides completion as well as adding many useful aliases.
- nvm: This plugin adds autocompletion for nvm — a Node.js version manager. It also automatically sources nvm, so you don’t need to do it manually in your
.zshrc
. - osx: This plugin provides a few utilities to make it more enjoyable on macOS
- sudo: Easily prefix your current or previous commands with
sudo
by pressing esc twice - vscode: This plugin makes the interaction between the command line and the VS Code editor easier
- yarn: This plugin adds completion for the Yarn package manager, as well as some aliases for common Yarn commands.
So after adding the above plugins along with custom plugins this is how my plugins section in ~/.zshrc file looks now.
plugins=(
zsh-syntax-highlighting
zsh-autosuggestions
zsh-history-substring-search
alias-finder
autojump
brew
common-aliases
copydir
copyfile
extract
git
npm
npx
nvm
macos
sudo
vscode
Yarn
)
iTerm2 Color Scheme
Now let’s beautify our iTerm2 terminal by some iTerm2 color schemes.
- Navigate to iTerm2-Color-Schemes and download the ZIP folder.
- Extract the downloaded folder and move inside the “Schemes” folder which contains color scheme files ending with
.itermcolors
. - Open
iTerm2 > Preferences > Profile > Colors > Color Presets > Import
- In the import window, navigate to the schemes folder and select your preferred color schemes to import them.
- Click on a specific color scheme to activate it.
Color LS
A Ruby script that colorizes the ls
output with color and icons.
1. Install Ruby (preferably, version >= 2.5)
$ brew install ruby
Skip Step2 below as we have already installed “Nerd Font ” above while installing iTerm2.
2. Install the patched fonts of powerline nerd-font and/or font-awesome. Have a look at the Nerd Font README for more installation instructions.
Note for iTerm2
users – Please enable the Nerd Font at iTerm2 > Preferences > Profiles > Text > Non-ASCII font > Hack Regular Nerd Font Complete.
Note for HyperJS
users – Please add "Hack Regular Nerd"
Font as an option to fontFamily
in your ~/.hyper.js
file.
3. After installing ruby, let’s install color ls
$ sudo gem install colorls
If facing issue while installing ColorLs and the issue in the log file says
fatal error: 'ruby/config.h' file not found
. then here is the solution in Stackoverflow
4. Enable tab completion for flags by entering the following line to your shell configuration file (~/.bashrc
or ~/.zshrc
) :
source $(dirname $(gem which colorls))/tab_complete.sh
5. Now let’s create an alias for listing files/folders with icons using ColorLs.
In your .zshrc
file add the below code
alias lc='colorls -lA --sd'
Let me know your thoughts