Garrett Zsh Theme for Prezto
A prompt with the information you need the moment you need it.
NEW: It's been a long time coming but I've added gifs so you can see what the fuss is all about!
I designed my prompt for readability and to present useful information when needed.
The Garrett prompt supports:
- All prompt types (
Autocorrection, and a backup
- Notification of background jobs
- Ruby version
- Non-zero return codes
- Line drawing
- Directory truncation
- Vi-editor info
- Job completion
- Current shell level
- History line number
- The current time
Standard Prompt (PS1)
Many (most?) prompts put the directory information in front of the cursor entry point. Changing directories changes the location of the cursor on the screen. This inconsistent location is undesirable. The Garrett prompt cursor is consistently at the same place on the screen.
By using line drawing and inserting a newline between each command, scrolling back through your history for the output of a previous command becomes drastically easier.
Both Terminal and iTerm2 support line drawing and the prompt will look it's best there.
The Garrett prompt has a fallback if line drawing is unsupported by your terminal emulator.
Right Prompt (RPROMPT)
The right prompt contains useful information but moves out of the way for long commands.
Continuation prompt (PS2)
Selection prompt (PS3)
NOTE: This view contains both the selection and continuation prompts. The selection prompt is shown when entering 1, 2, or 3.
Execution trace prompt (PS4)
Backup root prompt
There is a backup root prompt that will highlight most of the terminal in red if you switch to the sudo user inside another shell which hasn't set this prompt. It's a simple safety measure.
NOTE: This feature is available only when the shell environment is not reset by
switching to the
sudo command. i.e., switch to root using
sudo -s and you
will see the prompt change its primary color to red (as described above); switch
to root with
sudo -i, the environment will be reset and you'll see the base
Zsh prompt instead of my custom one.
This prompt has the following features. These features may be disabled and rearranged as desired by using the corresponding tokens. There are also minor changes that can (easily) be made in terms of formatting the output of the prompt by editing the prompt file itself but that's up to you.
Change host color when on ssh
You can display either the full or truncated hostname on ssh by editing the prompt file. The default is to display the truncated hostname.
NOTE: The primary prompt color changes from gray to orange—color was lost when making the gif (#1).
Change prompt color when UID is root
As a safety feature, the prompt will change color when logged in as the root user. This looks the same as host color change on ssh but with a red color instead of orange.
ls the directory contents on cd
Determine the number of background jobs
Present working directory truncation, if needed
Directory truncation will slim down the
PWD to the first letter of each child
directory; it can be turned off by editing the prompt file.
Report non-zero return codes
Report local time
You can change to time format from within the prompt file. Available options:
- 24 hour time format (default)
- 24 hour time format, second precise
- AM/PM time format
Report the terminal line number
Useful for bang history completion and hipster pride.
Report git status, git remote status, git prompt info and git SHA information
Report Ruby version
If you use the default Prezto, the prompt will also show the system's ruby. If you don't want to see that information, have a look at my fork of Prezto.
If you like, you can add notification of insert mode by editing the prompt.
Notifications for commands taking longer than n seconds
The default time is 2 seconds but is adjustable in the code.
SHLVL sets the shell-level notification value and increments by one each time
a new shell starts. Common reasons the number can increase include:
zshstarts from within another shell, which could be
- A terminal multiplexer like
tmuxis in use
- Have a working installation of Prezto
zstyle ':prezto:module:prompt' theme 'garrett'in
- Optionally, configure pwd trunctation
- Open a new terminal window
If you'd rather not have to do this, please provide your support on Prezto #914.
Here's helpful suggestions and tips for ensuring the prompt works at its best.
- Make sure you're using Prezto with the git module enabled - the prompt won't work without it (see #6, #7)!
- Even better, use my fork of Prezto which includes modifications (mentioned above) for a better experience
- The Garrett prompt has a custom
clear-screenwidget so that
^Lwill properly redraw the prompt (#5). If you use zsh-syntax-highlighting, zsh-history-substring-search, or zsh-autosuggestions, be sure to load those after you load the prompt in your dotfiles.
If you've found this project useful, would you consider sending your support?
The author of this module should be contacted via the issue tracker.