Skip to content

Instantly share code, notes, and snippets.

@syui
Created March 24, 2014 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syui/9737740 to your computer and use it in GitHub Desktop.
Save syui/9737740 to your computer and use it in GitHub Desktop.
# PROMPT {{{
setopt prompt_subst
setopt prompt_percent
setopt transient_rprompt
color256()
{
local red=$1; shift
local green=$2; shift
local blue=$3; shift
echo -n $[$red * 36 + $green * 6 + $blue + 16]
}
fg256()
{
echo -n $'\e[38;5;'$(color256 "$@")"m"
}
bg256()
{
echo -n $'\e[48;5;'$(color256 "$@")"m"
}
zstyle ':vcs_info:*' max-exports 3
zstyle ':vcs_info:hg:*' get-revision true
zstyle ':vcs_info:hg:*' use-simple true
autoload -Uz is-at-least
zstyle ':vcs_info:git:*' check-for-changes true
zstyle ':vcs_info:git:*' stagedstr "-"
zstyle ':vcs_info:git:*' unstagedstr "+"
zstyle ':vcs_info:git:*' formats '%K{green}%F{black}▶%k%f%%F{white}%K{green} %s %f%k%K{blue}%F{green}▶%k%f%%F{white}%K{blue} %b %f%k%K{black}%F{blue}▶%k%f%%F{white}%K{black} %c%u %f%k'
autoload -Uz vcs_info
prompt_bar_left_self="%{%F{white}%K{blue}%} %n%{%k%f%}%{%F{white}%K{blue}%}@%{%k%f%}%{%F{white}%K{blue}%}%m %{%k%f%}%{%B%F{blue}%K{blue}%}%{%b%f%k%}%K{cyan}%F{blue}▶%k%f%{%B%F{white}%K{cyan}%} [%~] %{%k%f%b%}%{%k%f%}%K{red}%F{cyan}▶%k%f%(?.%F{white}%K{red}%} COMP %k%f.%B%K{red}%F{red}%} ERROR %b%k%f)%{%K{green}%F{red}▶%k%f%F{white}%K{green}%} -%h %{%k%f%}%K{black}%F{green}▶%k%f"
#TMUX_POWERLINE_SEPARATOR_LEFT_BOLD="◀"
#TMUX_POWERLINE_SEPARATOR_LEFT_THIN="❮"
#TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD="▶"
#TMUX_POWERLINE_SEPARATOR_RIGHT_THIN="❯"
prompt_bar_left="${prompt_bar_left_self} ${prompt_bar_left_status} ${prompt_bar_left_date}"
prompt_left='%{%F{white}%K{black}%} $SHELL %{%k%f%}%{%K{white}%F{black}▶%k%f%B%F{black}%K{white}%} %# %{%b%k%f%f%}%K{black}%F{white}▶%k%f '
count_prompt_characters()
{
print -n -P -- "$1" | sed -e $'s/\e\[[0-9;]*m//g' | wc -m | sed -e 's/ //g'
}
update_prompt()
{
local bar_left_length=$(count_prompt_characters "$prompt_bar_left")
local bar_rest_length=$[COLUMNS - bar_left_length]
local bar_left="$prompt_bar_left"
local bar_right_without_path="${prompt_bar_right:s/%d//}"
local bar_right_without_path_length=$(count_prompt_characters "$bar_right_without_path")
# local max_path_length=$[bar_rest_length - bar_right_without_path_length]
bar_right=${prompt_bar_right:s/%d/%(C,%${max_path_length}<...<%d%<<,)/}
bar_right="%${bar_rest_length}<<${separator}${bar_right}%<<"
PROMPT="${bar_left}${bar_right}"$'\n'"${prompt_left}"
RPROMPT="%K{white}%F{black}▶%k%f%{%F{black}%K{white}%} %l %K{black}%F{white}▶%k%f%{%k%f%}%{%F{white}%K{black}%} $LANG %{%k%f%}"
case "$TERM_PROGRAM" in
Apple_Terminal)
RPROMPT="${RPROMPT}"
;;
esac
LANG=C vcs_info >&/dev/null
if [ -n "$vcs_info_msg_0_" ]; then
RPROMPT="${vcs_info_msg_0_}${RPROMPT}"
fi
}
precmd_functions=($precmd_functions update_prompt)
# }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment