I spend a fair amount of time in terminal emulators, and here is how I get a good experience on macOS. I use iTerm2, Zsh, and a few cool command-line tools.

iTerm2

I am working on macOS, and I prefer the iTerm2 terminal emulator over the macOS Terminal application:

iTerm2 in Action

I especially enjoy the ability to split panes horizontally and vertically, as well as the keyboard shortcuts to move around.

I use the minimal theme with the tab bar on top and the status bar in the bottom with a few helper icons like CPU usage and current process. The color theme is Dracula. I like this theme very much also in other tools, notably Visual Studio Code which is my currently preferred editor aside from IntelliJ IDEA for Java projects. I also use the Cascadia font from Microsoft which is my preferred monospace font these days.

Dot files

Everyone has their preferences for managing dot files.

I am using a simple repository for that, with a bill-of-materials for applications to install automatically: https://github.com/jponge/dotfiles/tree/2019 (the 2019 edition, switch to another branch if you want).

The dot files get sym-linked using GNU Stow. For instance ~/.zshrc points to ~/dotfiles/home/.zshrc.

There are various environment variables and shell functions that I rely on. They can be found in ~/dotfiles/env, and they get loaded from ~/.zshrc (or ~/.bash_profile if you prefer Bash) using a simple for-loop:

for envfile in ~/dotfiles/env/*.sh; do
  source ${envfile}
done

Oh My Zsh

There exist several Zsh plugin managers, but if you want something with sensible defaults and batteries included then Oh My Zsh is a no-brainer.

Once you have it installed, you will open ~/.zshrc and start tweaking the configuration. It is very likely that you will start with the theme πŸ˜‰

I personally like the default robbyrussell, but you can also use a random theme and eventually find something you like better:

# (...)
ZSH_THEME="random"
# (...)

Next come the plugins, and this is all about the tools that you need to use on daily basis. Check ~/.oh-my-zsh/plugins/ to see all the plugins that come with Oh My Zsh.

I personally have the following plugins in use, more on them in the next sections:

plugins=(
  git
  docker
  fzf
  httpie
  minikube
  zsh-syntax-highlighting
  zsh-autosuggestions
)

I’d recommend not having too many plugins in use. You can often replace a plugin with loading a Zsh completion from the tool.

fzf, a command-line fuzzy finder

You will have to install the tool for the corresponding Oh My Zsh plugin to work, so go to https://github.com/junegunn/fzf.

This tool will help your for completions. A lot πŸ˜‰

Syntax highlighting

This external plugin provides syntax highlighting as you type shell commands, much like the Fish shell would do. This is very useful, especially since you get instant feedback on non-existing commands, etc.

Head over to https://github.com/zsh-users/zsh-syntax-highlighting for installation instructions, aka:

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \
    ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Auto-suggestions

There is another useful plugin for having a Fish-like experience with completion suggestions based on past history.

Go to https://github.com/zsh-users/zsh-autosuggestions for more details, or simply run:

git clone https://github.com/zsh-users/zsh-autosuggestions \
    ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Misc. useful command-line tools

There are a bunch of command-line tools that I use but that not everyone may know.

  • HTTPie is great for doing HTTP requests. It comes with syntax highlighting and sensible ways to pass form fields, JSON data, files, etc. It is much better that cURL in a development context.
  • pstree to list processes as a parent-child tree. This is not installed by default on macOS.
  • bat is similar to cat, except it offers syntax highlighting (and other goodies).
  • watchexec is a general-purpose tool to watch files and trigger a command in response to changes.
  • dive is a tool for exploring Docker images, and especially see what each layer brings to the filesystem.
  • foreman is a tool for running multiple processes. You just specify commands in a Procfile, and then start them all and check their logs. It is very useful in development when you need to start many processes.
  • hub is the GitHub command-line tool for interacting with repositories. It is especially useful for checking out pull-requests.
  • plantuml is a fantastic tool for generating all sorts of diagrams from… text.
  • jabba is a tool for managing Java virtual machines. It is frequently updated with builds of OpenJDK, Azul Zulu, GraalVM, Amazon Corretto, OpenJ9, etc.

Edited: December 3rd 2019

Since I wrote that post I came across further great command-line tools and tips πŸ˜‰

  • kube-ps1 adds current Kubernetes context and namespace to the shell prompt. I do not enable it by default and I have a function ready when I need to enable it:
use_kube_ps1() {
    source "/usr/local/opt/kube-ps1/share/kube-ps1.sh"
    PS1='$(kube_ps1)'$PS1
}
  • htop is a replacement for top with a much much improved user interface.
  • fd is a modern alternative to find.
  • noti executes a command and sends a notification when done. This is very useful when running a long build, an upload, etc.
  • ag is a code search tool that can replace grep in many situations.

I also added some aliases to simplify my kubectl usage:

alias k="kubectl"
alias ka="kubectl apply -f"
alias kd="kubectl delete -f"
alias kgp="kubectl get pods"
alias kgs="kubectl get services"

Finally my growing usage of bat instead of cat has prompted me to define the following environment variables to have more sensible defaults:

export BAT_THEME="ansi-dark"
export BAT_STYLE="plain"