Skip to content

Instantly share code, notes, and snippets.

Created January 29, 2016 11:20
Show Gist options
  • Save anonymous/f105a60d1e03f2c91328 to your computer and use it in GitHub Desktop.
Save anonymous/f105a60d1e03f2c91328 to your computer and use it in GitHub Desktop.
#
# A ZSH theme inspired by paradox and agnoster themes,
# supercharged with FontAwesome icons.
#
# This theme requires a patched Powerline font. You will also need to
# have FontAwesome set as default fallback font.
#
# Authors:
# Jerome Indefenzo <jeromeindefenzo@gmail.com>
# -- define special characters
left_solid=""
left_outline=""
right_solid=""
right_outline=""
fa_code_fork=""
fa_check=""
fa_times=""
fa_bolt=""
fa_user=""
fa_cog=""
fa_caret_right=""
fa_folder=""
fa_folder_open=""
fa_home=""
fa_archive=""
fa_code=""
fa_flask=""
fa_hdd_o=""
fa_server=""
fa_tag=""
fa_tags=""
# -- replace icons with text
# -- preview colors
function preview_colors() {
for (( i = 0; i <= 7; i++ )); do
print -nP "%{%K{$i}%F{0}%} $i "
done
for (( i = 7; i >= 0; i-- )); do
print -nP "%{%K{$i}%F{7}%} $i "
done
print -nP "%{%k%f%}\n\n"
}
# -- prompt builder utils
# outputs a specified string with optional colors
function prompt_string() {
# print specified colors, use default if empty
[[ -n $1 ]] && print -nP "%{%K{$1}%}" || print -nP "%{%k%}"
[[ -n $2 ]] && print -nP "%{%F{$2}%}" || print -nP "%{%f%}"
# print string
[[ -n $3 ]] && print -nP "$3"
}
# outputs current directory location, takes in 4 args: bg1, fg1, bg2, fg2
function prompt_dir() {
# setup directory segments
local prompt_dir_segments=(${(s:/:)PWD})
# output initial icon label
local omit=0
prompt_string black $1 $right_solid
if [[ $UID -ne 0 && "$prompt_dir_segments[1]" == "home" && "$prompt_dir_segments[2]" != "" ]]; then
prompt_string $1 $2 " $fa_home "
omit=2
elif [[ $UID -eq 0 && "$prompt_dir_segments[1]" == "root" ]]; then
prompt_string $1 $2 " $fa_home "
omit=1
else
prompt_string $1 $2 " $fa_hdd_o "
fi
[[ "$prompt_dir_segments[$((omit+1))]" != "" ]] && prompt_string $3 $1 $left_solid
# output segments
local i=0 j=omit
for prompt_dir_segment in $prompt_dir_segments; do
if [[ j -eq 0 ]]; then
[[ i -ne 0 ]] && prompt_string $3 $1 $left_outline
prompt_string $3 $4 " $prompt_dir_segment "
i+=1
else
j+=-1
fi
done
local prompt_dir_end=$3 prompt_dir_bg=none
[[ "$prompt_dir_segments[$((omit+1))]" == "" ]] && prompt_dir_end=$1
[[ -d .git ]] && prompt_dir_bg=black
prompt_string $prompt_dir_bg $prompt_dir_end $left_solid
}
# -- output prompt segments
function prompt_jemhuntr_build() {
# preview_colors
# output extra newline
print -nP "%{%k%f%}\n%{%k%f%}"
# display return value status
if [[ $RETVAL -eq 0 ]]; then
prompt_string green white " $fa_check "
prompt_string black green $left_solid
else
prompt_string red white " $fa_times "
prompt_string black red $left_solid
fi
# display user status (root or not) and output dir
if [[ $UID -eq 0 ]]; then
prompt_string yellow black $left_solid
prompt_string yellow black " $fa_bolt "
prompt_string yellow black $right_solid
prompt_dir magenta black red white
else
prompt_string black black $left_solid
prompt_string black white " $fa_user "
prompt_string black black $right_solid
prompt_dir cyan black blue white
fi
# display git info
if [[ -d .git ]]; then
prompt_string black yellow " $fa_code_fork ${vcs_info_msg_0_} "
prompt_string none black $left_solid
fi
# end line
print -nP "%{$reset_color%}$prompt_newline"
}
# -- pre-command setup
function prompt_jemhuntr_precmd() {
# get return status of previous command
RETVAL=$?
# get vcs_info
vcs_info
# build prompt
prompt_jemhuntr_build
# update prompts
PROMPT="%{$reset_color%} $fa_caret_right %{$reset_color%}"
RPROMPT="%{%F{black}%k%}$right_solid%{%K{black}%}"
RPROMPT+="%{%F{red}%K{black}%} $(rbenv version-name) "
RPROMPT+="%{%F{red}%K{black}%}$right_solid"
RPROMPT+="%{%F{white}%K{red}%} rb %{%F{black}%}$right_solid"
RPROMPT+="%{%F{green}%K{black}%} $(pyenv version-name) "
RPROMPT+="%{%F{green}%K{black}%}$right_solid"
RPROMPT+="%{%F{black}%K{green}%} py %{%F{white}%}$right_solid"
RPROMPT+="%{%K{white}%F{black}%} %D{%H:%M:%S} %{%F{white}%k%}$left_solid%{%f%k%}"
}
# -- output prompt cmd and time
function prompt_jemhuntr_setup() {
# autoload external plugins
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
# set options
setopt PROMPT_SUBST
# attach precmd hook to custom precmd function
add-zsh-hook precmd prompt_jemhuntr_precmd
# configure vcs_info outputs
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git*' formats '%b'
zstyle ':vcs_info:git*' actionformats '%b (%a)'
}
prompt_jemhuntr_setup "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment