Skip to content

Instantly share code, notes, and snippets.

@yetti
Created February 5, 2014 14:34
Show Gist options
  • Save yetti/8824851 to your computer and use it in GitHub Desktop.
Save yetti/8824851 to your computer and use it in GitHub Desktop.
Prezto prompt config
#
# Based on zsh-powerline and paradox
# * Time and Ruby version shown on the right
# * Git branch info on the left
# * Single line prompt
#
# Authors:
# Yetrina Battad <hello@yetti.io>
ZSH_THEME_REP_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
ZSH_THEME_REP_TIME_SINCE_COMMIT_MEDIUM="%{$fg[yellow]%}"
ZSH_THEME_REP_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
ZSH_THEME_REP_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
# returns the time since last git commit
function git_time_details() {
# only proceed if there is actually a git repository
if `git rev-parse --git-dir > /dev/null 2>&1`; then
# only proceed if there is actually a commit
if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
# get the last commit hash
# lc_hash=`git log --pretty=format:'%h' -1 2> /dev/null`
# get the last commit time
lc_time=`git log --pretty=format:'%at' -1 2> /dev/null`
now=`date +%s`
seconds_since_last_commit=$((now-lc_time))
lc_time_since=`time_since_commit $seconds_since_last_commit`
echo "$lc_time_since"
else
echo ""
fi
else
echo ""
fi
}
# returns the time by given seconds
function time_since_commit() {
seconds_since_last_commit=$(($1 + 0))
# totals
MINUTES=$((seconds_since_last_commit / 60))
HOURS=$((seconds_since_last_commit/3600))
# sub-hours and sub-minutes
DAYS=$((seconds_since_last_commit / 86400))
SUB_HOURS=$((HOURS % 24))
SUB_MINUTES=$((MINUTES % 60))
if [ "$HOURS" -gt 24 ]; then
echo "${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m"
elif [ "$MINUTES" -gt 60 ]; then
echo "${HOURS}h${SUB_MINUTES}m"
else
echo "${MINUTES}m"
fi
}
function rvm_info_for_prompt {
if which rvm-prompt &> /dev/null; then
rvm-prompt i v g
else
if which rbenv &> /dev/null; then
rbenv version | sed -e "s/ (set.*$//"
fi
fi
}
function prompt_powerline_precmd {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
# Check for untracked files or updated submodules since vcs_info doesn't.
if [[ ! -z $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
fmt_branch=" %b%u%c${__PROMPT_SKWP_COLORS[4]}%f"
else
fmt_branch=" %b%u%c"
fi
zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}"
# Get Git repository information.
if (( $+functions[git-info] )); then
git_status=git-info
fi
vcs_info 'prompt'
RVM_PRECMD_INFO=$(rvm_info_for_prompt)
# zstyle ':prezto:module:ruby' rvm '%r'
}
function prompt_powerline_setup {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst)
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
add-zsh-hook precmd prompt_powerline_precmd
# Use extended color pallete if available.
if [[ $TERM = *256color* || $TERM = *rxvt* ]]; then
__PROMPT_SKWP_COLORS=(
"%F{16}" # black
"%F{81}" # turquoise
"%F{166}" # orange
"%F{135}" # purple
"%F{161}" # hotpink
"%F{118}" # limegreen
)
else
__PROMPT_SKWP_COLORS=(
"%F{black}"
"%F{cyan}"
"%F{yellow}"
"%F{magenta}"
"%F{red}"
"%F{green}"
)
fi
# Enable VCS systems you use.
zstyle ':vcs_info:*' enable bzr git hg svn
# check-for-changes can be really slow.
# You should disable it if you work with large repositories.
zstyle ':vcs_info:*:prompt:*' check-for-changes true
# Formats:
# %b - branchname
# %u - unstagedstr (see below)
# %c - stagedstr (see below)
# %a - action (e.g. rebase-i)
# %R - repository path
# %S - path in the repository
# %n - user
# %m - machine hostname
# local fmt_branch="(${__PROMPT_SKWP_COLORS[2]}%b%f%u%c)"
local fmt_branch="${__PROMPT_SKWP_COLORS[3]} %b%f%u%c"
local fmt_action="${__PROMPT_SKWP_COLORS[6]} %a%f"
local fmt_unstaged="${black} *%f"
local fmt_staged="${__PROMPT_SKWP_COLORS[6]} ⬆%f"
zstyle ':vcs_info:*:prompt:*' unstagedstr "${fmt_unstaged}"
zstyle ':vcs_info:*:prompt:*' stagedstr "${fmt_staged}"
zstyle ':vcs_info:*:prompt:*' actionformats "${fmt_branch}${fmt_action}"
zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}"
zstyle ':vcs_info:*:prompt:*' nvcsformats ""
# SPLIT RVM PROMPT INFO
# TODO: should assign this to local variable? somehow doesn't work correctly.
rvm_split=("${(s/@/)$(rvm_info_for_prompt)}")
# if [ "$POWERLINE_RIGHT_B" = "" ]; then
local powerline_right_b=" %D{%H:%M:%S}"
#local powerline_right_b=$(ruby_version)
# fi
# if [ "$POWERLINE_RIGHT_A" = "" ]; then
local powerline_right_a=$(rvm_info_for_prompt)
# fi
# Setup powerline style colouring
POWERLINE_COLOR_BG_GRAY=%K{240}
POWERLINE_COLOR_BG_LIGHT_GRAY=%K{240}
POWERLINE_COLOR_BG_WHITE=%K{255}
POWERLINE_COLOR_BG_RED=%K{124}
POWERLINE_COLOR_FG_GRAY=%F{240}
POWERLINE_COLOR_FG_LIGHT_GRAY=%F{240}
POWERLINE_COLOR_FG_WHITE=%F{255}
POWERLINE_COLOR_FG_RED=%F{124}
POWERLINE_SEPARATOR=$'\U00E0B0'
POWERLINE_R_SEPARATOR=$'\U00E0B2'
POWERLINE_LEFT_A="%K{black}%F{white} %{%F{blue}%}%n%{%F{red}%}@%{%F{green}%}%M %(1?;%{%F{red}%}✘ ;)%(!;%{%F{yellow}%}⚡ ;)%(1j;%{%F{cyan}%}%j⚙ ;) "%k%f%F{black}%K{blue}$POWERLINE_SEPARATOR
POWERLINE_LEFT_B="%k%f%F{white}%K{blue} %2~ %k%f%F{blue}%K{green}"$POWERLINE_SEPARATOR
POWERLINE_LEFT_C=" %k%f%F{black}%K{green}"'${vcs_info_msg_0_}'" %k%f%F{green}"$POWERLINE_SEPARATOR"
%B%F{blue}❯ %f%b%F{white}"
PROMPT=$POWERLINE_LEFT_A$POWERLINE_LEFT_B$POWERLINE_LEFT_C
RPROMPT=$POWERLINE_COLOR_FG_WHITE$POWERLINE_R_SEPARATOR"%f$POWERLINE_COLOR_BG_WHITE$POWERLINE_COLOR_FG_GRAY$powerline_right_b "%f$POWERLINE_COLOR_BG_WHITE$POWERLINE_COLOR_FG_RED$POWERLINE_R_SEPARATOR"%f%k$POWERLINE_COLOR_BG_RED$POWERLINE_COLOR_FG_WHITE $powerline_right_a %f%k"
#RPROMPT=%K{black}$POWERLINE_COLOR_FG_WHITE$POWERLINE_R_SEPARATOR"%f$POWERLINE_COLOR_BG_WHITE $POWERLINE_COLOR_FG_GRAY"'$powerline_right_b'" "$POWERLINE_R_SEPARATOR"%f%k$POWERLINE_COLOR_BG_GRAY$POWERLINE_COLOR_FG_WHITE "'$powerline_right_a'" %f%k"
#RPROMPT=$POWERLINE_COLOR_FG_RED$POWERLINE_R_SEPARATOR"%f$POWERLINE_COLOR_BG_RED $POWERLINE_COLOR_FG_WHITE"'$(rvm_info_for_prompt)'" "
}
prompt_powerline_setup "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment