This commit is contained in:
Andrey Anurin
2016-05-16 23:46:33 -07:00
commit 916d13f93e
412 changed files with 37846 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
Powerline for [Prezto](http://github.com/sorin-ionescu/prezto) ZSH
## Features
* Single line prompt
* Git branch info (current branch and modified states)
* Time since last commit
* RVM current ruby version / gemset
![Example](https://raw.github.com/davidjrice/prezto_powerline/master/prompt.png)
## Dependencies
* [skwp/dotfiles](http://github.com/skwp/dotfiles) *(YADR)*
* [prezto](https://github.com/sorin-ionescu/prezto) (included by YADR)
## Installation
# Install YADR
git clone https://github.com/skwp/dotfiles ~/.yadr
cd ~/.yadr && rake install
# Create a ~/.secrets file (required by YADR)
touch ~/.secrets
# Install the prompt
curl https://raw.github.com/davidjrice/prezto_powerline/master/prompt_powerline_setup > ~/.zsh.prompts/prompt_powerline_setup
# Install Solarized
git clone https://github.com/altercation/solarized
cd solarized
# e.g. for iTerm
cd iterm2-colors-solarized/
open Solarized\ Dark.itermcolors
# this should load the colours for iTerm, but they are not configured yet
# in iTerm2 open preferences
# profiles > default > colours > load presets > Solarized Dark
# profiles > default > terminal > report terminal type > "xterm-256color"
# Enable
echo "prompt powerline" > ~/.zsh.after/prompt.zsh
## Inspiration
This prompt is inspired by:
* [oh-my-zsh-powerline-theme](http://github.com/jeremyFreeAgent/oh-my-zsh-powerline-theme)
* [robbl oh-my-zsh theme](http://github.com/robbl/oh-my-zsh-config)
* [SKWP prezto theme](http://github.com/skwp/dotfiles/blob/master/zsh/prezto-themes/prompt_skwp_setup)
## TODO
* Moar configurable
* Extract functions to Prezto modules?
* Use better Prezto best practices...?
* Handle NVM version info?

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

View File

@@ -0,0 +1,185 @@
#
# A ZSH theme based on a combination of the skwp prezto theme and the robl ohmyzsh theme.
# * RVM info shown on the right
# * Git branch info on the left
# * Single line prompt
# * Time since last commit on the left
# * Time in place of user@hostname
#
# Authors:
# David Rice <me@davidjrice.co.uk>
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 [[ -d ~/.rvm/ ]]; then
local ruby_version=$(~/.rvm/bin/rvm-prompt)
if [ -n "$ruby_version" ]; then
echo "$ruby_version"
fi
else
echo ""
fi
}
function prompt_powerline_precmd {
# 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}"
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{81}" # turquoise
"%F{166}" # orange
"%F{135}" # purple
"%F{161}" # hotpink
"%F{118}" # limegreen
)
else
__PROMPT_SKWP_COLORS=(
"%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[1]}%b%f%u%c)"
local fmt_branch="${__PROMPT_SKWP_COLORS[2]}%b%f%u%c"
local fmt_action="${__PROMPT_SKWP_COLORS[5]}%a%f"
local fmt_unstaged="${__PROMPT_SKWP_COLORS[2]}●%f"
local fmt_staged="${__PROMPT_SKWP_COLORS[5]}●%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
# POWERLINE_RIGHT_B=%D{%H:%M:%S}
local powerline_right_b=$rvm_split[1]
# fi
# if [ "$POWERLINE_RIGHT_A" = "" ]; then
local powerline_right_a=$rvm_split[2]
# 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_FG_GRAY=%F{240}
POWERLINE_COLOR_FG_LIGHT_GRAY=%F{240}
POWERLINE_COLOR_FG_WHITE=%F{255}
POWERLINE_SEPARATOR=$'\u2b80'
POWERLINE_R_SEPARATOR=$'\u2b82'
POWERLINE_LEFT_A="%K{green}%F{white} %~ %k%f%F{green}%K{blue}"$POWERLINE_SEPARATOR
POWERLINE_LEFT_B="%k%f%F{white}%K{blue} "'${vcs_info_msg_0_}'" %k%f%F{blue}%K{black}"$POWERLINE_SEPARATOR
POWERLINE_LEFT_C=" %k%f%F{white}%K{black}"'$(git_time_details)'" %k%f%F{black}"$POWERLINE_SEPARATOR"%f "
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 "$POWERLINE_R_SEPARATOR"%f%k$POWERLINE_COLOR_BG_GRAY$POWERLINE_COLOR_FG_WHITE $powerline_right_a %f%k"
# RPROMPT=$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_WHITE$POWERLINE_R_SEPARATOR"%f$POWERLINE_COLOR_BG_WHITE $POWERLINE_COLOR_FG_GRAY"'$(rvm_info_for_prompt)'" "
}
prompt_powerline_setup "$@"