Skip to content

Instantly share code, notes, and snippets.

@scottgruber
Forked from remy/batcharge.py
Last active May 7, 2021 21:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottgruber/6d922d4ed80e23c35b2cd91135e7c2d3 to your computer and use it in GitHub Desktop.
Save scottgruber/6d922d4ed80e23c35b2cd91135e7c2d3 to your computer and use it in GitHub Desktop.
My zsh set up as of August 9, 2019

Setup zsh

Based on Remy Sharp's most excellent Working the Command Line

brew install zsh zsh-completions

Add oh-my-zsh

curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh

Make zsh default shell

chsh -s /bin/zsh

Add zsh-syntax highlighting plugin

git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting

Create custom theme file.

cp ~/.oh-my-zsh/themes/robbyrussell.zsh-theme ~/.oh-my-zsh/themes/scottgruber.zsh-theme

Copy and paste scottgruber.zsh-template file from this gist to update.

Open ~/.zshrc and change ZSH_THEME="robbyrussell" to ZSH_THEME="scottgruber" update plugins to plugins=(git zsh-syntax-highlighting)

Restart iTerm 2 source ~/.zshrc

Notes

  • I removed online-check and batcharge.py in scott.zsh-theme to disable them.
  • Add coding fonts from here and SourceCodePro from here.
# vim:ft=zsh ts=2 sw=2 sts=2
#
# Based on 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='⮀'
ONLINE='%{%F{green}%}◉'
OFFLINE='%{%F{red}%}⦿'
# 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
}
# disable online offline icon on cli
# function prompt_online() {
# if [[ -f ~/.offline ]]; then
# echo $OFFLINE
# else
# echo $ONLINE
# 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"
}
# disable battery charge symbol
# function battery_charge {
# echo `~/bin/batcharge.py`
# }
## Main prompt
build_prompt() {
RETVAL=$?
prompt_status
prompt_git
prompt_dir
prompt_end
}
# RPROMPT='$(prompt_online) $(battery_charge)'
PROMPT='%{%f%b%k%}$(build_prompt)
» '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment