Update ZSH theme

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-11-17 00:17:13 +01:00
parent 08ea6abf2b
commit 60d08b8998
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -1,7 +1,6 @@
# luzifer.zsh-theme
# Use with a dark background and 256-color terminal!
# Meant for people with RVM and git. Tested only on OS X 10.7.
# You can set your computer name in the ~/.box-name file if you want.
@ -11,73 +10,82 @@
#
# Also borrowing from http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/
function prompt_char {
git branch >/dev/null 2>/dev/null && echo '⠠⠵' && return
echo '○'
function box_color() {
[ -f ~/.box_color ] && cat ~/.box_color || ~/bin/color_from_hostname.py
}
function box_color {
[ -f ~/.box_color ] && cat ~/.box_color || ~/bin/color_from_hostname.py
function box_name() {
[ -f ~/.box-name ] && cat ~/.box-name || echo ${SHORT_HOST:-$HOST}
}
function box_name {
[ -f ~/.box-name ] && cat ~/.box-name || echo ${SHORT_HOST:-$HOST}
function git_describe() {
git describe --tags 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || printf '\ue701'
}
function git_describe {
git describe --tags 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo ""
function awsenv_prompt() {
local pr=$(awsenv prompt 2>/dev/null)
[ -z "${pr}" ] || echo "${bracket_open} ${pr} ${bracket_close}"
}
function awsenv_prompt {
local pr=$(awsenv prompt 2>/dev/null)
[ -z "${pr}" ] || echo "${bracket_open} ${pr} ${bracket_close}"
function config-git_prompt() {
if [ -f ~/bin/config-git-status.sh ]; then
if ! (~/bin/config-git-status.sh); then
echo "${bracket_open} %{$fg[red]%} ${bracket_close}"
fi
fi
}
function config-git_prompt {
if [ -f ~/bin/config-git-status.sh ]; then
if ! ( ~/bin/config-git-status.sh ); then
echo "${bracket_open} %{$fg[red]%} ${bracket_close}"
fi
fi
}
function build_git_prompt() {
# Allow hiding the right side of the prompt
(test "${NO_RIGHT}" = "true") && return
function build_git_prompt {
$( test "${NO_RIGHT}" = "true" ) && return
git branch >/dev/null 2>/dev/null || return
local INDEX=$(command git status --porcelain -b 2> /dev/null)
echo -n "${bracket_open} %{$fg[blue]%}"
local REMOTE=$(command git remote -v | grep fetch)
(echo "$REMOTE" | grep -q bitbucket.org) && echo -n "B "
(echo "$REMOTE" | grep -q github.com) && echo -n "G "
(echo "$REMOTE" | grep -q gitlab.com) && echo -n "L "
(echo "$REMOTE" | grep -q collins.kg) && echo -n "C "
echo -n "%{$reset_color%}"
echo -n "$(git_current_branch) "
echo -n "($(git_describe)) "
# Repository status
echo -n "%{$FG[236]%}"
( echo "$INDEX" | grep -E '^\?\? ' &> /dev/null ) && echo -n "%{$fg[blue]%}"
echo -n "U%{$FG[236]%}"
( echo "$INDEX" | grep -E '^(A |M ) ' &> /dev/null ) && echo -n "%{$fg[green]%}"
echo -n "A%{$FG[236]%}"
( echo "$INDEX" | grep -E '^( M|AM| T) ' &> /dev/null ) && echo -n "%{$fg[yellow]%}"
echo -n "M%{$FG[236]%}"
( echo "$INDEX" | grep -E '^R ' &> /dev/null ) && echo -n "%{$fg[yellow]%}"
echo -n "R%{$FG[236]%}"
( echo "$INDEX" | grep -E '^( D|D |AD) ' &> /dev/null ) && echo -n "%{$fg[red]%}"
echo -n "D%{$FG[236]%}"
( git rev-parse --verify refs/stash >/dev/null 2>&1 ) && echo -n "%{$fg[green]%}"
echo -n "S%{$FG[236]%}"
if ( echo "$INDEX" | grep '^## .*ahead.*behind' &> /dev/null ); then
echo -n "%{$fg[red]%}↔"
elif ( echo "$INDEX" | grep '^## .*ahead' &> /dev/null ); then
echo -n "%{$fg[green]%}→"
elif ( echo "$INDEX" | grep '^## .*behind' &> /dev/null ); then
echo -n "%{$fg[yellow]%}←"
else
echo -n "%{$fg[green]%}="
fi
echo -n "%{$reset_color%} ${bracket_close}"
# When there is no git, don't show a git prompt
git branch >/dev/null 2>/dev/null || return
# Fetch status of the current repo
local INDEX=$(command git status --porcelain -b 2>/dev/null)
local REMOTE=$(command git remote -v | grep fetch)
echo -n "${bracket_open} %{$fg[blue]%}"
# Mark specific remotes
case "${REMOTE}" in
*bitbucket.org*)
printf '\ue703 '
;;
*github.com*)
printf '\ue709 '
;;
*gitlab.com*)
printf '\uf296 '
;;
*)
printf '\uf1d3 '
;;
esac
# Show current branch and commit / tag
echo -n "%{$reset_color%}"
echo -n "$(git_current_branch) "
echo -n "($(git_describe)) "
# Print repository status information
[ $(echo "$INDEX" | wc -l) -gt 1 ] && echo -n "%{$fg[red]%}$(printf '\uf0f6')%{$FG[236]%} "
(git rev-parse --verify refs/stash >/dev/null 2>&1) && echo -n "%{$fg[blue]%}$(printf '\uf64c')%{$FG[236]%} "
# Show difference to remote
if (echo "$INDEX" | grep '^## .*ahead.*behind' &>/dev/null); then
echo -n "%{$fg[red]%}$(printf '\uf047')"
elif (echo "$INDEX" | grep '^## .*ahead' &>/dev/null); then
echo -n "%{$fg[green]%}$(printf '\uf061')"
elif (echo "$INDEX" | grep '^## .*behind' &>/dev/null); then
echo -n "%{$fg[yellow]%}$(printf '\uf060')"
else
echo -n "%{$fg[green]%}="
fi
echo -n "%{$reset_color%} ${bracket_close}"
}
local current_dir='$(short_path)'
@ -94,8 +102,8 @@ local prompt_part_char='$(prompt_char)'
local prompt_part_configgit='$(config-git_prompt)'
PROMPT="
╭─ ${prompt_part_time}${prompt_part_user}${prompt_part_configgit}$(awsenv_prompt)${prompt_part_exit} ${prompt_part_path}
╰─${prompt_part_char} "
╭─ ${prompt_part_time}${prompt_part_user}${prompt_part_configgit}${prompt_part_exit} ${prompt_part_path}
╰─ "
RPROMPT="${git_info}"
@ -105,3 +113,5 @@ ZSH_THEME_GIT_PROMPT_SUFFIX=""
# Format for git_prompt_long_sha() and git_prompt_short_sha()
ZSH_THEME_GIT_PROMPT_SHA_BEFORE=""
ZSH_THEME_GIT_PROMPT_SHA_AFTER=""
# vim: set ft=zsh: