mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-12 21:39:48 +01:00
Updated documentation for agnoster theme
This commit is contained in:
parent
bf4157514f
commit
6e85ff5b44
1 changed files with 64 additions and 35 deletions
|
@ -1,22 +1,51 @@
|
||||||
|
# vim:ft=zsh ts=2 sw=2 sts=2
|
||||||
|
#
|
||||||
|
# agnoster's Theme
|
||||||
|
# A Powerline-inspired theme for ZSH
|
||||||
|
#
|
||||||
|
# # README
|
||||||
|
#
|
||||||
|
# In order for this theme to render correctly, you will need a
|
||||||
|
# [Powerline-patched font](https://gist.github.com/1595572).
|
||||||
|
#
|
||||||
|
# In addition, I recommend the
|
||||||
|
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
|
||||||
|
# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app -
|
||||||
|
# it has significantly better color fidelity.
|
||||||
|
#
|
||||||
|
# # Goals
|
||||||
|
#
|
||||||
|
# The aim of this theme is to only show you *relevant* information. Like most
|
||||||
|
# prompts, it will only show git information when in a git working directory.
|
||||||
|
# However, it goes a step further: everything from the current user and
|
||||||
|
# hostname to whether the last call exited with an error to whether background
|
||||||
|
# jobs are running in this shell will all be displayed automatically when
|
||||||
|
# appropriate.
|
||||||
|
|
||||||
### Segment drawing
|
### Segment drawing
|
||||||
# A few utility functions to make it easy and re-usable to draw segmented prompts
|
# A few utility functions to make it easy and re-usable to draw segmented prompts
|
||||||
|
|
||||||
CURRENT_BG=''
|
CURRENT_BG='NONE'
|
||||||
SEGMENT_SEPARATOR='⮀'
|
SEGMENT_SEPARATOR='⮀'
|
||||||
function segment_start() {
|
|
||||||
local bg=$1
|
# Begin a segment
|
||||||
local fg=$2
|
# Takes two arguments, background and foreground. Both can be omitted,
|
||||||
if [[ -n $CURRENT_BG && $bg != $CURRENT_BG ]]; then
|
# rendering default background/foreground.
|
||||||
echo -n " %{%K{$bg}%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
|
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
|
else
|
||||||
echo -n "%{%K{$bg}%}"
|
echo -n "%{$bg%}%{$fg%} "
|
||||||
fi
|
fi
|
||||||
[[ -n $fg ]] && fg="%F{$fg}" || fg="%f"
|
CURRENT_BG=$1
|
||||||
echo -n "%{$fg%} "
|
[[ -n $3 ]] && echo -n $3
|
||||||
CURRENT_BG=$bg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function segment_stop() {
|
# End the prompt, closing any open segments
|
||||||
|
prompt_end() {
|
||||||
if [[ -n $CURRENT_BG ]]; then
|
if [[ -n $CURRENT_BG ]]; then
|
||||||
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
|
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
|
||||||
else
|
else
|
||||||
|
@ -29,58 +58,58 @@ function segment_stop() {
|
||||||
### Prompt components
|
### Prompt components
|
||||||
# Each component will draw itself, and hide itself if no information needs to be shown
|
# Each component will draw itself, and hide itself if no information needs to be shown
|
||||||
|
|
||||||
function prompt_context() {
|
# Context: user@hostname (who am I and where am I)
|
||||||
|
prompt_context() {
|
||||||
local user=`whoami`
|
local user=`whoami`
|
||||||
|
|
||||||
if [[ ("$user" != "$DEFAULT_USER") || (-n "$SSH_CLIENT") ]]; then
|
if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
|
||||||
segment_start black
|
prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m"
|
||||||
#echo -n "%{%F{yellow}%}$user%{%F{gray}%}@%{%F{green}%}%m%{%f%}"
|
|
||||||
echo -n "%(!.%{%F{yellow}%}.)$user@%m"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function prompt_git() {
|
# Git: branch/detached head, dirty status
|
||||||
|
prompt_git() {
|
||||||
|
local ref dirty
|
||||||
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
|
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
|
||||||
ZSH_THEME_GIT_PROMPT_DIRTY='±'
|
ZSH_THEME_GIT_PROMPT_DIRTY='±'
|
||||||
local dirty=$(parse_git_dirty)
|
dirty=$(parse_git_dirty)
|
||||||
local ref
|
|
||||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
|
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
|
||||||
if [[ -n $dirty ]]; then
|
if [[ -n $dirty ]]; then
|
||||||
segment_start yellow black
|
prompt_segment yellow black
|
||||||
else
|
else
|
||||||
segment_start green black
|
prompt_segment green black
|
||||||
fi
|
fi
|
||||||
echo -n "${ref/refs\/heads\//⭠ }$dirty"
|
echo -n "${ref/refs\/heads\//⭠ }$dirty"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function prompt_dir() {
|
# Dir: current working directory
|
||||||
segment_start blue white
|
prompt_dir() {
|
||||||
echo -n '%~'
|
prompt_segment blue black '%~'
|
||||||
}
|
}
|
||||||
|
|
||||||
function prompt_status() {
|
# Status:
|
||||||
|
# - was there an error
|
||||||
|
# - am I root
|
||||||
|
# - are there background jobs?
|
||||||
|
prompt_status() {
|
||||||
local symbols
|
local symbols
|
||||||
symbols=()
|
symbols=()
|
||||||
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
|
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
|
||||||
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
|
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
|
||||||
jobs=$(jobs -l | wc -l)
|
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
|
||||||
[[ $jobs -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
|
|
||||||
if [[ -n "$symbols" ]]; then
|
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
|
||||||
segment_start black white
|
|
||||||
echo -n "${symbols}"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## Main prompt
|
## Main prompt
|
||||||
function build_prompt() {
|
build_prompt() {
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
prompt_status
|
prompt_status
|
||||||
prompt_context
|
prompt_context
|
||||||
prompt_dir
|
prompt_dir
|
||||||
prompt_git
|
prompt_git
|
||||||
segment_stop
|
prompt_end
|
||||||
}
|
}
|
||||||
|
|
||||||
PROMPT='%{%f%b%k%}
|
PROMPT='%{%f%b%k%}$(build_prompt) '
|
||||||
$(build_prompt) '
|
|
||||||
|
|
Loading…
Reference in a new issue