Skip to content

Instantly share code, notes, and snippets.

Last active July 13, 2024 19:26
Show Gist options
  • Save agnoster/3712874 to your computer and use it in GitHub Desktop.
Save agnoster/3712874 to your computer and use it in GitHub Desktop.
My ZSH Theme


A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

For Mac users, I highly recommend iTerm 2 + Solarized Dark


NOTE: In all likelihood, you will need to install a Powerline-patched font for this theme to render correctly.

To test if your terminal and font support it, check that all the necessary characters are supported by copying the following command to your terminal: echo "\ue0b0 \u00b1 \ue0a0 \u27a6 \u2718 \u26a1 \u2699". The result should look like this:

Character Example

What does it show?

  • If the previous command failed (✘)
  • User @ Hostname (if user is not DEFAULT_USER, which can then be set in your profile)
  • Git status
    • Branch () or detached head (➦)
    • Current branch / SHA1 in detached head state
    • Dirty working directory (±, color change)
  • Working directory
  • Elevated (root) privileges (⚡)


Future Work

I don't want to clutter it up too much, but I am toying with the idea of adding RVM (ruby version) and n (node.js version) display.

It's currently hideously slow, especially inside a git repo. I guess it's not overly so for comparable themes, but it bugs me, and I'd love to hear ideas about how to improve the performance.

Would be nice for the code to be a bit more sane and re-usable. Something to easily append a section with a given FG/BG, and add the correct opening and closing.

Also the dependency on a powerline-patched font is regrettable, but there's really no way to get that effect without it. Ideally there would be a way to check for compatibility, or maybe even fall back to one of the similar unicode glyphs.

# vim:ft=zsh ts=2 sw=2 sts=2
# agnoster's Theme -
# A Powerline-inspired theme for ZSH
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](
# In addition, I recommend the
# [Solarized theme]( and, if you're
# using it on Mac OS X, [iTerm 2]( over -
# it has significantly better color fidelity.
# # Goals
# The aim of this theme is to only show you *relevant* information. Like most
# prompts, it will only show git information when in a git working directory.
# However, it goes a step further: everything from the current user and
# hostname to whether the last call exited with an error to whether background
# jobs are running in this shell will all be displayed automatically when
# appropriate.
### Segment drawing
# A few utility functions to make it easy and re-usable to draw segmented prompts
# Characters
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
print -n "%{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%}"
print -n "%{$bg%}%{$fg%}"
[[ -n $3 ]] && print -n $3
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
print -n "%{%k%}"
print -n "%{%f%}"
### Prompt components
# Each component will draw itself, and hide itself if no information needs to be shown
# Context: user@hostname (who am I and where am I)
prompt_context() {
local user=`whoami`
if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CONNECTION" ]]; then
prompt_segment $PRIMARY_FG default " %(!.%{%F{yellow}%}.)$user@%m "
# Git: branch/detached head, dirty status
prompt_git() {
local color ref
is_dirty() {
test -n "$(git status --porcelain --ignore-submodules)"
if [[ -n "$ref" ]]; then
if is_dirty; then
ref="${ref} $PLUSMINUS"
ref="${ref} "
if [[ "${ref/.../}" == "$ref" ]]; then
ref="$BRANCH $ref"
ref="$DETACHED ${ref/.../}"
prompt_segment $color $PRIMARY_FG
print -Pn " $ref"
# Dir: current working directory
prompt_dir() {
prompt_segment blue $PRIMARY_FG ' %~ '
# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
local symbols
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}$CROSS"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}$LIGHTNING"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}$GEAR"
[[ -n "$symbols" ]] && prompt_segment $PRIMARY_FG default " $symbols "
## Main prompt
prompt_agnoster_main() {
prompt_agnoster_precmd() {
PROMPT='%{%f%b%k%}$(prompt_agnoster_main) '
prompt_agnoster_setup() {
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
prompt_opts=(cr subst percent)
add-zsh-hook precmd prompt_agnoster_precmd
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' check-for-changes false
zstyle ':vcs_info:git*' formats '%b'
zstyle ':vcs_info:git*' actionformats '%b (%a)'
prompt_agnoster_setup "$@"
Copy link

I have a segment issue of the theme.
If I enter a git directory, the segment colour becomes white.

I use iTerm2 v3.0.2 + Solarized Dark
Any suggestion?

Copy link

hugohil commented Jul 21, 2016

The thing that worked for me was to disable the "Use different font for non-ASCII text" option in iTerm settings.
Hope this helps ( @petertom51 maybe ?)


Copy link

@petertom51 Maybe you need to change the contrast.

Copy link

+1 for contrast 👍

Copy link

nbraud commented Aug 9, 2016

@agnoster I think this is missing a setopt PROMPT_SUBST

Copy link

Hi agnoster ..the theme is awesome ......I am trying to add remote url of the repo.Is there a space for contribution

Copy link

my ansi colors look different, am i doing something wrong?

schermafbeelding 2016-09-04 om 18 12 57

Copy link

Hello! I don't see the custom root, when used "sudo -s". How to resolve this? Its Arch, gnome-terminal.

Copy link

allansun commented Oct 6, 2016

@petertom51 you should tick this box


Copy link

tkizm1 commented Oct 8, 2016

virtualenv promot needed

Copy link

bbuivn commented Oct 13, 2016

Hi there, still looking for the ability to show the time into the left prompt :)

Copy link

azat-io commented Jan 19, 2017

@quoniammm How did you solve your problem?

I've the same
screenshot from 2017-01-19 20-23-24

Copy link

When I try to update my agnoster theme to show only the current directory: prompt_segment blue black '%d' doesn't work... it shows again the full path. Any ideas?

Copy link

To show only the current folder this worked for me:

prompt_dir() {
  prompt_segment blue black '%c'

Copy link

You should change print -Pn to print -n on line 100 ( to avoid getting pwned by

Copy link

xu3352 commented Mar 20, 2017

after change iTerm2->Profiles->Text:Font and Non-ASCII Font, it's work for me

Copy link

any link how to use agnoster.zsh-theme. i am newbie

Copy link

I'm a almost new with agnoster, I would like to know if I can add a symbol to show if there are stashed items to the prompt, just to know it without the need to run git stash list.
If no, can you help me to customize it by myself?

Copy link

Opening the terminal I see a red cross, how to remove it?
2017-09-29 18 59 19

Copy link

cschell commented Nov 17, 2017

Just dropping the link to the GitHub Repository of this theme, since all the development and discussions seem to take place there:

Copy link

himanshuxd commented Nov 26, 2017

@gHashTag Commet out the line in /home/username/.bash/themes/agnoster-bash/agnoster.bash that has $RETVAL

prompt_status() {
    local symbols
    #[[ $RETVAL -ne 0 ]] && symbols+="$(ansi_single $(fg_color red))✘"
    [[ $UID -eq 0 ]] && symbols+="$(ansi_single $(fg_color yellow))⚡"
    [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="$(ansi_single $(fg_color cyan))⚙"

    [[ -n "$symbols" ]] && prompt_segment black default "$symbols"

See the bold line it is commented to prevent that cross.

Copy link

Hi guys, i just got my new macbook its on Sierra and after installing theme the terminal didnt changed color and when i go to profiles i dont see anything added there... Any help?

Copy link

@alexandar87 are u using iTerm 2 and Zsh? It should be works with additional font installed

Copy link

It's unfortunate that gist's don't have issue reporting features. Anyhow I wanted to make note of something I discovered and subsequently fixed after the agnoster theme was initially borked for me. When you are using a distro that does not name its ifconfig interfaces according to the standard naming convention (I'm looking at you, Ubuntu >-<), it causes an error to appear below every carriage return you feed into the terminal.

To fix this, I recommend introducing a loop that checks for connected and configured interfaces by calling ifconfig -a and doing some parsing to pull a list of the configured interfaces. Here is how I did it using standard bash commands:

ifconfig -a | grep -i ': ' | cut -d ':' -f1


You can further narrow it down by pulling the ethernet interface which, even though it's not convention, universally starts with 'e' in the interface name, and the same is true for 'w' on wireless interfaces. If you introduce a new function in your agnoster theme that checks for this, it can save a lot of people some headache and confusion when first running the script. 👍

Copy link

there is a very short current dir in the theme of robbyrussel, just show the current folder's name. How is it work in the theme of agnoster??? agnoster theme(PS: I have not done the power-line problem)
1841526714375_ pic
2. in robbyrussel theme. I want just display "HB说明" folder's name in the agnoster. Help!!!
1851526714555_ pic

Copy link

ghost commented Jul 7, 2018

Hey guys.
I'm using fish with agnoster theme.

I saw this:
in: and

as @tonilaukka mentioned;

in your screenshot you ssh milly. Do you have your remote server set up with zsh/oh-my-zsh/agnoster-theme or how do you get a prompt like that?

Now I'm wondering how can I bring that ssh: tag (in picture) to my agnoster theme? Is that possible?


Copy link

For anyone trying to install this theme with ZPlugin. This is what I added in my .zshrc.

### Agnoster Theme
zplugin snippet OMZ::lib/git.zsh
zplugin light agnoster/agnoster-zsh-theme
setopt promptsubst 

Copy link

Uploading Screenshot 2019-10-26 at 8.25.24 PM.png…
Still, I am facing the icon issue

Copy link

hypefi commented Jan 5, 2021

quick fix that worked for me :
cd ~/.oh-my-zsh/themes
vi agnoster.zsh-theme
replace (\ue0b0) with ▓ (\u2593) and  (\ue0a0) with ⎇ (\u2387)

Copy link

davidhcefx commented Feb 27, 2022

@agnoster I like your theme. But I noticed that in line 118, you wrote:

[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}$GEAR"

I would however suggest changing it to %1(j.%{%F{cyan}%}$GEAR.) for better performance.


$ GEAR="\u2699"
$ f1() { local s; [[ $(jobs -l | wc -l) -gt 0 ]] && s+="%{%F{cyan}%}$GEAR"; print -n "$s" }
$ f2() { local s; s+="%1(j.%{%F{cyan}%}$GEAR.)"; print -n "$s" }
$ timer() { date +%S.%N >> /tmp/timer.log }
$ timer_newline() { echo "" >> /tmp/timer.log }
$ precmd_functions=(timer)

# test original version (w/ and w/o background jobs)
$ PROMPT='$(f1) > '
$ <long press Enter>
$ timer_newline; cat &
$ <long press Enter>
$ timer_newline; kill %%

# test modified version (w/ and w/o background jobs)
$ PROMPT='$(f2) > '
$ <long press Enter>
$ timer_newline; cat &
$ <long press Enter>
$ timer_newline; kill %%

After some processing we got:

for test in open('/tmp/timer.log').read().strip().split('\n\n'):
    lines = test.split('\n')
    assert len(lines) >= 10, "Must have at least 10 logs. Try again and press Enter longer."
    lines = list(map(float, lines[-10:]))
    print(sum(lines[i + 1] - lines[i] for i in range(9)) / 10)


Therefore it's an increase in performance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment