First, what is the command prompt? From Wikipedia:
A command prompt (or just prompt) is a sequence of (one or more) characters used in a command-line interface to indicate readiness to accept commands. It literally prompts the user to take action. A prompt usually ends with one of the characters
>and often includes other information, such as the path of the current working directory and the hostname.
By default, macOS comes with Bash, Terminal, and the default command prompt:
<hostname>:<directory> <username>$ echo Hello, World! Hello, World!
In my setup, I use Zsh, instead of Bash, with Oh My Zsh, a community-driven Zsh framework for managing Zsh configuration. I don’t necessarily think that Zsh is better than Bash, but I do like the fact that the Oh My Zsh framework comes with powerful defaults. For example, when changing to a certain directory in the terminal using autocomplete, the default behavior of the Oh My Zsh framework allows autocompletion without having to care about capitalization, see video below.
Note: There exist many shell configuration frameworks like Bash-it, zplug, and more.
More importantly, the Oh My Zsh framework comes with many built-in prompt themes that display the necessary Git state of a directory. The Zsh theme that I am using at the moment is called Spaceship, an external Zsh theme, which comes with a nice default prompt that is very informative, and allows easy configuration of the prompt when necessary.
# On macOS $ brew install zsh # On Ubuntu $ sudo apt-get install zsh
Install Oh My Zsh:
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
$ git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt" $ ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"
Note: Spacehip recommends using a Powerline font for displaying certain symbols. For example, for Git it shows a branching symbol, see video below. However, if you don’t care about this, you can configure the Spaceship theme to just ignore this symbol by setting
~/.zshrcbefore sourcing the theme.
The last step is to change the Zsh theme. Set
.zshrc file is loaded on startup by Zsh.
We have seen how to configure the command prompt using Zsh, Oh My Zsh, and Spaceship. In my opinion, it is essential to have a well-configured prompt when working in the terminal. Also, I would strongly recommend using iTerm2 over the default Terminal application due to its more sophisticated panes management, path selection, and more.
Feel free to reach out to me with comments, questions, and feedback. My Zsh configuration can be found on GitHub.