Skip to content

Commit

Permalink
Merge changes from Agnoster upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-auer committed Nov 29, 2020
1 parent 0b63d90 commit 851d1dc
Showing 1 changed file with 74 additions and 90 deletions.
164 changes: 74 additions & 90 deletions multiline.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
# # 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.
# [Powerline-patched font](https://gist.github.com/1595572).
#
# In addition, I recommend the
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
Expand All @@ -34,29 +31,14 @@

CURRENT_BG='NONE'

case ${SOLARIZED_THEME:-dark} in
light) CURRENT_FG='white';;
*) CURRENT_FG='black';;
esac

DEFAULT_BG=$CURRENT_FG

# Special Powerline characters

() {
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
# NOTE: This segment separator character is correct. In 2012, Powerline changed
# the code points they use for their special characters. This is the new code point.
# If this is not working for you, you probably have an old version of the
# Powerline-patched fonts installed. Download and install the new version.
# Do not submit PRs to change this unless you have reviewed the Powerline code point
# history and have new information.
# This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of
# what font the user is viewing this source code in. Do not replace the
# escape sequence with a single literal character.
# Do not change this! Do not make it '\u2b80'; that is the old, wrong code point.
SEGMENT_SEPARATOR=$'\ue0b0'
}
if [ "$(echo $COLORFGBG | cut -d ';' -f2)" -gt 8 ]; then
PRIMARY_FG=white
else
PRIMARY_FG=black
fi

# Characters
SEGMENT_SEPARATOR="\ue0b0"

# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
Expand All @@ -66,23 +48,23 @@ prompt_segment() {
[[ -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%} "
print -n "%{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%}"
else
echo -n "%{$bg%}%{$fg%} "
print -n "%{$bg%}%{$fg%}"
fi
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
[[ -n $3 ]] && print -n $3
}

# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%k%}"
print -n "%{%k%}"
fi
echo
echo -n "%{%F{green}%} ❯%{%f%}"
print
print -n "%{%F{green}%} ❯%{%f%}"
CURRENT_BG=''
}

Expand All @@ -91,88 +73,71 @@ prompt_end() {

# Context: user@hostname (who am I and where am I)
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment $DEFAULT_BG default "%(!.%{%F{yellow}%}.)%n@%m"
local user=`whoami`

if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CONNECTION" ]]; then
prompt_segment $PRIMARY_FG default " %(!.%{%F{yellow}%}.)$user@%m "
fi
}

# Git: branch/detached head, dirty status
prompt_git() {
(( $+commands[git] )) || return
if [[ "$(git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then
return
fi
local PL_BRANCH_CHAR
() {
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
PL_BRANCH_CHAR=$'\ue0a0' #
local color ref
is_dirty() {
test -n "$(git status --porcelain --ignore-submodules)"
}
local ref dirty mode repo_path

if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then
repo_path=$(git rev-parse --git-dir 2>/dev/null)
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 yellow black
ref="$vcs_info_msg_0_"
if [[ -n "$ref" ]]; then
if is_dirty; then
color=yellow
ref="${ref} \u00b1"
else
prompt_segment green $CURRENT_FG
color=green
ref="${ref} "
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>"
if [[ "${ref/.../}" == "$ref" ]]; then
ref="\ue0a0 $ref"
else
ref="\u27a6 ${ref/.../}"
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}"
prompt_segment $color $PRIMARY_FG
print -n " $ref"
fi
}

# Dir: current working directory
prompt_dir() {
prompt_segment blue $CURRENT_FG '%~'
}

# Virtualenv: current working virtualenv
prompt_virtualenv() {
local virtualenv_path="$VIRTUAL_ENV"
if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
prompt_segment yellow $CURRENT_FG "(`basename $virtualenv_path`)"
fi
prompt_segment blue $PRIMARY_FG ' %~ '
}

# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
local -a symbols
local symbols
symbols=()
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}\u2718 $RETVAL"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}\u26a1"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}\u2699"

[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘ $RETVAL"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
[[ -n "$symbols" ]] && prompt_segment $PRIMARY_FG default " $symbols "
}

[[ -n "$symbols" ]] && prompt_segment $DEFAULT_BG default "$symbols"
# Display current virtual environment
prompt_virtualenv() {
if [[ -n $VIRTUAL_ENV ]]; then
prompt_segment yellow $PRIMARY_FG
print -Pn " $(basename $VIRTUAL_ENV) "
fi
}

## Main prompt
build_prompt() {
prompt_agnoster_main() {
RETVAL=$?
echo
CURRENT_BG='NONE'

print
prompt_status
prompt_context
prompt_virtualenv
Expand All @@ -181,4 +146,23 @@ build_prompt() {
prompt_end
}

PROMPT='%{%f%b%k%}$(build_prompt) '
prompt_agnoster_precmd() {
vcs_info
PROMPT='%{%f%b%k%}$(prompt_agnoster_main) '
}

prompt_agnoster_setup() {
autoload -Uz add-zsh-hook
autoload -Uz vcs_info

prompt_opts=(cr subst percent)

add-zsh-hook precmd prompt_agnoster_precmd

zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' check-for-changes false
zstyle ':vcs_info:git*' formats '%b'
zstyle ':vcs_info:git*' actionformats '%b (%a)'
}

prompt_agnoster_setup "$@"

0 comments on commit 851d1dc

Please sign in to comment.