public
Last active

My ZSH Theme

  • Download Gist
README.md
Markdown

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 "⮀ ± ⭠ ➦ ✔ ✘ ⚡". 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.

agnoster.zsh-theme
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
# 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'
SEGMENT_SEPARATOR='⮀'
 
# 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
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
}
 
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%k%}"
fi
echo -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_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m"
fi
}
 
# Git: branch/detached head, dirty status
prompt_git() {
local ref dirty
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
ZSH_THEME_GIT_PROMPT_DIRTY='±'
dirty=$(parse_git_dirty)
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
if [[ -n $dirty ]]; then
prompt_segment yellow black
else
prompt_segment green black
fi
echo -n "${ref/refs\/heads\//⭠ }$dirty"
fi
}
 
# Dir: current working directory
prompt_dir() {
prompt_segment blue black '%~'
}
 
# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
local symbols
symbols=()
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
 
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
}
 
## Main prompt
build_prompt() {
RETVAL=$?
prompt_status
prompt_context
prompt_dir
prompt_git
prompt_end
}
 
PROMPT='%{%f%b%k%}$(build_prompt) '

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. :)

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.

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

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

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

Same issue here. OSX, ZSH and Menlo font.

Maybe this character can be made to work?

Yep, seems broken :(

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

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

Same as @npostulart

@agnoster Could you share your iTerm2 profile?

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

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

You need a Powerline patched font.

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

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

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

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.

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.

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

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

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

@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 ;-)

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

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

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

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?

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

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? =)

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

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

@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 ;-)

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

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

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…

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

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

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

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.

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

PS. I use iTerm2 with the latest Solarized.

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

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

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

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

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.

can I have the hex value of the background thanks

Also can I have the item 2 profile

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 ?

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

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

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

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.

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.

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.

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.

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?

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?

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.

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

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)

Can you add support for remote branch status? Function added in pull request https://github.com/robbyrussell/oh-my-zsh/pull/253

Gets really bad with tmux or gnu screen

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

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

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

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

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

@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

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.

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

I'm using Monaco, and the newer patched font available at https://github.com/Lokaltog/powerline-fonts/pull/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?

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

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

@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"

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

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

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.

Thanks, @blackrobot
But

export $DEFAULT_USER="my_username"

might be

export DEFAULT_USER="my_username"

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

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

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.

@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 :)

No 256-color under Cygwin.

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.

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!

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 :

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

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

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.

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

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?

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

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 " ± ➦ ✔ ✘ ⚡" works correctly, OS Kubuntu 13.10.

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.

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

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

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!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.