Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
bf415751
Commit
bf415751
authored
Sep 17, 2012
by
Isaac Wolkerstorfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored theme
parent
b11e2891
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
17 deletions
+75
-17
agnoster.zsh-theme
themes/agnoster.zsh-theme
+75
-17
No files found.
themes/agnoster.zsh-theme
View file @
bf415751
#
Theme by [agnoster](https://github.com/agnoster)
#
See https://gist.github.com/3712874
#
## Segment drawing
#
A few utility functions to make it easy and re-usable to draw segmented prompts
ZSH_THEME_GIT_PROMPT_DIRTY='±'
CURRENT_BG=''
SEGMENT_SEPARATOR='⮀'
function segment_start() {
local bg=$1
local fg=$2
if [[ -n $CURRENT_BG && $bg != $CURRENT_BG ]]; then
echo -n " %{%K{$bg}%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%K{$bg}%}"
fi
[[ -n $fg ]] && fg="%F{$fg}" || fg="%f"
echo -n "%{$fg%} "
CURRENT_BG=$bg
}
function _git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
echo "${ref/refs\/heads\//⭠ }$(parse_git_dirty)"
function segment_stop() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%k%}"
fi
echo -n "%{%f%}"
CURRENT_BG=''
}
function _git_info() {
### Prompt components
# Each component will draw itself, and hide itself if no information needs to be shown
function prompt_context() {
local user=`whoami`
if [[ ("$user" != "$DEFAULT_USER") || (-n "$SSH_CLIENT") ]]; then
segment_start black
#echo -n "%{%F{yellow}%}$user%{%F{gray}%}@%{%F{green}%}%m%{%f%}"
echo -n "%(!.%{%F{yellow}%}.)$user@%m"
fi
}
function prompt_git() {
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
local BG_COLOR=green
if [[ -n $(parse_git_dirty) ]]; then
BG_COLOR=yellow
ZSH_THEME_GIT_PROMPT_DIRTY='±'
local 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)"
if [[ -n $dirty ]]; then
segment_start yellow black
else
segment_start green black
fi
echo "%{%K{$BG_COLOR}%}⮀%{%F{black}%} $(_git_prompt_info) %{%F{$BG_COLOR}%K{blue}%}⮀"
else
echo "%{%K{blue}%}⮀"
echo -n "${ref/refs\/heads\//⭠ }$dirty"
fi
}
function prompt_dir() {
segment_start blue white
echo -n '%~'
}
function prompt_status() {
local symbols
symbols=()
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
jobs=$(jobs -l | wc -l)
[[ $jobs -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
if [[ -n "$symbols" ]]; then
segment_start black white
echo -n "${symbols}"
fi
}
PROMPT_HOST='%{%b%F{gray}%K{black}%} %(?.%{%F{green}%}✔.%{%F{red}%}✘)%{%F{gray}%} %m %{%F{black}%}'
PROMPT_DIR='%{%F{white}%} %1~ '
PROMPT_SU='%(!.%{%k%F{blue}%K{black}%}⮀%{%F{yellow}%} ⚡ %{%k%F{black}%}.%{%k%F{blue}%})⮀%{%f%k%b%}'
## Main prompt
function build_prompt() {
RETVAL=$?
prompt_status
prompt_context
prompt_dir
prompt_git
segment_stop
}
PROMPT='%{%f%b%k%}
$
PROMPT_HOST$(_git_info)$PROMPT_DIR$PROMPT_SU
'
$
(build_prompt)
'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment