Create a gist now

Instantly share code, notes, and snippets.

My ZSH Theme

agnoster.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

Compatibility

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 (⚡)

Screenshot

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 - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://gist.github.com/1595572).
#
# In addition, I recommend the
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app -
# 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
CURRENT_BG='NONE'
PRIMARY_FG=black
# Characters
SEGMENT_SEPARATOR="\ue0b0"
PLUSMINUS="\u00b1"
BRANCH="\ue0a0"
DETACHED="\u27a6"
CROSS="\u2718"
LIGHTNING="\u26a1"
GEAR="\u2699"
# 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%}"
else
print -n "%{$bg%}%{$fg%}"
fi
CURRENT_BG=$1
[[ -n $3 ]] && print -n $3
}
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
print -n "%{%k%}"
fi
print -n "%{%f%}"
CURRENT_BG=''
}
### 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 "
fi
}
# Git: branch/detached head, dirty status
prompt_git() {
local color ref
is_dirty() {
test -n "$(git status --porcelain --ignore-submodules)"
}
ref="$vcs_info_msg_0_"
if [[ -n "$ref" ]]; then
if is_dirty; then
color=yellow
ref="${ref} $PLUSMINUS"
else
color=green
ref="${ref} "
fi
if [[ "${ref/.../}" == "$ref" ]]; then
ref="$BRANCH $ref"
else
ref="$DETACHED ${ref/.../}"
fi
prompt_segment $color $PRIMARY_FG
print -Pn " $ref"
fi
}
# 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
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() {
RETVAL=$?
CURRENT_BG='NONE'
prompt_status
prompt_context
prompt_dir
prompt_git
prompt_end
}
prompt_agnoster_precmd() {
vcs_info
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 "$@"
@digitalformula

This looks awesome - great job. I'd love to use it but I'm not using OMZ anymore (using Prezto now). Might have to look into retro-fitting your theme. :)

@tjdett
tjdett commented Sep 19, 2012

The first and third glyphs don't appear to be standard unicode, and aren't present in either Bitstream Vera or Deja Vu. Looks like this is set to be an Mac-only theme.

Screenshots look great though.

@npostulart

Love this theme.
I already use Menlo as my iTerm2 Font but the first an third character doesn't seem to work.
Any solutions?

@jtheoof
jtheoof commented Sep 19, 2012

Same as tjdett and npostular.
I'm using Ubuntu Monospace and the > don't show up properly.
Any thing you could do ?

@bendavies

Same here.

@Linuus
Linuus commented Sep 19, 2012

Using ZSH and Menlo on OSX. The same problem with the 1st and 3rd glyphs. Too bad, it looked like a sweet theme :(

@Linuus
Linuus commented Sep 19, 2012

Same issue here. OSX, ZSH and Menlo font.

@Linuus
Linuus commented Sep 19, 2012

Maybe this character can be made to work?

@Linuus
Linuus commented Sep 19, 2012

Yep, seems broken :(

(My comments doesn't show up! ARGH!)

@Linuus
Linuus commented Sep 19, 2012

To make special characters work you need a Powerline patched font:
https://github.com/Lokaltog/vim-powerline/wiki/Patched-fonts

@FiloSottile

@agnoster Could you share your iTerm2 profile?

@Linuus
Linuus commented Sep 19, 2012

You need a Powerline patched font to make the glyphs work:
https://github.com/Lokaltog/vim-powerline/wiki/Patched-fonts

@linuxonrails

+1 I'm using Ubuntu Monospace and the > don't show up properly.

@Linuus
Linuus commented Sep 19, 2012

You need a Powerline patched font.

@brkattk
brkattk commented Sep 19, 2012

Please share your profile. Wondering how you got these special characters to show up properly

@negnetsolutions

It's a the patched Menlo Powerline font. https://gist.github.com/1595572

@FiloSottile

Thanks! Awesome.
I was interested in your profile also for the color palette...

@FiloSottile

Oh! My fault :)
I guess that I have to thank you also for making me discover Solarized, now!

@agnoster
Owner

Oh my. I guess I need to update this with the proper prerequisites... hehe. Didn't get any notifications about all the comments!

Will update with the latest version and better details about what you need to use it.

@agnoster
Owner

It looks like the main issue people were having was with the Powerline-specific glyphs - I had installed these earlier and forgotten that there was that prereq. I've now put a clear link in the README and in a comment on the theme itself, hopefully that should remove the biggest stumbling block.

@Linuus
Linuus commented Sep 26, 2012

Anyone else has issues with the color of the glyphs? Some of them are not rendering in the same color for me.

Image:
http://cl.ly/image/1Z1V3r3k1g2r

@Linuus
Linuus commented Sep 26, 2012

Anyone else has issues with the color of the glyphs? Some of them are not rendering in the same color for me.

Image:
http://cl.ly/image/1Z1V3r3k1g2r

@To1ne
To1ne commented Sep 28, 2012

Why do I get an empty line between each prompt?
empty line between prompts

@To1ne
To1ne commented Sep 28, 2012

For some reason github made the link invalid: http://s9.postimage.org/e6s23lbdp/agnoster_newlines.png

@agnoster
Owner

@To1ne Looks like you have an older version of the theme, which put lines between each entry because... well, I thought it looked better. I've since changed my opinion ;-)

@agnoster
Owner

@jeremyFreeAgent Indeed! I like the look of your theme, too - a bit fancier with the right prompt for date/time, might have to borrow that for mine. Though I do like keeping it minimal...

@adben
adben commented Oct 1, 2012

What is the plugin that you use for the colorized unix-command highlight?

@azmodude
azmodude commented Oct 2, 2012

Very stylish and informative theme - thanks a lot for it!

@jeroenh
jeroenh commented Oct 2, 2012

I'm getting errors in the git part of the prompt:
prompt_git:4: command not found: parse_git_dirty

Is there something missing there?

@Linuus
Linuus commented Oct 2, 2012

@adben It's called "zsh-syntax-highlighting" I believe.
Link: https://github.com/zsh-users/zsh-syntax-highlighting

Anyone know why I get the color mismatch I wrote about above?
http://cl.ly/image/1Z1V3r3k1g2r

(Sorry that so many comments was added by me. Apparently github flagged me as spam by mistake which prevented my comments to show up at first)

@zoomix
zoomix commented Oct 3, 2012

Loved the theme. Although I use the solarized light color scheme. I fiddled with it a bit and came up with this https://gist.github.com/3827269 . You wanna 'support' it? =)

@jeromegn
jeromegn commented Oct 7, 2012

Is there a way to remove the duplicate git information on the far right? Is that a plugin I'm using or something? I looked at my config, can't find how to disable it.

http://cl.ly/image/3m0m0x0Z1q1u

@jeromegn
jeromegn commented Oct 7, 2012

Nevermind, seems like it was a quirk from zsh, from my old theme.

@agnoster
Owner
agnoster commented Oct 8, 2012

@jeromegn Yeah, it doesn't explicitly set an RPROMPT, meaning if you had one from a previous theme it'll linger. The advantage is you can put whatever you want in there without messing with the theme ;-)

@agnoster
Owner
agnoster commented Oct 8, 2012

@jeroenh parse_git_dirty is included in oh_my_zsh - this version of the prompt depends upon it. I also have a prezto-based version that doesn't rely on any special stuff, but haven't had a chance to publish yet. Short version is, the prompt in its current form probably works best if you have OMZ installed.

@justinclayton

@Linuus I am also getting the color mismatch when using Terminal.app, but not using iTerm2. Hope that helps...

@rue
rue commented Oct 16, 2012

Similar problem to that of @Linuus, except the special chars are white; the segment arrows, the x for nonzero exit etc. I’ll have to grab a shot of it tomorrow. Ideas, @agnoster? Might be some weirdness with iterm2/solarized, but both should be newest versions…

@rue
rue commented Oct 17, 2012

And here, different scheme showing that the colors work somewhat: https://dl.dropbox.com/u/4761700/omz-agnoster-color-bug-2.png

@rue
rue commented Oct 17, 2012

…And solved, it was the contrast setting. Have to have it set to minimum contrast in iterm2.

@rdrey
rdrey commented Oct 21, 2012

@rue Thanks, I must have also messed with the contrast setting. Now it's pretty! :D

@lmorency
lmorency commented Nov 1, 2012

Same problem here in iTerm2 under OS X 10.8 with Menlo font, ZSH and OH My ZSH ! The 1st and 3rd glyphs are not showing.

@achikin
achikin commented Nov 17, 2012

Hi! Commands like sudo, kill and others are not shown in green for me. Please have a look what I mean http://d.pr/i/7N0u

@achikin
achikin commented Nov 17, 2012

PS. I use iTerm2 with the latest Solarized.

@ershovandrey

I know how to fix 1st and 3rd glyphs issue: iTerm2 - Preferences - Profiles - YOUR_PROFILE - Colors - Minimum Contrast - set to Low.

@lenpr
lenpr commented Nov 26, 2012

the last update messed up the theme and replaced the local settings with one of the developers… I am talking to you ~/carlos user ;p

@boxofrox
boxofrox commented Dec 2, 2012

Anyone find a way to get Powerline to work on xTerm/uxTerm under Linux?

@boxofrox
boxofrox commented Dec 2, 2012

Meh, forgot to mention. I installed "Menlo for Powerline" font in my ~/.fonts. The segment arrow appears in GVIM, but not in uxTerm :/

@kalkin
kalkin commented Dec 2, 2012

First of all i have to thank you. After seeing your prompt i finally started to write my own.

If you want to improove the performance, do it the right way ;). Use vcs_info and conditions in the prompt. I have no performance problems and i have a big config. See also https://github.com/kalkin/zsh/blob/master/kalkinprompt.zsh for the prompt.

@dorafmon
dorafmon commented Dec 6, 2012

can I have the hex value of the background thanks

@dorafmon
dorafmon commented Dec 6, 2012

Also can I have the item 2 profile

@nathan-appere

Question: how do you get the binary to color in green ? Is it in the theme (if so I do not understand where) or is it an extra plugin ?

@cunningham

I can't get the ✘ to show up when an command fails. It just prints 127 in red. Thoughts?

@shellbj
shellbj commented Dec 21, 2012

@cunningham: If you are using the stock OMZ theme of the same name it is different from the gist version. The ✘ was removed in favor of the error codes you are now seeing. You can create a custom theme to add it back.

@marr
marr commented Jan 13, 2013

When in low contrast mode using solarized, all the comments disappear in vim. Im using Menlo for Powerline for my iTerm2 fonts. Also in your twitter screenshot you have white inside the blue path area, mine is more like the screenshots above but i'd like to use white there. https://twitter.com/agnoster/status/246324692590415874

@marr
marr commented Jan 13, 2013

With contrast turned up a little so I can see comments: http://cl.ly/image/0X2P0z0b432e
And the comment problem with the contrast all the way down: http://cl.ly/image/350q2y2k460n

The comments are the same color as the background in solarized vim, I have no clue how to fix this.

@monkey-za

FYI
Don't know if anyone else have this problem, but when I try to use auto complete my cursor jumps around. I have created a fork where I fixed this.

@sent-hil

I added a simple function to show code to spec ratio. I'm very new of zsh, so tips are greatly appreciated.

prompt_rspec_stats() {
  if [[ (-a config/application.rb) ]]; then
    local app=`wc -l app/**/*.rb | grep -oE "[0-9]+" | tail -n 1`
    local spec=`wc -l spec/**/*.rb | grep -oE "[0-9]+" | tail -n 1`

    prompt_segment cyan black "$app:$spec"
  fi
}

I tried showing the actual ratio, but I wasn't able to figure out how to round the float.

One great condition for git is if told how long since last commit. I remember using a diff. theme that offered that functionality, especially useful when it changed colors from green to yellow to red as the time since last commit increased.

@sent-hil

Updated it to look for app/spec folders and vary background colors based on ratio.

prompt_rspec_stats() {
  if [[ (-d app && -d spec) ]]; then
    local app=`wc -l app/**/*.rb | grep -oE "[0-9]+" | tail -n 1`
    local spec=$((`wc -l spec/**/*.rb | grep -oE "[0-9]+" | tail -n 1`))+0.01
    local ratio=`printf "%.2f\n" $((spec/app))`

    [[ ratio -ge 0.75 ]] && prompt_segment cyan black "$ratio"
    [[ ratio -ge 0.5 && ratio -lt 0.75 ]] && prompt_segment yellow black "$ratio"
    [[ ratio -lt 0.5 ]] && prompt_segment red black "$ratio"
  fi
}

Ping @agnoster.

@Anrock
Anrock commented Feb 20, 2013

Can't make it work with urxvt - it shows boxes instead of 2b80(first) and 2b60(third) symbols. Works fine with gnome-terminal, though. I suppose it's the urxvt-specific problem. Did someone make it work as it should be?

@deiga
deiga commented Mar 8, 2013

I don't quite understand the reasoning behind this theme. Couldn't one just use powerline? Or are there some serious pros to using this? What would the cons be?

@eailfly
eailfly commented Mar 20, 2013

Hi,guys.I think I found a way to show 2b80(first) and 2b60(third) in xterm, just use "xterm -cjk_width".For other term,see if your term support CJK characters.

@dpsk
dpsk commented Apr 4, 2013

Can't make it work on os x with the patched fonts, 1st and 3rd symbols are looking messy :( Any hints?

@flying-sheep

it doesn’t work anymore with the newest version of powerline. also, one should rather use fontconfig instead of patching fonts: that’s both easier and more future-proof (if e.g. a new source code pro version is realeased, you don’t have to update your patched version manually)

@ploddi
ploddi commented May 20, 2013

Can you add support for remote branch status? Function added in pull request robbyrussell/oh-my-zsh#253

@jaseemabid

Gets really bad with tmux or gnu screen

@DaveC0DE

I noticed commenters on bad glyphs. I'm on Linux/urxvt with that issue. Powerline changed code points - see the red warning box at
https://powerline.readthedocs.org/en/latest/fontpatching.html

So any powerline font patches using code points lower than U+E0A0 is now stale. E.g. the article and git sources from
http://www.paradox.gd/posts/9-my-new-zsh-prompt
...has glyphs messed up this way, with the same (wrong) code points as here, U+2B80 and U+2B60 I think.

If some people with offerings on github still use older patched fonts (i.e. wrong code points), then it would explain a lot. The test from flying-sheep just above is correct.

