logicalhacking-zsh/themes/logicalhacking.zsh-theme

282 lines
7.9 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# vim:ft=zsh ts=4 sw=2 sts=2
# Copyright (C) 2017 Achim D. Brucker, https://www.brucker.ch
#
# LogicalHacking Theme
# A Agnoster-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# Make sure you have a recent version: the code points that Powerline
# uses changed in 2012, and older versions will display incorrectly,
# in confusing ways.
# Generic function for formatting the working directory - in particular,
# it allows zpresto-style shortening of the full path.
promptpwd() {
setopt localoptions extendedglob
local current_pwd="${PWD/#$HOME/~}"
local ret_directory
if [[ "$current_pwd" == (#m)[/~] ]]; then
ret_directory="$MATCH"
unset MATCH
elif zstyle -m ':lh:module:prompt' pwd-length 'full'; then
ret_directory=${PWD}
elif zstyle -m ':lh:module:prompt' pwd-length 'long'; then
ret_directory=${current_pwd}
else
ret_directory="${${${${(@j:/:M)${(@s:/:)current_pwd}##.#?}:h}%/}//\%/%%}/${${current_pwd:t}//\%/%%}"
fi
print "$ret_directory"
}
# Define abstract names for the PowerLine symbols
() {
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
PL_BRANCH=$'\ue0a0' # 
PL_LN=$'\ue0a1' # 
PL_CPADLOCK=$'\ue0a2' # 
PL_BRARROW=$'\ue0b0' # 
PL_RARROW=$'\ue0b1' # 
PL_BLARROW=$'\ue0b2' # 
PL_LARROW=$'\ue0b3' # 
}
# Drawing of segments
CURRENT_BG='NONE'
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
if [[ $CURRENT_BG != 'NONE' ]]; then
echo -n "%{$bg%}%{$fg%}$SEGMENT_SEPARATOR_SAME_COLOR"
fi
echo -n "%{$bg%}%{$fg%}"
fi
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
}
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%k%}"
fi
echo -n "%{%f%}"
CURRENT_BG=''
}
# Prompt: LH Logo
prompt_logo() {
prompt_segment $1 $2 "{*λH*}"
}
# Prompt: working directory
prompt_dir() {
prompt_segment $1 $2 "$(promptpwd)"
}
# Prompt: Isabelle Version
isa_version_cmd (){
echo `Isabelle version | sed -e 's/:.*//' -e 's/Isabelle//'`
}
isa_version_dir() {
echo `which isabelle | sed -e 's/.*Isabelle//' -e 's/.bin.*//'`
}
prompt_isabelle_env() {
ISADIR=false
if [[ -f ROOT || -f ROOTS ]]; then
ISADIR=true
else
if (){ setopt localoptions nonomatch nocshnullglob; [ -f *.thy([1]) ] }
then
ISADIR=true
fi
fi
if [ "$ISADIR" = true ]; then
prompt_segment $1 $2 "(Isabelle $( $ISAVERSION ))"
fi
}
# Prompt: git information (branch/detached head, dirty status)
prompt_git() {
(( $+commands[git] )) || return
local PL_BRANCH_CHAR
() {
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
PL_BRANCH_CHAR=$'\ue0a0' # 
}
local ref dirty mode repo_path
repo_path=$(git rev-parse --git-dir 2>/dev/null)
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
dirty=$(parse_git_dirty)
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="$(git rev-parse --short HEAD 2> /dev/null)"
if [[ -n $dirty ]]; then
prompt_segment "$1" "$3"
else
prompt_segment "$2" "$3"
fi
if [[ -e "${repo_path}/BISECT_LOG" ]]; then
mode=" <B>"
elif [[ -e "${repo_path}/MERGE_HEAD" ]]; then
mode=" >M<"
elif [[ -e "${repo_path}/rebase" || -e "${repo_path}/rebase-apply" || -e "${repo_path}/rebase-merge" || -e "${repo_path}/../.dotest" ]]; then
mode=" >R>"
fi
setopt promptsubst
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' get-revision true
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr '✚'
zstyle ':vcs_info:*' unstagedstr '●'
zstyle ':vcs_info:*' formats ' %u%c'
zstyle ':vcs_info:*' actionformats ' %u%c'
vcs_info
echo -n "${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
fi
}
# Prompt: Bazar
prompt_bzr() {
(( $+commands[bzr] )) || return
if (bzr status >/dev/null 2>&1); then
status_mod=`bzr status | head -n1 | grep "modified" | wc -m`
status_all=`bzr status | head -n1 | wc -m`
revision=`bzr log | head -n2 | tail -n1 | sed 's/^revno: //'`
if [[ $status_mod -gt 0 ]] ; then
prompt_segment $1 $3
echo -n "bzr@"$revision "✚ "
else
if [[ $status_all -gt 0 ]] ; then
prompt_segment $1 $3
echo -n "bzr@"$revision
else
prompt_segment $2 $3
echo -n "bzr@"$revision
fi
fi
fi
}
# Prompt Setup and key bindings
build_prompt() {
RETVAL=$?
prompt_logo $LHORANGE black
prompt_isabelle_env $LHCYAN black
prompt_dir $LHLIGHTORANGE black
prompt_git $LHGOLD $LHGREEN black
prompt_bzr $LHGOLD $LHGREEN black
prompt_end
}
build_inactive_prompt() {
RETVAL=$?
prompt_logo $LHDARKGRAY white
prompt_isabelle_env $LHLIGHTGRAY white
prompt_dir $LHLIGHTGRAY white
prompt_git $LHDARKGRAY $LHDARKGRAY white
prompt_bzr $LHDARKGRAY $LHDARKGRAY white
prompt_end
}
del-prompt-accept-line() {
OLD_PROMPT="$PROMPT"
PROMPT=$INACTIVEPROMPT
zle reset-prompt
PROMPT="$OLD_PROMPT"
zle accept-line
}
zle -N del-prompt-accept-line
bindkey "^M" del-prompt-accept-line
# Actual prompt definition
PROMPT='%{%f%b%k%}$(build_prompt) '
INACTIVEPROMPT='%{%f%b%k%}$(build_inactive_prompt) '
# Default configuration
SEGMENT_SEPARATOR=$PL_BRARROW
SEGMENT_SEPARATOR_SAME_COLOR=" %{$fg[black]%}$PL_RARROW "
ISAVERSION=isa_version_dir
if [[ "$TERM" =~ ".*256.*" ]]; then
# 0 - 15: System colors (color theme might define up to color 21)
# 16 - 231: 6x6x6 color cube, for R, G, B \in {0, ..., 5}:
# index = 16 + R×6×6 + G×6 + B
# 132 - 255: grayscale
#
# 243 107 33 #F36B21 lhOrange
LHORANGE=202 #FF5F00
# 65 242 34 #41F222 lhGreen
LHGREEN=82 #5FFF00
# 30 174 219 #1EAEDB lhCyan
LHCYAN=38 #00AFD7
# 211 34 242 #D322F2 lhMagenta
LHMAGENTA=165 #D700FF
# 242 211 34 #F2D322 lhGold
LHGOLD=220 #FFD700
#
# 156 69 22 #9C4516 lhOrangeMedium
LHORANGEMEDIUM=130 #AF5F00
# 42 156 22 #2A9C16 lhGreenMedium
LHGREENMEDIUM=34 #00AF00
# 22 109 156 #166D9C lhCyanMedium
LHCYANMEDIUM=25 #0055af
# 135 22 156 #87169C lhMagentaMedium
LHMAGENTAMEDIUM=91 #8700AF
# 156 135 22 #9C8716 lhGoldMedium
LHGOLDMEDIUM=136 #AF8700
#
# 71 31 10 #471F0A lhOrangeDark
LHORANGEDARK=52 #%F0000
# 19 71 10 #13470A lhGreenDark
LHGREENDARK=22 #005f00
# 10 50 71 #0A3247 lhCyanDark
LHCYANDARK=23 #005F5F
# 62 10 71 #3E0A47 lhMagentaDark
LHMAGENTADARK=53 #5F005F
# 51 86 28 #33561C lhGoldDark
LHGOLDDARK=58 #5F5F00
#
# 204 204 204 #CCCCCC lhLightGray
LHLIGHTGRAY=188 #D7D7D7
# 68 68 68 #444444 lhDarkGray
LHDARKGRAY=59 #5F5F5F
# 8 8 8 #080808 lhBlack
LHBLACK=232 #080808
# 248 248 248 #F8F8F8 lhWhite
LHWHITE=255 #EEEEEE
else
LHORANGE="068"
LHLIGHTORANGE="016"
LHDARKGRAY="019"
LHLIGHTGRAY="008"
LHCYAN="014"
LHGOLD="003"
LHGREEN="002"
fi