Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 87 lines (76 sloc) 2.008 kB
bf41575 @agnoster Refactored theme
agnoster authored
1 ### Segment drawing
2 # A few utility functions to make it easy and re-usable to draw segmented prompts
b11e289 @agnoster Add agnoster.zsh-theme
agnoster authored
3
bf41575 @agnoster Refactored theme
agnoster authored
4 CURRENT_BG=''
5 SEGMENT_SEPARATOR='⮀'
6 function segment_start() {
7 local bg=$1
8 local fg=$2
9 if [[ -n $CURRENT_BG && $bg != $CURRENT_BG ]]; then
10 echo -n " %{%K{$bg}%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
11 else
12 echo -n "%{%K{$bg}%}"
13 fi
14 [[ -n $fg ]] && fg="%F{$fg}" || fg="%f"
15 echo -n "%{$fg%} "
16 CURRENT_BG=$bg
17 }
b11e289 @agnoster Add agnoster.zsh-theme
agnoster authored
18
bf41575 @agnoster Refactored theme
agnoster authored
19 function segment_stop() {
20 if [[ -n $CURRENT_BG ]]; then
21 echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
22 else
23 echo -n "%{%k%}"
24 fi
25 echo -n "%{%f%}"
26 CURRENT_BG=''
b11e289 @agnoster Add agnoster.zsh-theme
agnoster authored
27 }
28
bf41575 @agnoster Refactored theme
agnoster authored
29 ### Prompt components
30 # Each component will draw itself, and hide itself if no information needs to be shown
31
32 function prompt_context() {
33 local user=`whoami`
34
35 if [[ ("$user" != "$DEFAULT_USER") || (-n "$SSH_CLIENT") ]]; then
36 segment_start black
37 #echo -n "%{%F{yellow}%}$user%{%F{gray}%}@%{%F{green}%}%m%{%f%}"
38 echo -n "%(!.%{%F{yellow}%}.)$user@%m"
39 fi
40 }
41
42 function prompt_git() {
b11e289 @agnoster Add agnoster.zsh-theme
agnoster authored
43 if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
bf41575 @agnoster Refactored theme
agnoster authored
44 ZSH_THEME_GIT_PROMPT_DIRTY='±'
45 local dirty=$(parse_git_dirty)
46 local ref
47 ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
48 if [[ -n $dirty ]]; then
49 segment_start yellow black
50 else
51 segment_start green black
b11e289 @agnoster Add agnoster.zsh-theme
agnoster authored
52 fi
bf41575 @agnoster Refactored theme
agnoster authored
53 echo -n "${ref/refs\/heads\//⭠ }$dirty"
54 fi
55 }
56
57 function prompt_dir() {
58 segment_start blue white
59 echo -n '%~'
60 }
61
62 function prompt_status() {
63 local symbols
64 symbols=()
65 [[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
66 [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
67 jobs=$(jobs -l | wc -l)
68 [[ $jobs -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
69 if [[ -n "$symbols" ]]; then
70 segment_start black white
71 echo -n "${symbols}"
b11e289 @agnoster Add agnoster.zsh-theme
agnoster authored
72 fi
73 }
74
bf41575 @agnoster Refactored theme
agnoster authored
75 ## Main prompt
76 function build_prompt() {
77 RETVAL=$?
78 prompt_status
79 prompt_context
80 prompt_dir
81 prompt_git
82 segment_stop
83 }
b11e289 @agnoster Add agnoster.zsh-theme
agnoster authored
84
85 PROMPT='%{%f%b%k%}
bf41575 @agnoster Refactored theme
agnoster authored
86 $(build_prompt) '
Something went wrong with that request. Please try again.