I wonder also on Macintosh/Linux mismatch. Much powerline stuff comes from Mac people. I'm unclear what encodings they post on github. Sometimes I see 7-bit, sometimes UTF-8, etc. A linguist wrote helpful tools for inspecting encodings in detail (straight C with no outside dependencies),
http://billposer.org/Software/unidesc.html

@atuttle
atuttle commented Jul 5, 2013

Latest iTerm update seems to have broken the glyphs. Was fine until the update. OSX 10.7.5. Any thoughts?

@xbot
xbot commented Jul 6, 2013

Arrow symbols are displayed as boxes in rxvt-unicode, gnome-terminal works fine, but I only love rxvt-unicode, I am very very sad.

@NicosKaralis

@atuttle same problem here. did you manage to fix it?

@bbshih
bbshih commented Jul 7, 2013

@atuttle @NicosKaralis I deleted and reinstalled the powerline fonts https://github.com/Lokaltog/powerline-fonts and then selected the powerline font as the Regular and Non-ASCII font. It works now. It seems to have separated it out the powerline sybmols into the Non-ASCII font setting.

@NicosKaralis

@atuttle and @bbshih i just updated my file agnoster.zsh-theme the file i had on my computer had 172 lines, the latest version has only 115

this fixed my problem

@ce6n
ce6n commented Jul 8, 2013

For me it was the change of codepoints, as @DaveC0DE mentioned.
I had to change line 29 and 82 in the agnoster.zsh-theme file.

@kzahel
kzahel commented Jul 10, 2013

@NicosKaralis Also seeing the broken glyphs. I'm seeing agnoster.zsh-theme still has 172 SLOC. My remote origin is github robbyrussel/oh-my-zsh.git, where is the updated oh-my-zsh? I tried updating some powerline fonts but that didn't do the trick.

@gabetax
gabetax commented Jul 12, 2013

I'm using Monaco, and the newer patched font available at powerline/fonts#16 works for me with the changes to powerline and the corresponding changes in this theme.

However, I was using RPROMPT='%*' (timestamp), and the last two characters of the RPROMPT are wrapping onto the second line when I'm in a git repo. I'm suspecting that by moving the locations of these glyphs, something is no longer counting them as characters when determining where to place the RPROMPT. Any ideas?

@atuttle
atuttle commented Jul 18, 2013

Updating my agnoster.zsh-theme fixed it for me, no need to muck with fonts.

@mgbellaire

my $USER@$HOSTHAME is still showing up. everything else is working fine! any ideas on how to fix this?

@blackrobot

@notbieber If you set this in your ~/.zshrc file, it will remove the user@host prefix:

export $DEFAULT_USER="my_username"

If you want the theme to show the prefix only when on a remote server, add a line using this conditional instead:

[[ -n "$SSH_CLIENT" ]] || export DEFAULT_USER="my_username"
@peterpeerdeman

Thanks @bbshih, setting the non-ascii font to the same as the regular font fixed my glyph encoding issue

@davertron

On Mountain Lion, updating to latest agnoster theme (115 LOC version) fixed the glyph issues for me.

@njuaplusplus

Hi @davertron. I aslo use the Mountain Lion 10.8.4 with the 172 LOC version and it works. But the 115 LOC version seems out of work. Like the 1st and 3rd glyph issues. But echo -e "\ue0a0\ue0a1\ue0a2\ue0b0\ue0b1\ue0b2" works out.

@njuaplusplus

Thanks, @blackrobot
But

export $DEFAULT_USER="my_username"

might be

export DEFAULT_USER="my_username"
@lichtamberg

Changed the line 29 (verison 172 lines) to SEGMENT_SEPARATOR='⮀' (see source code at page begin) worked for me, a box was displayed instead of the arrow...

@juanfe
juanfe commented Sep 22, 2013

For Debian, I use Oh-my-zsh [0], I install fontconfig package, and follow the instrucction on [1], downloading 10-powerline-symbols.conf from the repo [2], and after that I change the line 66 where say black, y change by yellow, and is awesome! If I change something else, may be I will make a new branch!

[0] https://github.com/robbyrussell/oh-my-zsh
[1] https://powerline.readthedocs.org/en/latest/installation/linux.html#font-installation
[2] https://github.com/PiPeep/dotfiles

@joshleaves

If you still want to add RVM to this prompt, I wrote this some days ago to know instantly if I was using my default ruby or one set up by RVM:

prompt_rubyver() {
  if [[ -n "$RUBY_VERSION" ]]; then
    RUBY_VER=`echo $RUBY_VERSION | cut -d'-' -f2`
    prompt_segment red black "v"$RUBY_VER
  fi
}
# Call it from build_prompt in your preferred order.

Result when going to a folder with a .rvmrc file
http://i.imgur.com/oaPtSBg.png

Notes:

  • I use RUBY_VERSION because it's set by the .rvmrc when cd-ing and applies to subfolders too. Looking up recursively in parents folder for a .rvmrc was just too much.
  • If you have a RUBY_VERSION in you classic env, the ruby version will be displayed all the time.
  • I only got one folder using a custom ruby, so I'd like for people who use dozens of ruby at the same time to correct anything that's wrong with this approach.
@andion
andion commented Nov 4, 2013

@joshleaves you can also use rvm-prompt

"$(~/.rvm/bin/rvm-prompt i v p g s)"
  • If you use the s option it will return 'system' if you are using your system ruby.
  • It also returns a unique one-unicode-char representation of the ruby you are using with the u option (Useful to make a compact prompt if you have a long list of installed rubies :)
@bcbcarl
bcbcarl commented Nov 5, 2013

No 256-color under Cygwin.

@JonDum
JonDum commented Nov 10, 2013

Is there anyway to basename the working directory prompt? I have very nested structures and the prompt takes 80% of my window.

I see how it's making it in the prompt_dir() function, but I don't know how the ~ is expanding into the pwd, nor do I understand how I would encapsulate the basename

Edit: nevermind figured it out. I changed '%~' to '%2d' to show only 2 directories worth of context.

@oli
oli commented Nov 19, 2013

re: the changes after updating to the latest version of this theme, for me L29 → SEGMENT_SEPARATOR='\ue0b0' and L82 → echo -n "${ref/refs\/heads\//\ue0a0 }$dirty" did the trick.

I customized the final prompt to add a newline:

PROMPT='%{%f%b%k%}$(build_prompt)
%% '

However, a deeply nested folder’s path will cause the first line of the prompt to wrap, and the rest of this line to inherit the prompt’s background color (blue, or the repo status color). I tried adding %{$reset_color%} in various places but had no luck. If any zsh pros can give me some advice:

  • How can I reset the background color for a multiline prompt?
  • How would I trim the path in the center to prevent it being longer than the window width? For example, ~/Sites/…/parent-directory/present-working-directory, where replaces one or more sections of the path to keep the prompt from wrapping?

Thx!

@wenLiangcan

I use Terminator on Arch Linux and already installed a Powerline patched font, but the arrow symbols are still displayed as boxes :

Vim with Powerline color scheme in Terminator :

@lzdhlsc
lzdhlsc commented Dec 9, 2013

@wenLiangcan try "Inconsolata for Powerline" for none ascii.

@bricewge

@wenLigancan I had the same issue on Arch some time ago.
Installingttf-powerline-fonts-gitand using this fork https://gist.github.com/fujin/5169248 worked for me.

@damianesteban

The glyphs / fonts work fine for me on iTerm 2, what doesn't show up for me is parts of the interface, i.e. the "arrowish bars".

Basically the bars are just straight with no arrows. All the glyphs do however print out when I do the test above.

@deKilla
deKilla commented Jan 21, 2014

If you're having Problems with the "⮀" not showing, you might want to edit the ~/.oh-my-zsh/themes/agnoster.zsh-theme.

In line 29 there is the SEGMENT_SEPARATOR ... that showed the same weird symbol that i had in the shell (logically) so by replacing it with the desired arrow, i got it to work. You can use the arrow I pasted - works just fine for me.

Hope this helps anybody :)

EDIT: on second view i saw some other wrong symbols as well, so you might just replace the whole zsh-theme with this: https://gist.github.com/agnoster/3712874/raw/c3107c06c04fb42b0ca27b0a81b15854819969c6/agnoster.zsh-theme

@emmedema

I started using this theme today and I noticed some problems with tab-completion, that seem to be related with the prompt: http://stackoverflow.com/questions/19305291/remnant-characters-when-tab-completing-with-zsh

More specifically, assume I have a variable BLAH="/usr/blah/blah".

When, from my prompt I type

cd $BLAH/[tab]

the line becomes the following:

cd $BLAH//usr/blah/blah

instead of

cd /usr/blah/blah

This was not happening before. Any idea how I can fix this?

@unikitty37

Is it possible to have a symbol that indicates if there are stashed items? I keep forgetting there's something in the stash, meaning having to waste time figuring out if the changes are still needed a few days later...

@spellanser

Thank you very much, this theme is awesome!
But i have some trouble, then my git working directory is clean, it still show ± instead of branch symbol.
The rest works fine.
Can somebody help me with this?

P.S echo "<2b80> ± <2b60> ➦ ✔ ✘ ⚡" works correctly, OS Kubuntu 13.10.

@cdarken
cdarken commented Feb 26, 2014

I have the same problem as sarkisn, I'm on LinuxMint 16. It doesn't work with konsole, terminator. It works on my laptop in Ubuntu 13.04.

@spellanser

Thanks to @NicosKaralis, my problem solved. @cdarken just replace your agnoster.zsh-theme file, with this. https://gist.github.com/agnoster/3712874#file-agnoster-zsh-theme

@tonilaukka

@agnoster, 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?

@elauqsap
elauqsap commented Apr 8, 2014

I cant seem to get the same color scheme in iTerm2, any ideas or could someone link me to the iTerm presets that he is using?

Thanks in advance!

@redsunsoft

Love this theme. Just merged a pull request to add git visualization for merging, rebasing, and bisecting modes.
Here are the new identifiers:

<B> signifies Bisecting Mode
>M< signifies Merging Mode
>R> signifies Rebasing Mode

Pull request: robbyrussell/oh-my-zsh#2633

@bmaingret

In Ubuntu 14.04, using the default terminal, I had to copy paste the first and third special characters in the theme file because they weren't recognized properly (rectangle and chinese character). Hope this help!

@maximhoffman

Guys i use iTerm2 with Solarized color sheme. Bat i have a problems with this theme. I install neccesary fonts and turn it in iTerm profile (mensch-Powerline)
http://cl.ly/image/1x091Q1N0C1L

What did I do wrong?

@nmn
nmn commented May 6, 2014

I have the same problem
http://cl.ly/image/1x091Q1N0C1L

@Dietr1ch
Dietr1ch commented May 8, 2014

I think you can drop the machine name when you are on your machine.

@killerspaz

Regarding fonts, the thing being left out and might be confusing people is that you have to choose the font for your term emulator.

The link that @MarcoSero provided has a great collection of patched/modded fonts.

Just download the main zip file, extract, and copy the fonts to ~/.fonts (make it if necessary).
Then simply run 'fc-cache' and you should have it working just fine.

@ashebanow

I fixed the two glyphs to match the current powerline font encodings (as have several folks above), but here it is as a fork of this gist: https://gist.github.com/ashebanow/9a02751a82058efaf0d8

@lfilho
lfilho commented Jun 3, 2014

@digitalformula it does work on prezto (but you probably wanted to hear that sometime sooner than 2 years after your comment, right? 😄 )

Thanks for this gist, @agnoster. Using it :) But maybe you could think about organizing it a bit more like jeremyFreeAgent's one? His looks reallys extensible and configurable! 😍

@andrewzigerelli

@ifilho This works on prezto? I get an error prompt_git:4: command not found: parse_git_dirty

@igneosaur

I've gone through all the comments from the past 2 years and I still have this problem:

alt text

  • I have downloaded and installed many different powerline fonts from many repositories.
  • I have replaced the agnoster.zsh-theme file with this one and others that have been suggested.
  • I'm using iTerm2 on Mac OSX 10.9.3.
  • Solarized theme installed.

What's going on? Does anyone have an up to date run down of all the different components that work together? I mean, is it a specific combination or something?

@MunchyYDL

@igneosaur: I use the same setup, and it works for me, finally. The gotcha you need to look out for, is to set up iTerm2 to use the Powerline-font as both the Regular Font and Non-ASCII Font.

Hope this helps! :)

@fcamblor

FYI, I created a fork of this theme allowing to display remote tracking branch infos (commits ahead/behind remote tracking branch)

Fork is there

Screenshot : agnoster-fcamblor

@inspectahstack

Hello, I've created a theme based heavily on this one and jeremyFreeAgent's adding the ability to configure all the components via ~/.zshrc flags as well as these additional ones:

  1. rvm-prompt
  2. time
  3. more git info

Demo

Demo2

Check it out here https://github.com/maverick2000/zsh2000

@RenieWell

@igneosaur I have a same problem as you. Have find a way out? The way to use the Powerline-font as both the Regular Font and Non-ASCII Font same like not very helpful.

@agnoster
Owner

I just updated the theme to work with the latest version of the Powerline fonts and pointed to the correct versions. There are a few other minor changes that should make the theme a little faster.

What I'd like to have longer-term is the ability for different plugins to hook in so you can essentially configure your prompt to show a series of independent modules. That might help with all the forks to do one specific thing differently ;-)

@synthecypher

You you also update the theme to work with Mercurial I get a bunch of weird characters instead of the nice powerline ones. :(

@steve-tran

@MunchyYDL: your tip already made my day. Thanks a lot

@raduchiriac

@mgbellaire you can comment the line prompt_context at the very end

@daidais
daidais commented Feb 20, 2015

For Ubuntu users you need to install powerline

sudo apt-get install powerline
@wittyfilter

@MunchyYDL Your comment helps me a lot! Thanks ^_^

@bhilburn

I created another Powerline-based theme, based on agnoster's work with a number of updated features and speed improvements. Check it out, here: https://github.com/bhilburn/powerlevel9k

@VincentDS

I love this theme! Is it possible to only print the current directory name instead of the full path? This becomes a mess with long path names... :)

@vgorloff
vgorloff commented May 8, 2015

Seems ok .) iTerm2 + Menlo for Powerline (from here https://github.com/abertsch/Menlo-for-Powerline) on OS X.

@adriandeveloper

Dammit. Even after looking through this thread, it's still displaying $USER@$HOSTHAME. Anyone get this resolved?

@enthusiasmus

Yeah, for me this line works: [[ -n "$SSH_CLIENT" ]] || export DEFAULT_USER="username"

@scottbaron

First to the author and the supporters, if any, thank you for providing awesome open source software. Your efforts are appreciated. Please anyone correct me if I'm wrong. I may be hallucinating, but I thought that the
'X' that appears when the prompt is first delivered at the time the terminal opens was always apparent. I realize this is counter intuitive, but its been a long year! Any comment would be appreciated. I see the screen shots do not have the "X" following command execution.

@NickHurst

I'm not entirely sure what I'm doing wrong, but I'm not getting the prompt that is show in all the screenshots. I'm running Mac OSX 10.10.4 (14E26a) and that is in iTerm 2. This is what mine looks like:

prompt

@brettrann

Thanks!

If anyone wants chruby ruby version here's an easy way. It'll show if chruby has been used, and hide if it's fallen back to the system ruby.

install the chruby plugin.

zgen oh-my-zsh plugins/chruby

then add this:

prompt_chruby() {
  local ruby=`current_ruby`
  if [[ -n "$ruby" ]] && [[ $ruby != "system" ]] && prompt_segment cyan $PRIMARY_FG " $ruby "
}

and modify the prompt_agnoster_main() from this gist to add it in:

## Main prompt
prompt_agnoster_main() {
  RETVAL=$?
  CURRENT_BG='NONE'
  prompt_status
  prompt_context
  prompt_dir
  prompt_chruby
  prompt_git
  prompt_end
}

chruby prompt

@franklinyu

@adriandeveloper Seems that you missed this:

Optionally set DEFAULT_USER in ~/.zshrc to your regular username to hide the “user@hostname” info when you’re logged in as yourself on your local machine.

@gsscoder

I've installed the fonts but when running the echo test some character is missing:

echo "\ue0b0 \u00b1 \ue0a0 \u27a6 \u2718 \u26a1 \u2699"
 ±  ➦ ✘ ⚡ ⚙

Any idea? Thanks... :)

@alphabraga

I'm facing the same problem here too.

@alphabraga

solved! After instaling Powerline-patched font (as sugested) and change font to "Anonymous Pro for Poweline" in my terminal application fix the problem!

@ccharlton

I fixed my iTerm2 setup. The font needs to be set in the Prefs > Profiles > Text > Non-ASCII Font

iterm2-powerline-font-setting
@alanhogan

I added a new file into my custom directory that said

prompt_dir() {
  prompt_segment blue $PRIMARY_FG ' %2d '
}

But I still get the very long working directory prompt instead of the last 2 directories.

Anyone figure out how to change this without editing the theme itself?

https://gist.github.com/agnoster/3712874#gistcomment-947350

@alanhogan

BTW %2~ is better than %2d if you want to see ~ instead of ahogan (or your username) when you are at ~

@yangyu0116

Loved the theme. very nice

@choushishi

@ccharlton 's solution works for me

@fcpwiz
fcpwiz commented Aug 28, 2015

For some reason, when I'm connected to a server via SSH, no colors or special formatting is used. How do I fix this?

Screenshot

@DoctorJellyface

@agnoster Could you please optimize your theme a bit for solarized light? E.g. setting the font colour in the prompt by the bg would help a lot. If you want, I can make a PR for this.

@phuongtailtranminh

Hi.

I'm using zsh with agnoster theme on my OSX.

On my Windows, i've ssh-ed in to OSX machine i got this error. (I've tried ssh to an Ubuntu server with zsh and agnoster theme also but everything work fine)

Both of oh-my-zsh has been updated to latest version!

Image
Image

@Kuro-Maii

I may have found a bug on line 69 of your theme
the -n "$SSH_CLIENT" part of the if statement ( in the function prompt_context() ) will not be reached as as both root and my own user account $DEFAULT_USER empty
this will cause "$USER" != "$DEFAULT_USER" to always be true

I found this as I was trying to make the prompt different for a SSH login. I am still debating if I should add a character or a different color for the user/machine name.

@Eriner
Eriner commented Sep 30, 2015

small patch to remove the use of backticks. The syntax $(COMMAND) is much preferred.

diff --git a/agnoster.zsh-theme.orig b/agnoster.zsh-theme
index 9304556..e2cc83a 100644
--- a/agnoster.zsh-theme.orig
+++ b/agnoster.zsh-theme
@@ -69,7 +69,7 @@ prompt_end() {

 # Context: user@hostname (who am I and where am I)
 prompt_context() {
-  local user=`whoami`
+  local user=$(whoami)

   if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CONNECTION" ]]; then
     prompt_segment $PRIMARY_FG default " %(!.%{%F{yellow}%}.)$user@%m "
@isae
isae commented Sep 30, 2015

https://github.com/abertsch/Menlo-for-Powerline
This is a proper font, now theme started to work. OSX Yosemite 10.10.5, iTerm 2 + Solarized Dark

@Mediatrucbar

I have some problem when i am connected as root or as ssh : i have a basic prompt without color and effect. Anyone know an issue ?

@viix
viix commented Oct 11, 2015

Great work, any one knows the meaning of the GEAR indicator for git ?
screen shot 2015-10-11 at 11 40 36 am

@alanmaciel

Thats not related to git, the gear means that you are executing some background process, type fg and enter to return the process to the foreground to examine what is that process doing.

@DanielGGordon

So do I need to install powerline AND the powerline fonts?

@hottehead

Really great theme. I just installed "oh my zsh" and then grabbed your theme and the powerline font. Big respect. I like it.

@rjorgenson

I forked this(well, the version shipping with OMZ) and made some modifications adding nvm/rvm/todo.sh support as well as a timestamp in a right prompt. It doesn't seem to cluttered to me, and ZSH handles the RPROMPT pretty well when you need the space back to type. All modules fail gracefully in my testing so far if not present, if you find any issues don't hesitate to let me know =] Here's a screenshot
screenshot
and a link to the fork - https://gist.github.com/rjorgenson/83094662ace4d3b82b95

edit - went ahead and updated my version to be in line with version instead of the one shipping with OMZ

@mdrmike
mdrmike commented Oct 20, 2015

Ubuntu 14.04 with manually installed powerline fonts (e.g., download zip, copy font folder(s) to ~/.local/share/fonts/powerline/) and working off idea similar to @ccharlton

I customized guake & gnome terminal by changing default font to use Ubuntu Mono derivitive Powerline.

screenshot_guakepreferences_096
screenshot_editingprofile default _099

@cah-danmonroe

iTerm2 folks, see comment from @MunchyYDL . You need the Non-ASCII font selected as a Powerline font

@zackn9ne

@ccharlton thank you! Setting ascii font to a different variant fixes symbol font display problem. OS X iTerm2

@junhan-z

I have my Ubuntu installed these fonts too. However, I still got this..

image

Any suggestions?

Here is my locale, does that matter?
image

Lastly, the zsh theme I tried to use is af-magic and I have set the font to be "Hack"

Thanks.


OK, I solved it...

The trick is to enable Unicode under terminal

menu->terminal->set character encoding

@timfeirg

is it OK that I just made a PR by borrowing your code?

https://github.com/caiogondim/bullet-train-oh-my-zsh-theme/pull/101/files

@DONSA
DONSA commented Feb 25, 2016

It's possible to style the numbers on the left?
A different background would be nice.

screen shot 2016-02-25 at 23 49 40
@dzlab
dzlab commented Mar 3, 2016

I'm on osx el capitan, I've the long working directory starting from home, something like ~/dir1/dir2/dir3/currentdir! How I can print just the current directory, tried to modify in prompt_dir to put %d instead of %~ but now I get the whole directory structure!!

@V-Go
V-Go commented Mar 7, 2016

osx el capitan issue that i've had since yosemite . End of line on a windowed zsh iTerm causes the next line to behave strangely.

After that several things happen: next character disappears, backspace causes letter duplicated and aliasing, any resizing of screen which have long prompts cause prompt to sometimes break.

It seems to be an issue with agnoster, zsh behaves fine when theme isnt set.

@masoncodes

spicy bruh

@light2yellow

This doesn't work with grml-zsh-config. I've put prompt off and than inner text of this file in /etc/zsh/zshrc.local. As a result I only get $(prompt_agnoster_main) and nothing else. Could someone help?
screenshot_2016-04-09_19-48-22

Solution

You need to add setopt promptsubst to the end of this file. This would work even without prompt off.

@gartz
gartz commented Apr 13, 2016

Is there a way to not display the full path to working directory and only the name of the current directory?

@light2yellow

There's a small issue with Fira Code. See this one.

@siwka
siwka commented May 17, 2016 edited

When set Powerline for Non-ASCII font my lighting "\u26a1" lost color. Lighting lost light!
If I use other font, e.g. Monaco - lighting is back (but of course other fonts are not recognized :-( ). Any suggestions?

@QuoniamYIF

2016-05-18 11 52 25

There is no the icon of the brach.
How can I deal with this problem?

@hasanein

In had a similar problem on Mac OSX using Iterm2, it has been sorted by changing the terminal font config to use any of the powerline fonts for non-ascii characters.

@petertom51

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

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

@hugohil
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 ?)

preferences_and_1__hugo_hibou____sources_js_soixante_bbscope-front__zsh_
@ruichao-factual

@petertom51 Maybe you need to change the contrast.
image

@xsenechal

+1 for contrast 👍

@nbraud
nbraud commented Aug 9, 2016

@agnoster I think this is missing a setopt PROMPT_SUBST

@VijayKrish93

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

@haitamattar

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

schermafbeelding 2016-09-04 om 18 12 57

@dead-sea256

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

@allansun
allansun commented Oct 6, 2016

@petertom51 you should tick this box

preferences

@tkisme
tkisme commented Oct 8, 2016

virtualenv promot needed

@bbuivn
bbuivn commented Oct 13, 2016

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

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