[go: up one dir, main page]

Skip to content

chauncey-garrett/zsh-prompt-garrett

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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:

  • git status information
  • All prompt types (PS1-PS4, Autocorrection, and a backup SUDO_PS1)
  • Notification of background jobs
  • Non-zero return codes
  • Line drawing
  • ssh status
  • Directory truncation
  • Vi-editor info
  • Job completion
  • History line number
  • The current time

Prompt types

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.

The terminal theme shown here is Solarized Dark and the font is Pragmata Pro (affiliate link).

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)

Autocorrection prompt

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.

Features

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. This is configurable via Prezto.

Report non-zero return codes

Support for non-zero return codes must be enabled. See Prezto's prompt documentation.

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

Symbol Meaning
λ:master branch
9769ee9 commit hash
| dirty
ahead
behind
diverged
stashed
added
deleted
modified
renamed
unmerged
untracked

Indicate vi-mode

Normal mode:

Overwrite mode:

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.

Installation

  • Have a working installation of Prezto
  • Copy prompt_garrett_setup to ~/.zprezto/modules/prompt/functions/
  • Set zstyle ':prezto:module:prompt' theme 'garrett' in ~/.zpreztorc
  • 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.

Helpful tips

Here's helpful suggestions and tips for ensuring the prompt works at its best.

Like it?

If you've found this project useful, would you consider sending your support?

Author

The author of this module should be contacted via the issue tracker.

Chauncey Garrett