Skip to content

Instantly share code, notes, and snippets.

@omarowns
Forked from agnoster/README.md
Last active February 11, 2019 16:53
Show Gist options
  • Save omarowns/2d169c9ea561aed9c8b564d899132ca0 to your computer and use it in GitHub Desktop.
Save omarowns/2d169c9ea561aed9c8b564d899132ca0 to your computer and use it in GitHub Desktop.
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.

if `hg st | grep -q "^\?"`; then
prompt_segment red black
st='±'
elif `hg st | grep -q "^[MA]"`; then
prompt_segment yellow black
st='±'
else
prompt_segment green $CURRENT_FG
fi
echo -n "☿ $rev@$branch" $st
fi
fi
}
# Dir: current working directory
prompt_dir() {
prompt_segment blue $CURRENT_FG "$(get_pwd)"
}
get_pwd(){
git_root=$PWD
while [[ $git_root != / && ! -e $git_root/.git ]]; do
git_root=$git_root:h
done
if [[ $git_root = / ]]; then
unset git_root
prompt_short_dir=%~
else
parent=${git_root%\/*}
prompt_short_dir=${PWD#$parent/}
fi
echo $prompt_short_dir
}
# Virtualenv: current working virtualenv
prompt_virtualenv() {
local virtualenv_path="$VIRTUAL_ENV"
if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
prompt_segment blue black "(`basename $virtualenv_path`)"
fi
}
# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
local -a 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_virtualenv
prompt_context
prompt_dir
prompt_git
prompt_bzr
prompt_hg
prompt_end
}
PROMPT='%{%f%b%k%}$(build_prompt) '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment