2019-07-24 14:34:26 +02:00
if ! autoload -Uz is-at-least || ! is-at-least 5.1; then
2019-06-01 17:54:53 +02:00
( ) {
>& 2 echo -E " You are using ZSH version $ZSH_VERSION . The minimum required version for Powerlevel10k is 5.1. "
>& 2 echo -E "Type 'echo \$ZSH_VERSION' to see your current zsh version."
local def = ${ SHELL : c : A }
local cur = ${ ${ ZSH_ARGZERO #- } : c : A }
2019-07-29 14:18:57 +02:00
local cur_v = " $( $cur -c 'echo -E $ZSH_VERSION' 2>/dev/null) "
2019-06-01 17:54:53 +02:00
if [ [ $cur_v = = $ZSH_VERSION && $cur != $def ] ] ; then
>& 2 echo -E " The shell you are currently running is likely $cur . "
fi
local other = ${ ${ :- zsh } : c }
2019-07-24 14:34:26 +02:00
if [ [ -n $other ] ] && $other -c 'autoload -Uz is-at-least && is-at-least 5.1' & >/dev/null; then
2019-07-29 14:18:57 +02:00
local other_v = " $( $other -c 'echo -E $ZSH_VERSION' 2>/dev/null) "
2019-06-01 17:54:53 +02:00
if [ [ -n $other_v && $other_v != $ZSH_VERSION ] ] ; then
>& 2 echo -E " You have $other with version $other_v but this is not what you are using. "
if [ [ -n $def && $def != ${ other : A } ] ] ; then
>& 2 echo -E "To change your user shell, type the following command:"
>& 2 echo -E ""
2019-07-29 14:18:57 +02:00
if [ [ " $( grep -F $other /etc/shells 2>/dev/null) " != $other ] ] ; then
2019-06-01 17:54:53 +02:00
>& 2 echo -E " echo ${ (q-)other } | sudo tee -a /etc/shells "
fi
>& 2 echo -E " chsh -s ${ (q-)other } "
fi
fi
fi
}
return 1
fi
2019-07-28 12:19:51 +02:00
source " ${ __p9k_root_dir } /internal/icons.zsh "
2019-07-28 18:54:02 +02:00
source " ${ __p9k_root_dir } /internal/configure.zsh "
2019-07-24 15:06:36 +02:00
2019-07-24 15:01:26 +02:00
# For compatibility with Powerlevel9k. It's not recommended to use mnemonic color
# names in the configuration except for colors 0-7 as these are standard.
typeset -grA __p9k_colors = (
black 000 red 001 green 002 yellow 003
blue 004 magenta 005 cyan 006 white 007
grey 008 maroon 009 lime 010 olive 011
navy 012 fuchsia 013 aqua 014 teal 014
silver 015 grey0 016 navyblue 017 darkblue 018
blue3 020 blue1 021 darkgreen 022 deepskyblue4 025
dodgerblue3 026 dodgerblue2 027 green4 028 springgreen4 029
turquoise4 030 deepskyblue3 032 dodgerblue1 033 darkcyan 036
lightseagreen 037 deepskyblue2 038 deepskyblue1 039 green3 040
springgreen3 041 cyan3 043 darkturquoise 044 turquoise2 045
green1 046 springgreen2 047 springgreen1 048 mediumspringgreen 049
cyan2 050 cyan1 051 purple4 055 purple3 056
blueviolet 057 grey37 059 mediumpurple4 060 slateblue3 062
royalblue1 063 chartreuse4 064 paleturquoise4 066 steelblue 067
steelblue3 068 cornflowerblue 069 darkseagreen4 071 cadetblue 073
skyblue3 074 chartreuse3 076 seagreen3 078 aquamarine3 079
mediumturquoise 080 steelblue1 081 seagreen2 083 seagreen1 085
darkslategray2 087 darkred 088 darkmagenta 091 orange4 094
lightpink4 095 plum4 096 mediumpurple3 098 slateblue1 099
wheat4 101 grey53 102 lightslategrey 103 mediumpurple 104
lightslateblue 105 yellow4 106 darkseagreen 108 lightskyblue3 110
skyblue2 111 chartreuse2 112 palegreen3 114 darkslategray3 116
skyblue1 117 chartreuse1 118 lightgreen 120 aquamarine1 122
darkslategray1 123 deeppink4 125 mediumvioletred 126 darkviolet 128
purple 129 mediumorchid3 133 mediumorchid 134 darkgoldenrod 136
rosybrown 138 grey63 139 mediumpurple2 140 mediumpurple1 141
darkkhaki 143 navajowhite3 144 grey69 145 lightsteelblue3 146
lightsteelblue 147 darkolivegreen3 149 darkseagreen3 150 lightcyan3 152
lightskyblue1 153 greenyellow 154 darkolivegreen2 155 palegreen1 156
darkseagreen2 157 paleturquoise1 159 red3 160 deeppink3 162
magenta3 164 darkorange3 166 indianred 167 hotpink3 168
hotpink2 169 orchid 170 orange3 172 lightsalmon3 173
lightpink3 174 pink3 175 plum3 176 violet 177
gold3 178 lightgoldenrod3 179 tan 180 mistyrose3 181
thistle3 182 plum2 183 yellow3 184 khaki3 185
lightyellow3 187 grey84 188 lightsteelblue1 189 yellow2 190
darkolivegreen1 192 darkseagreen1 193 honeydew2 194 lightcyan1 195
red1 196 deeppink2 197 deeppink1 199 magenta2 200
magenta1 201 orangered1 202 indianred1 204 hotpink 206
mediumorchid1 207 darkorange 208 salmon1 209 lightcoral 210
palevioletred1 211 orchid2 212 orchid1 213 orange1 214
sandybrown 215 lightsalmon1 216 lightpink1 217 pink1 218
plum1 219 gold1 220 lightgoldenrod2 222 navajowhite1 223
mistyrose1 224 thistle1 225 yellow1 226 lightgoldenrod1 227
khaki1 228 wheat1 229 cornsilk1 230 grey100 231
grey3 232 grey7 233 grey11 234 grey15 235
grey19 236 grey23 237 grey27 238 grey30 239
grey35 240 grey39 241 grey42 242 grey46 243
grey50 244 grey54 245 grey58 246 grey62 247
grey66 248 grey70 249 grey74 250 grey78 251
grey82 252 grey85 253 grey89 254 grey93 255)
# For compatibility with Powerlevel9k.
#
# Type `getColorCode background` or `getColorCode foreground` to see the list of predefined colors.
function getColorCode( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-07-24 15:01:26 +02:00
if ( ( ARGC = = 1 ) ) ; then
case $1 in
foreground)
local k
for k in " ${ (k@)__p9k_colors } " ; do
local v = ${ __p9k_colors [ $k ] }
2019-08-05 10:37:04 +02:00
print -rP -- " %F{ $v } $v - $k %f "
2019-07-24 15:01:26 +02:00
done
return
; ;
background)
local k
for k in " ${ (k@)__p9k_colors } " ; do
local v = ${ __p9k_colors [ $k ] }
2019-08-05 10:37:04 +02:00
print -rP -- " %K{ $v } $v - $k %k "
2019-07-24 15:01:26 +02:00
done
return
; ;
esac
fi
echo "Usage: getColorCode background|foreground" >& 2
return 1
}
# _p9k_declare <type> <uppercase-name> [default]...
function _p9k_declare( ) {
local -i set = $+parameters[ $2 ]
( ( ARGC > 2 || set ) ) || return 0
case $1 in
-b)
if ( ( set ) ) ; then
[ [ ${ (P)2 } = = true ] ] && typeset -gi _$2 = 1 || typeset -gi _$2 = 0
else
typeset -gi _$2 = $3
fi
; ;
-a)
local -a v = ( ${ (P)2 } )
if ( ( set ) ) ; then
eval " typeset -ga _ ${ (q)2 } =( ${ (@qq)v } ) " ;
else
if [ [ $3 != '--' ] ] ; then
echo "internal error in _p9k_declare " " ${ (qqq)@ } " >& 2
fi
eval " typeset -ga _ ${ (q)2 } =( ${ (@qq)*[4,-1] } ) "
fi
; ;
-i)
( ( set ) ) && typeset -gi _$2 = $2 || typeset -gi _$2 = $3
; ;
-F)
( ( set ) ) && typeset -gF _$2 = $2 || typeset -gF _$2 = $3
; ;
-s)
( ( set ) ) && typeset -g _$2 = ${ (P)2 } || typeset -g _$2 = $3
; ;
-e)
2019-08-20 14:56:43 +02:00
[ [ -z $_p9k_locale ] ] || local LC_ALL = $_p9k_locale
2019-07-24 15:01:26 +02:00
if ( ( set ) ) ; then
local v = ${ (P)2 }
typeset -g _$2 = ${ (g : : )v }
else
typeset -g _$2 = ${ (g : : )3 }
fi
; ;
*)
echo "internal error in _p9k_declare " " ${ (qqq)@ } " >& 2
esac
}
# If we execute `print -P $1`, how many characters will be printed on the last line?
# Assumes that `%{%}` and `%G` don't lie.
#
# _p9k_prompt_length '' => 0
# _p9k_prompt_length 'abc' => 3
# _p9k_prompt_length $'abc\nxy' => 2
# _p9k_prompt_length $'\t' => 8
# _p9k_prompt_length '%F{red}abc' => 3
# _p9k_prompt_length $'%{a\b%Gb%}' => 1
function _p9k_prompt_length( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-07-24 15:01:26 +02:00
local COLUMNS = 1024
local -i x y = $# 1 m
if ( ( y ) ) ; then
while ( ( ${ ${ (%) :- $1 % $y (l.1.0) } [-1] } ) ) ; do
x = y
( ( y *= 2 ) ) ;
done
local xy
while ( ( y > x + 1 ) ) ; do
m = $(( x + ( y - x) / 2 ))
typeset ${ ${ (%) :- $1 % $m (l.x.y) } [-1] } = $m
done
fi
_p9k_ret = $x
}
typeset -gr __p9k_byte_suffix = ( 'B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y' )
# 42 => 42B
# 1536 => 1.5K
function _p9k_human_readable_bytes( ) {
typeset -F 2 n = $1
local suf
for suf in $__p9k_byte_suffix ; do
( ( n < 100 ) ) && break
( ( n /= 1024 ) )
done
_p9k_ret = $n $suf
}
# Determine if the passed segment is used in the prompt
#
# Pass the name of the segment to this function to test for its presence in
# either the LEFT or RIGHT prompt arrays.
# * $1: The segment to be tested.
2019-07-24 21:07:28 +02:00
_p9k_segment_in_use( ) {
2019-07-24 15:01:26 +02:00
( ( $_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS [ ( I) $1 ( | _joined) ] ||
$_POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS [ ( I) $1 ( | _joined) ] ) )
}
function _p9k_parse_ip( ) {
local desiredInterface = ${ 1 :- '^[^ ]+' }
if [ [ $_p9k_os = = OSX ] ] ; then
[ [ -x /sbin/ifconfig ] ] || return
local rawInterfaces && rawInterfaces = " $( /sbin/ifconfig -l 2>/dev/null) " || return
local -a interfaces = ( ${ (A)=rawInterfaces } )
local pattern = " ${ desiredInterface } [^ ]? "
local -a relevantInterfaces
for rawInterface in $interfaces ; do
[ [ " $rawInterface " = ~ $pattern ] ] && relevantInterfaces += $MATCH
done
local newline = $'\n'
local interfaceName interface
for interfaceName in $relevantInterfaces ; do
interface = " $( /sbin/ifconfig $interfaceName 2>/dev/null) " || continue
[ [ " ${ interface } " = ~ "lo[0-9]*" ] ] && continue
if [ [ " ${ interface // ${ newline } / } " = ~ "<([^>]*)>(.*)inet[ ]+([^ ]*)" ] ] ; then
local ipFound = " ${ match [3] } "
local -a interfaceStates = ( ${ (s : , : )match[1] } )
if ( ( ${ interfaceStates [(I)UP] } ) ) ; then
_p9k_ret = $ipFound
return
fi
fi
done
else
[ [ -x /sbin/ip ] ] || return
local -a interfaces = ( " ${ (f) $( /sbin/ip -brief -4 a show 2>/dev/null) } " )
local pattern = " ^ ${ desiredInterface } [[:space:]]+UP[[:space:]]+([^/ ]+) "
local interface
for interface in " ${ (@)interfaces } " ; do
if [ [ " $interface " = ~ $pattern ] ] ; then
_p9k_ret = $match [ 1]
return
fi
done
fi
return 1
}
2019-06-01 17:54:53 +02:00
# Caching allows storing array-to-array associations. It should be used like this:
#
# if ! _p9k_cache_get "$key1" "$key2"; then
# # Compute val1 and val2 and then store them in the cache.
# _p9k_cache_set "$val1" "$val2"
# fi
2019-07-24 14:34:26 +02:00
# # Here ${_p9k_cache_val[1]} and ${_p9k_cache_val[2]} are $val1 and $val2 respectively.
2019-06-01 17:54:53 +02:00
#
# Limitations:
#
# * Calling _p9k_cache_set without arguments clears the cache entry. Subsequent calls to
# _p9k_cache_get for the same key will return an error.
# * There must be no intervening _p9k_cache_get calls between the associated _p9k_cache_get
# and _p9k_cache_set.
_p9k_cache_set( ) {
# Uncomment to see cache misses.
2019-07-24 14:34:26 +02:00
# echo "caching: ${(@0q)_p9k_cache_key} => (${(q)@})" >&2
_p9k_cache[ $_p9k_cache_key ] = " ${ (pj : \0 : )* } 0 "
_p9k_cache_val = ( " $@ " )
2019-06-01 17:54:53 +02:00
}
_p9k_cache_get( ) {
2019-07-24 14:34:26 +02:00
_p9k_cache_key = " ${ (pj : \0 : )* } "
local v = $_p9k_cache [ $_p9k_cache_key ]
[ [ -n $v ] ] && _p9k_cache_val = ( " ${ (@0) ${ v [1,-2] } } " )
2019-06-01 17:54:53 +02:00
}
2019-07-09 12:40:31 +02:00
# _p9k_param prompt_foo_BAR BACKGROUND red
_p9k_param( ) {
local key = " _p9k_param ${ (pj : \0 : )* } "
2019-07-24 14:34:26 +02:00
_p9k_ret = $_p9k_cache [ $key ]
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
_p9k_ret[ -1,-1] = ''
2019-07-09 12:40:31 +02:00
else
if [ [ $1 = = ( #b)prompt_([a-z0-9_]#)(*) ]]; then
local var = POWERLEVEL9K_${ (U)match[1] } $match [ 2] _$2
if ( ( $+parameters[ $var ] ) ) ; then
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (P)var }
2019-07-09 12:40:31 +02:00
else
var = POWERLEVEL9K_${ (U)match[1]%_ } _$2
if ( ( $+parameters[ $var ] ) ) ; then
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (P)var }
2019-07-09 12:40:31 +02:00
else
var = POWERLEVEL9K_$2
if ( ( $+parameters[ $var ] ) ) ; then
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (P)var }
2019-07-09 12:40:31 +02:00
else
2019-07-23 15:47:25 +02:00
_p9k_ret = $3
2019-07-09 12:40:31 +02:00
fi
fi
fi
else
local var = POWERLEVEL9K_$2
if ( ( $+parameters[ $var ] ) ) ; then
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (P)var }
2019-07-09 12:40:31 +02:00
else
2019-07-23 15:47:25 +02:00
_p9k_ret = $3
2019-07-09 12:40:31 +02:00
fi
fi
2019-07-24 14:34:26 +02:00
_p9k_cache[ $key ] = ${ _p9k_ret } .
2019-07-09 12:40:31 +02:00
fi
}
2019-07-01 20:20:59 +02:00
2019-07-09 14:42:13 +02:00
# _p9k_get_icon prompt_foo_BAR BAZ_ICON quix
2019-06-01 17:54:53 +02:00
_p9k_get_icon( ) {
2019-07-09 12:40:31 +02:00
local key = " _p9k_param ${ (pj : \0 : )* } "
2019-07-24 14:34:26 +02:00
_p9k_ret = $_p9k_cache [ $key ]
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
_p9k_ret[ -1,-1] = ''
2019-07-01 20:20:59 +02:00
else
2019-07-09 12:40:31 +02:00
if [ [ $2 = = $'\1' * ] ] ; then
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ 2 [2,-1] }
2019-07-01 20:20:59 +02:00
else
2019-07-09 14:42:13 +02:00
_p9k_param " $@ " ${ icons [ $2 ]- $'\1' $3 }
2019-07-23 15:47:25 +02:00
if [ [ $_p9k_ret = = $'\1' * ] ] ; then
_p9k_ret = ${ _p9k_ret [2,-1] }
2019-07-09 14:42:13 +02:00
else
2019-08-20 14:56:43 +02:00
[ [ -z $_p9k_locale ] ] || local LC_ALL = $_p9k_locale
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (g : : )_p9k_ret }
[ [ $_p9k_ret != $'\b' ? ] ] || _p9k_ret = " %{ $_p9k_ret %} " # penance for past sins
2019-07-09 14:42:13 +02:00
fi
2019-07-01 20:20:59 +02:00
fi
2019-07-24 14:34:26 +02:00
_p9k_cache[ $key ] = ${ _p9k_ret } .
2019-07-01 20:20:59 +02:00
fi
2019-06-01 17:54:53 +02:00
}
_p9k_translate_color( ) {
2019-07-09 12:40:31 +02:00
if [ [ $1 = = <-> ] ] ; then # decimal color code: 255
2019-07-23 15:47:25 +02:00
_p9k_ret = $1
2019-07-09 12:40:31 +02:00
elif [ [ $1 = = '#' [ [ :xdigit:] ] ## ]]; then # hexademical color code: #ffffff
2019-07-23 15:47:25 +02:00
_p9k_ret = $1
2019-07-09 12:40:31 +02:00
else # named color: red
2019-06-01 17:54:53 +02:00
# Strip prifixes if there are any.
2019-07-23 15:47:25 +02:00
_p9k_ret = $__p9k_colors [ ${ ${ ${ 1 #bg- } #fg- } #br } ]
2019-06-01 17:54:53 +02:00
fi
}
2019-07-09 12:40:31 +02:00
# _p9k_param prompt_foo_BAR BACKGROUND red
2019-06-01 17:54:53 +02:00
_p9k_color( ) {
2019-07-09 12:40:31 +02:00
local key = " _p9k_color ${ (pj : \0 : )* } "
2019-07-24 14:34:26 +02:00
_p9k_ret = $_p9k_cache [ $key ]
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
_p9k_ret[ -1,-1] = ''
2019-07-09 12:40:31 +02:00
else
_p9k_param " $@ "
2019-07-23 15:47:25 +02:00
_p9k_translate_color $_p9k_ret
2019-07-24 14:34:26 +02:00
_p9k_cache[ $key ] = ${ _p9k_ret } .
2019-07-09 12:40:31 +02:00
fi
2019-06-01 17:54:53 +02:00
}
2019-07-09 13:32:45 +02:00
# _p9k_vcs_color CLEAN REMOTE_BRANCH
_p9k_vcs_style( ) {
local key = " _p9k_vcs_color ${ (pj : \0 : )* } "
2019-07-24 14:34:26 +02:00
_p9k_ret = $_p9k_cache [ $key ]
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
_p9k_ret[ -1,-1] = ''
2019-07-09 13:32:45 +02:00
else
local style = %b # TODO: support bold
2019-07-24 14:34:26 +02:00
_p9k_color prompt_vcs_$1 BACKGROUND " ${ __p9k_vcs_states [ $1 ] } "
2019-07-23 15:47:25 +02:00
_p9k_background $_p9k_ret
style += $_p9k_ret
2019-07-09 13:32:45 +02:00
local var = POWERLEVEL9K_VCS_${ 1 } _${ 2 } FORMAT_FOREGROUND
if ( ( $+parameters[ $var ] ) ) ; then
2019-08-01 15:09:39 +02:00
_p9k_translate_color " ${ (P)var } "
2019-07-09 13:32:45 +02:00
else
var = POWERLEVEL9K_VCS_${ 2 } FORMAT_FOREGROUND
if ( ( $+parameters[ $var ] ) ) ; then
2019-08-01 15:09:39 +02:00
_p9k_translate_color " ${ (P)var } "
2019-07-09 13:32:45 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_color prompt_vcs_$1 FOREGROUND " $_p9k_color1 "
2019-07-09 13:32:45 +02:00
fi
fi
2019-08-01 15:09:39 +02:00
2019-07-23 15:47:25 +02:00
_p9k_foreground $_p9k_ret
_p9k_ret = $style $_p9k_ret
2019-07-24 14:34:26 +02:00
_p9k_cache[ $key ] = ${ _p9k_ret } .
2019-07-09 13:32:45 +02:00
fi
}
2019-06-01 17:54:53 +02:00
_p9k_background( ) {
2019-07-23 15:47:25 +02:00
[ [ -n $1 ] ] && _p9k_ret = " %K{ $1 } " || _p9k_ret = "%k"
2019-06-01 17:54:53 +02:00
}
_p9k_foreground( ) {
2019-07-24 23:05:41 +02:00
case $1 in
'' ) _p9k_ret = "%f" ; ;
'#' *) _p9k_ret = " %F{ $1 } " ; ;
*) _p9k_ret = " % ${ 1 } F " ; ;
esac
2019-06-01 17:54:53 +02:00
}
2019-07-24 23:05:41 +02:00
_p9k_escape_style( ) {
[ [ $1 = = *'}' * ] ] && _p9k_ret = '${:-"' $1 '"}' || _p9k_ret = $1
2019-06-01 17:54:53 +02:00
}
2019-07-08 19:33:42 +02:00
_p9k_escape( ) {
2019-07-23 15:47:25 +02:00
[ [ $1 = = *[ "~!#\$^&*()\\\"'<>?{}[]" ] * ] ] && _p9k_ret = " \${(Q)\${:- ${ (qqq) ${ (q)1 } } }} " || _p9k_ret = $1
2019-07-08 19:33:42 +02:00
}
2019-07-09 16:00:05 +02:00
# * $1: Name of the function that was originally invoked.
# Necessary, to make the dynamic color-overwrite mechanism work.
2019-07-24 21:07:28 +02:00
# * $2: Background color.
# * $3: Foreground color.
# * $4: An identifying icon.
# * $5: 1 to to perform parameter expansion and process substitution.
# * $6: If not empty but becomes empty after parameter expansion and process substitution,
2019-07-09 16:00:05 +02:00
# the segment isn't rendered.
2019-07-24 21:07:28 +02:00
# * $7: Content.
_p9k_left_prompt_segment( ) {
if ! _p9k_cache_get " $0 " " $1 " " $2 " " $3 " " $4 " " $_p9k_segment_index " ; then
_p9k_color $1 BACKGROUND $2
2019-07-23 15:47:25 +02:00
local bg_color = $_p9k_ret
2019-06-01 17:54:53 +02:00
_p9k_background $bg_color
2019-07-23 15:47:25 +02:00
local bg = $_p9k_ret
2019-06-01 17:54:53 +02:00
2019-07-24 21:07:28 +02:00
_p9k_color $1 FOREGROUND $3
2019-07-23 15:47:25 +02:00
local fg_color = $_p9k_ret
2019-06-01 17:54:53 +02:00
_p9k_foreground $fg_color
2019-07-23 15:47:25 +02:00
local fg = $_p9k_ret
2019-06-01 17:54:53 +02:00
2019-07-09 14:42:13 +02:00
_p9k_get_icon $1 LEFT_SEGMENT_SEPARATOR
2019-07-23 15:47:25 +02:00
local sep = $_p9k_ret
_p9k_escape $_p9k_ret
local sep_ = $_p9k_ret
2019-07-09 14:42:13 +02:00
2019-07-09 12:40:31 +02:00
_p9k_get_icon $1 LEFT_SUBSEGMENT_SEPARATOR
2019-07-23 15:47:25 +02:00
_p9k_escape $_p9k_ret
local subsep_ = $_p9k_ret
2019-06-01 17:54:53 +02:00
2019-07-09 10:09:50 +02:00
local icon_
2019-07-24 21:07:28 +02:00
if [ [ -n $4 ] ] ; then
_p9k_get_icon $1 $4
2019-07-23 15:47:25 +02:00
_p9k_escape $_p9k_ret
icon_ = $_p9k_ret
2019-07-09 10:09:50 +02:00
fi
2019-07-09 14:42:13 +02:00
_p9k_get_icon $1 LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL
2019-07-23 15:47:25 +02:00
local start_sep = $_p9k_ret
2019-07-11 18:45:53 +02:00
[ [ -n $start_sep ] ] && start_sep = " %b%k%F{ $bg_color } $start_sep "
2019-07-09 14:42:13 +02:00
_p9k_get_icon $1 LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL $sep
2019-07-23 15:47:25 +02:00
_p9k_escape $_p9k_ret
local end_sep_ = $_p9k_ret
2019-07-04 17:40:54 +02:00
2019-07-08 19:33:42 +02:00
local style = %b$bg $fg
2019-07-24 23:05:41 +02:00
local style_ = ${ style // \} / \\ \} }
2019-07-08 19:33:42 +02:00
2019-07-23 15:47:25 +02:00
_p9k_get_icon $1 WHITESPACE_BETWEEN_LEFT_SEGMENTS ' '
local space = $_p9k_ret
2019-07-09 14:42:13 +02:00
_p9k_get_icon $1 LEFT_LEFT_WHITESPACE $space
2019-07-23 15:47:25 +02:00
local left_space = $_p9k_ret
2019-07-09 14:42:13 +02:00
[ [ $left_space = = *%* ] ] && left_space += $style
_p9k_get_icon $1 LEFT_RIGHT_WHITESPACE $space
2019-07-23 15:47:25 +02:00
_p9k_escape $_p9k_ret
local right_space_ = $_p9k_ret
2019-07-09 14:42:13 +02:00
[ [ $right_space_ = = *%* ] ] && right_space_ += $style_
2019-07-09 10:09:50 +02:00
2019-07-24 14:34:26 +02:00
local s = '<_p9k_s>' ss = '<_p9k_ss>'
2019-06-01 17:54:53 +02:00
# Segment separator logic:
#
2019-07-24 14:34:26 +02:00
# if [[ $_p9k_bg == NONE ]]; then
2019-06-01 17:54:53 +02:00
# 1
# elif (( joined )); then
# 2
2019-07-24 14:34:26 +02:00
# elif [[ $bg_color == (${_p9k_bg}|${_p9k_bg:-0}) ]]; then
2019-06-01 17:54:53 +02:00
# 3
# else
# 4
# fi
2019-07-24 14:34:26 +02:00
local t = $# _p9k_t
_p9k_t += $start_sep $style $left_space # 1
_p9k_t += $style # 2
2019-07-11 21:11:38 +02:00
if [ [ -n $fg_color && $fg_color = = $bg_color ] ] ; then
2019-07-24 14:34:26 +02:00
if [ [ $fg_color = = $_p9k_color1 ] ] ; then
_p9k_foreground $_p9k_color2
2019-07-11 21:11:38 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_foreground $_p9k_color1
2019-07-11 21:11:38 +02:00
fi
2019-07-24 14:34:26 +02:00
_p9k_t += %b$bg $_p9k_ret $ss $style $left_space # 3
2019-06-01 17:54:53 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_t += %b$bg $fg $ss $style $left_space # 3
2019-06-01 17:54:53 +02:00
fi
2019-07-24 14:34:26 +02:00
_p9k_t += %b$bg $s $style $left_space # 4
2019-06-01 17:54:53 +02:00
2019-07-24 21:07:28 +02:00
local join = " _p9k_i>= $_p9k_left_join [ $_p9k_segment_index ] "
2019-07-10 20:06:19 +02:00
_p9k_param $1 SELF_JOINED false
2019-07-24 21:07:28 +02:00
[ [ $_p9k_ret = = false ] ] && join += " &&_p9k_i< $_p9k_segment_index "
2019-07-10 20:06:19 +02:00
2019-07-08 19:33:42 +02:00
local p =
2019-07-24 14:34:26 +02:00
p += "\${_p9k_n::=}"
p += " \${\${\${_p9k_bg:-0}:#NONE}:-\${_p9k_n::= $(( t+1)) }} " # 1
p += " \${_p9k_n:=\${\${\$(( $join )):#0}:+ $(( t+2)) }} " # 2
p += " \${_p9k_n:=\${\${(M)\${:-x $bg_color }:#x(\$_p9k_bg|\${_p9k_bg:-0})}:+ $(( t+3)) }} " # 3
p += " \${_p9k_n:= $(( t+4)) } " # 4
2019-07-09 10:09:50 +02:00
2019-07-09 12:40:31 +02:00
_p9k_param $1 VISUAL_IDENTIFIER_EXPANSION '${P9K_VISUAL_IDENTIFIER}'
2019-07-23 15:47:25 +02:00
local icon_exp_ = ${ _p9k_ret : + \" $_p9k_ret \" }
2019-07-09 12:40:31 +02:00
_p9k_param $1 CONTENT_EXPANSION '${P9K_CONTENT}'
2019-07-23 15:47:25 +02:00
local content_exp_ = ${ _p9k_ret : + \" $_p9k_ret \" }
2019-07-09 10:09:50 +02:00
2019-07-23 09:16:47 +02:00
if [ [ ( $icon_exp_ != '"${P9K_VISUAL_IDENTIFIER}"' && $icon_exp_ = = *'$' * ) ||
( $content_exp_ != '"${P9K_CONTENT}"' && $content_exp_ = = *'$' * ) ] ] ; then
2019-07-17 09:52:37 +02:00
p += " \${P9K_VISUAL_IDENTIFIER::= $icon_ } "
fi
local -i has_icon = -1 # maybe
2019-07-23 09:16:47 +02:00
if [ [ $icon_exp_ != '"${P9K_VISUAL_IDENTIFIER}"' && $icon_exp_ = = *'$' * ] ] ; then
2019-07-24 14:34:26 +02:00
p += '${_p9k_v::=' $icon_exp_ $style_ '}'
2019-07-09 10:09:50 +02:00
else
2019-07-23 15:47:25 +02:00
[ [ $icon_exp_ = = '"${P9K_VISUAL_IDENTIFIER}"' ] ] && _p9k_ret = $icon_ || _p9k_ret = $icon_exp_
if [ [ -n $_p9k_ret ] ] ; then
2019-07-24 14:34:26 +02:00
p += " \${_p9k_v::= $_p9k_ret "
2019-07-23 15:47:25 +02:00
[ [ $_p9k_ret = = *%* ] ] && p += $style_
2019-07-17 09:52:37 +02:00
p += "}"
has_icon = 1 # definitely yes
else
has_icon = 0 # definitely no
fi
2019-07-08 19:33:42 +02:00
fi
2019-07-24 14:34:26 +02:00
p += " \${_p9k_c::= $content_exp_ } "
2019-07-17 09:52:37 +02:00
if ( ( has_icon = = -1 ) ) ; then
2019-07-24 14:34:26 +02:00
p += '${_p9k_e::=${${(%):-$_p9k_c%1(l.1.0)}[-1]}${${(%):-$_p9k_v%1(l.1.0)}[-1]}}'
2019-07-17 09:52:37 +02:00
else
2019-07-24 14:34:26 +02:00
p += '${_p9k_e::=${${(%):-$_p9k_c%1(l.1.0)}[-1]}' $has_icon '}'
2019-07-17 09:52:37 +02:00
fi
2019-07-08 19:33:42 +02:00
p += '}+}'
2019-06-01 17:54:53 +02:00
2019-07-24 14:34:26 +02:00
p += '${${_p9k_e:#00}:+${${_p9k_t[$_p9k_n]/' $ss '/$_p9k_ss}/' $s '/$_p9k_s}'
2019-07-11 18:45:53 +02:00
2019-08-20 14:56:43 +02:00
[ [ -z $_p9k_locale ] ] || local LC_ALL = $_p9k_locale
2019-07-21 19:43:14 +02:00
_p9k_param $1 ICON_BEFORE_CONTENT ''
2019-07-23 15:47:25 +02:00
if [ [ $_p9k_ret != false ] ] ; then
2019-07-21 19:43:14 +02:00
_p9k_param $1 PREFIX ''
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (g : : )_p9k_ret }
_p9k_escape $_p9k_ret
p += $_p9k_ret
[ [ $_p9k_ret = = *%* ] ] && local -i need_style = 1 || local -i need_style = 0
2019-07-21 19:43:14 +02:00
if ( ( has_icon != 0 ) ) ; then
_p9k_color $1 VISUAL_IDENTIFIER_COLOR $fg_color
2019-07-23 15:47:25 +02:00
_p9k_foreground $_p9k_ret
2019-07-24 23:05:41 +02:00
_p9k_ret = %b$bg $_p9k_ret
_p9k_ret = ${ _p9k_ret // \} / \\ \} }
2019-07-23 15:47:25 +02:00
[ [ $_p9k_ret != $style_ || $need_style = = 1 ] ] && p += $_p9k_ret
2019-07-24 14:34:26 +02:00
p += '${_p9k_v}'
2019-07-21 19:43:14 +02:00
_p9k_get_icon $1 LEFT_MIDDLE_WHITESPACE ' '
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
_p9k_escape $_p9k_ret
[ [ _p9k_ret = = *%* ] ] && _p9k_ret += $style_
2019-07-24 14:34:26 +02:00
p += '${${(M)_p9k_e:#11}:+' $_p9k_ret '}'
2019-07-21 19:43:14 +02:00
fi
elif ( ( need_style ) ) ; then
p += $style_
fi
2019-07-08 19:33:42 +02:00
2019-07-24 14:34:26 +02:00
p += '${_p9k_c}' $style_
2019-07-21 19:43:14 +02:00
else
_p9k_param $1 PREFIX ''
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (g : : )_p9k_ret }
_p9k_escape $_p9k_ret
p += $_p9k_ret
[ [ $_p9k_ret = = *%* ] ] && p += $style_
2019-07-21 19:43:14 +02:00
2019-07-24 14:34:26 +02:00
p += '${_p9k_c}' $style_
2019-07-21 19:43:14 +02:00
if ( ( has_icon != 0 ) ) ; then
local -i need_style = 0
_p9k_get_icon $1 LEFT_MIDDLE_WHITESPACE ' '
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
_p9k_escape $_p9k_ret
[ [ $_p9k_ret = = *%* ] ] && need_style = 1
2019-07-24 14:34:26 +02:00
p += '${${(M)_p9k_e:#11}:+' $_p9k_ret '}'
2019-07-21 19:43:14 +02:00
fi
2019-07-17 09:52:37 +02:00
2019-07-21 19:43:14 +02:00
_p9k_color $1 VISUAL_IDENTIFIER_COLOR $fg_color
2019-07-23 15:47:25 +02:00
_p9k_foreground $_p9k_ret
2019-07-24 23:05:41 +02:00
_p9k_ret = %b$bg $_p9k_ret
_p9k_ret = ${ _p9k_ret // \} / \\ \} }
2019-07-23 15:47:25 +02:00
[ [ $_p9k_ret != $style_ || $need_style = = 1 ] ] && p += $_p9k_ret
2019-07-24 14:34:26 +02:00
p += '$_p9k_v'
2019-07-17 09:52:37 +02:00
fi
2019-07-09 12:40:31 +02:00
fi
2019-07-06 19:55:08 +02:00
2019-07-09 12:40:31 +02:00
_p9k_param $1 SUFFIX ''
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (g : : )_p9k_ret }
_p9k_escape $_p9k_ret
p += $_p9k_ret
[ [ $_p9k_ret = = *%* && -n $right_space_ ] ] && p += $style_
2019-07-09 14:42:13 +02:00
p += $right_space_
2019-07-19 14:59:44 +02:00
p += '${${:-'
2019-07-24 14:34:26 +02:00
p += " \${_p9k_s::=%F{ $bg_color \} $sep_ }\${_p9k_ss::= $subsep_ }\${_p9k_sss::=%F{ $bg_color \} $end_sep_ } "
2019-07-24 21:07:28 +02:00
p += " \${_p9k_i::= $_p9k_segment_index }\${_p9k_bg::= $bg_color } "
2019-07-19 14:59:44 +02:00
p += '}+}'
2019-07-11 18:45:53 +02:00
p += '}'
2019-07-06 19:55:08 +02:00
2019-07-08 19:33:42 +02:00
_p9k_cache_set " $p "
2019-06-01 17:54:53 +02:00
fi
2019-07-24 23:05:41 +02:00
( ( $5 ) ) && _p9k_ret = \" $7 \" || _p9k_escape $7
2019-07-24 21:07:28 +02:00
if [ [ -z $6 ] ] ; then
2019-07-24 14:34:26 +02:00
_p9k_prompt += " \${\${:-\${P9K_CONTENT::= $_p9k_ret } $_p9k_cache_val [1] "
2019-07-09 10:09:50 +02:00
else
2019-07-24 23:05:41 +02:00
_p9k_prompt += " \${\${:-\" $6 \"}:+\${\${:-\${P9K_CONTENT::= $_p9k_ret } $_p9k_cache_val [1]} "
2019-07-09 10:09:50 +02:00
fi
2019-06-01 17:54:53 +02:00
}
2019-07-24 21:07:28 +02:00
# The same as _p9k_left_prompt_segment above but for the right prompt.
_p9k_right_prompt_segment( ) {
if ! _p9k_cache_get " $0 " " $1 " " $2 " " $3 " " $4 " " $_p9k_segment_index " ; then
_p9k_color $1 BACKGROUND $2
2019-07-23 15:47:25 +02:00
local bg_color = $_p9k_ret
2019-06-01 17:54:53 +02:00
_p9k_background $bg_color
2019-07-23 15:47:25 +02:00
local bg = $_p9k_ret
2019-07-24 23:05:41 +02:00
local bg_ = ${ _p9k_ret // \} / \\ \} }
2019-06-01 17:54:53 +02:00
2019-07-24 21:07:28 +02:00
_p9k_color $1 FOREGROUND $3
2019-07-23 15:47:25 +02:00
local fg_color = $_p9k_ret
2019-06-01 17:54:53 +02:00
_p9k_foreground $fg_color
2019-07-23 15:47:25 +02:00
local fg = $_p9k_ret
2019-06-01 17:54:53 +02:00
2019-07-11 18:45:53 +02:00
_p9k_get_icon $1 RIGHT_SEGMENT_SEPARATOR
2019-07-23 15:47:25 +02:00
local sep = $_p9k_ret
_p9k_escape $_p9k_ret
local sep_ = $_p9k_ret
2019-07-11 18:45:53 +02:00
2019-07-09 12:40:31 +02:00
_p9k_get_icon $1 RIGHT_SUBSEGMENT_SEPARATOR
2019-07-23 15:47:25 +02:00
local subsep = $_p9k_ret
2019-06-01 17:54:53 +02:00
2019-07-11 18:45:53 +02:00
local icon_
2019-07-24 21:07:28 +02:00
if [ [ -n $4 ] ] ; then
_p9k_get_icon $1 $4
2019-07-23 15:47:25 +02:00
_p9k_escape $_p9k_ret
icon_ = $_p9k_ret
2019-06-01 17:54:53 +02:00
fi
2019-07-11 18:45:53 +02:00
_p9k_get_icon $1 RIGHT_PROMPT_FIRST_SEGMENT_START_SYMBOL $sep
2019-07-23 15:47:25 +02:00
local start_sep = $_p9k_ret
2019-07-11 18:45:53 +02:00
[ [ -n $start_sep ] ] && start_sep = " %b%k%F{ $bg_color } $start_sep "
_p9k_get_icon $1 RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL
2019-07-23 15:47:25 +02:00
_p9k_escape $_p9k_ret
local end_sep_ = $_p9k_ret
2019-07-11 18:45:53 +02:00
local style = %b$bg $fg
2019-07-24 23:05:41 +02:00
local style_ = ${ style // \} / \\ \} }
2019-07-11 18:45:53 +02:00
2019-07-23 15:47:25 +02:00
_p9k_get_icon $1 WHITESPACE_BETWEEN_RIGHT_SEGMENTS ' '
local space = $_p9k_ret
2019-07-11 18:45:53 +02:00
_p9k_get_icon $1 RIGHT_LEFT_WHITESPACE $space
2019-07-23 15:47:25 +02:00
local left_space = $_p9k_ret
2019-07-11 18:45:53 +02:00
[ [ $left_space = = *%* ] ] && left_space += $style
_p9k_get_icon $1 RIGHT_RIGHT_WHITESPACE $space
2019-07-23 15:47:25 +02:00
_p9k_escape $_p9k_ret
local right_space_ = $_p9k_ret
2019-07-11 18:45:53 +02:00
[ [ $right_space_ = = *%* ] ] && right_space_ += $style_
2019-07-24 14:34:26 +02:00
local w = '<_p9k_w>' s = '<_p9k_s>'
2019-07-11 18:45:53 +02:00
# Segment separator logic:
#
2019-07-24 14:34:26 +02:00
# if [[ $_p9k_bg == NONE ]]; then
2019-07-11 18:45:53 +02:00
# 1
# elif (( joined )); then
# 2
2019-07-24 14:34:26 +02:00
# elif [[ $_p9k_bg == (${bg_color}|${bg_color:-0}) ]]; then
2019-07-11 18:45:53 +02:00
# 3
# else
# 4
# fi
2019-07-24 14:34:26 +02:00
local t = $# _p9k_t
_p9k_t += $start_sep $style $left_space # 1
_p9k_t += $w $style # 2
_p9k_t += $w $subsep $style $left_space # 3
_p9k_t += $w %F{ $bg_color } $sep $style $left_space # 4
2019-07-11 18:45:53 +02:00
2019-07-24 21:07:28 +02:00
local join = " _p9k_i>= $_p9k_right_join [ $_p9k_segment_index ] "
2019-07-11 18:45:53 +02:00
_p9k_param $1 SELF_JOINED false
2019-07-24 21:07:28 +02:00
[ [ $_p9k_ret = = false ] ] && join += " &&_p9k_i< $_p9k_segment_index "
2019-07-11 18:45:53 +02:00
local p =
2019-07-24 14:34:26 +02:00
p += "\${_p9k_n::=}"
p += " \${\${\${_p9k_bg:-0}:#NONE}:-\${_p9k_n::= $(( t+1)) }} " # 1
p += " \${_p9k_n:=\${\${\$(( $join )):#0}:+ $(( t+2)) }} " # 2
p += " \${_p9k_n:=\${\${(M)\${:-x\$_p9k_bg}:#x( ${ (b)bg_color } | ${ (b)bg_color :- 0 } )}:+ $(( t+3)) }} " # 3
p += " \${_p9k_n:= $(( t+4)) } " # 4
2019-07-11 18:45:53 +02:00
_p9k_param $1 VISUAL_IDENTIFIER_EXPANSION '${P9K_VISUAL_IDENTIFIER}'
2019-07-23 15:47:25 +02:00
local icon_exp_ = ${ _p9k_ret : + \" $_p9k_ret \" }
2019-07-11 18:45:53 +02:00
_p9k_param $1 CONTENT_EXPANSION '${P9K_CONTENT}'
2019-07-23 15:47:25 +02:00
local content_exp_ = ${ _p9k_ret : + \" $_p9k_ret \" }
2019-07-11 18:45:53 +02:00
2019-07-23 09:16:47 +02:00
if [ [ ( $icon_exp_ != '"${P9K_VISUAL_IDENTIFIER}"' && $icon_exp_ = = *'$' * ) ||
( $content_exp_ != '"${P9K_CONTENT}"' && $content_exp_ = = *'$' * ) ] ] ; then
2019-07-17 09:52:37 +02:00
p += " \${P9K_VISUAL_IDENTIFIER::= $icon_ } "
fi
local -i has_icon = -1 # maybe
2019-07-23 09:16:47 +02:00
if [ [ $icon_exp_ != '"${P9K_VISUAL_IDENTIFIER}"' && $icon_exp_ = = *'$' * ] ] ; then
2019-07-24 14:34:26 +02:00
p += " \${_p9k_v::= $icon_exp_ $style_ } "
2019-07-11 18:45:53 +02:00
else
2019-07-23 15:47:25 +02:00
[ [ $icon_exp_ = = '"${P9K_VISUAL_IDENTIFIER}"' ] ] && _p9k_ret = $icon_ || _p9k_ret = $icon_exp_
if [ [ -n $_p9k_ret ] ] ; then
2019-07-24 14:34:26 +02:00
p += " \${_p9k_v::= $_p9k_ret "
2019-07-23 15:47:25 +02:00
[ [ $_p9k_ret = = *%* ] ] && p += $style_
2019-07-17 09:52:37 +02:00
p += "}"
has_icon = 1 # definitely yes
else
has_icon = 0 # definitely no
fi
2019-07-11 18:45:53 +02:00
fi
2019-07-24 14:34:26 +02:00
p += " \${_p9k_c::= $content_exp_ } "
2019-07-17 09:52:37 +02:00
if ( ( has_icon = = -1 ) ) ; then
2019-07-24 14:34:26 +02:00
p += '${_p9k_e::=${${(%):-$_p9k_c%1(l.1.0)}[-1]}${${(%):-$_p9k_v%1(l.1.0)}[-1]}}'
2019-07-17 09:52:37 +02:00
else
2019-07-24 14:34:26 +02:00
p += '${_p9k_e::=${${(%):-$_p9k_c%1(l.1.0)}[-1]}' $has_icon '}'
2019-07-17 09:52:37 +02:00
fi
2019-07-11 18:45:53 +02:00
p += '}+}'
2019-07-24 14:34:26 +02:00
p += '${${_p9k_e:#00}:+${_p9k_t[$_p9k_n]/' $w '/$_p9k_w}'
2019-07-11 18:45:53 +02:00
2019-08-20 14:56:43 +02:00
[ [ -z $_p9k_locale ] ] || local LC_ALL = $_p9k_locale
2019-07-21 19:43:14 +02:00
_p9k_param $1 ICON_BEFORE_CONTENT ''
2019-07-23 15:47:25 +02:00
if [ [ $_p9k_ret != true ] ] ; then
2019-07-21 19:43:14 +02:00
_p9k_param $1 PREFIX ''
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (g : : )_p9k_ret }
_p9k_escape $_p9k_ret
p += $_p9k_ret
[ [ $_p9k_ret = = *%* ] ] && p += $style_
2019-07-21 19:43:14 +02:00
2019-07-24 14:34:26 +02:00
p += '${_p9k_c}' $style_
2019-07-21 19:43:14 +02:00
if ( ( has_icon != 0 ) ) ; then
local -i need_style = 0
_p9k_get_icon $1 RIGHT_MIDDLE_WHITESPACE ' '
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
_p9k_escape $_p9k_ret
[ [ $_p9k_ret = = *%* ] ] && need_style = 1
2019-07-24 14:34:26 +02:00
p += '${${(M)_p9k_e:#11}:+' $_p9k_ret '}'
2019-07-21 19:43:14 +02:00
fi
2019-07-11 18:45:53 +02:00
2019-07-21 19:43:14 +02:00
_p9k_color $1 VISUAL_IDENTIFIER_COLOR $fg_color
2019-07-23 15:47:25 +02:00
_p9k_foreground $_p9k_ret
2019-07-24 23:05:41 +02:00
_p9k_ret = %b$bg $_p9k_ret
_p9k_ret = ${ _p9k_ret // \} / \\ \} }
2019-07-23 15:47:25 +02:00
[ [ $_p9k_ret != $style_ || $need_style = = 1 ] ] && p += $_p9k_ret
2019-07-24 14:34:26 +02:00
p += '$_p9k_v'
2019-07-21 19:43:14 +02:00
fi
else
_p9k_param $1 PREFIX ''
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (g : : )_p9k_ret }
_p9k_escape $_p9k_ret
p += $_p9k_ret
[ [ $_p9k_ret = = *%* ] ] && local -i need_style = 1 || local -i need_style = 0
2019-07-21 19:43:14 +02:00
if ( ( has_icon != 0 ) ) ; then
_p9k_color $1 VISUAL_IDENTIFIER_COLOR $fg_color
2019-07-23 15:47:25 +02:00
_p9k_foreground $_p9k_ret
2019-07-24 23:05:41 +02:00
_p9k_ret = %b$bg $_p9k_ret
_p9k_ret = ${ _p9k_ret // \} / \\ \} }
2019-07-23 15:47:25 +02:00
[ [ $_p9k_ret != $style_ || $need_style = = 1 ] ] && p += $_p9k_ret
2019-07-24 14:34:26 +02:00
p += '${_p9k_v}'
2019-07-21 19:43:14 +02:00
_p9k_get_icon $1 RIGHT_MIDDLE_WHITESPACE ' '
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
_p9k_escape $_p9k_ret
[ [ _p9k_ret = = *%* ] ] && _p9k_ret += $style_
2019-07-24 14:34:26 +02:00
p += '${${(M)_p9k_e:#11}:+' $_p9k_ret '}'
2019-07-21 19:43:14 +02:00
fi
elif ( ( need_style ) ) ; then
p += $style_
2019-07-17 09:52:37 +02:00
fi
2019-07-11 18:45:53 +02:00
2019-07-24 14:34:26 +02:00
p += '${_p9k_c}' $style_
2019-07-17 09:52:37 +02:00
fi
2019-07-11 18:45:53 +02:00
_p9k_param $1 SUFFIX ''
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ (g : : )_p9k_ret }
_p9k_escape $_p9k_ret
p += $_p9k_ret
2019-07-11 18:45:53 +02:00
2019-07-19 14:59:44 +02:00
p += '${${:-'
2019-07-12 09:19:20 +02:00
if [ [ -n $fg_color && $fg_color = = $bg_color ] ] ; then
2019-07-24 14:34:26 +02:00
if [ [ $fg_color = = $_p9k_color1 ] ] ; then
_p9k_foreground $_p9k_color2
2019-07-12 09:19:20 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_foreground $_p9k_color1
2019-07-12 09:19:20 +02:00
fi
else
2019-07-23 15:47:25 +02:00
_p9k_ret = $fg
2019-07-12 09:19:20 +02:00
fi
2019-07-24 23:05:41 +02:00
_p9k_ret = ${ _p9k_ret // \} / \\ \} }
2019-07-24 14:34:26 +02:00
p += " \${_p9k_w::= ${ right_space_ : + $style_ } $right_space_ %b $bg_ $_p9k_ret } "
2019-07-11 18:45:53 +02:00
2019-07-24 14:34:26 +02:00
p += '${_p9k_sss::='
2019-07-16 16:19:16 +02:00
p += $style_ $right_space_
[ [ $right_space_ = = *%* ] ] && p += $style_
2019-07-30 12:49:36 +02:00
if [ [ -n $end_sep_ ] ] ; then
p += " %k%F{ $bg_color \} $end_sep_ $style_ "
fi
2019-07-19 14:59:44 +02:00
p += '}'
2019-07-11 18:45:53 +02:00
2019-07-24 21:07:28 +02:00
p += " \${_p9k_i::= $_p9k_segment_index }\${_p9k_bg::= $bg_color } "
2019-07-19 14:59:44 +02:00
p += '}+}'
2019-07-11 18:45:53 +02:00
p += '}'
_p9k_cache_set " $p "
fi
2019-07-24 23:05:41 +02:00
( ( $5 ) ) && _p9k_ret = \" $7 \" || _p9k_escape $7
2019-07-24 21:07:28 +02:00
if [ [ -z $6 ] ] ; then
2019-07-24 14:34:26 +02:00
_p9k_prompt += " \${\${:-\${P9K_CONTENT::= $_p9k_ret } $_p9k_cache_val [1] "
2019-07-11 18:45:53 +02:00
else
2019-07-24 23:05:41 +02:00
_p9k_prompt += " \${\${:-\" $6 \"}:+\${\${:-\${P9K_CONTENT::= $_p9k_ret } $_p9k_cache_val [1]} "
2019-07-11 18:45:53 +02:00
fi
2019-06-01 17:54:53 +02:00
}
2019-07-24 21:07:28 +02:00
function _p9k_prompt_segment( ) { " _p9k_ ${ _p9k_prompt_side } _prompt_segment " " $@ " }
2019-07-31 19:41:14 +02:00
function p9k_prompt_segment( ) { p10k segment " $@ " }
2019-07-10 20:06:19 +02:00
2019-06-20 09:14:09 +02:00
function _p9k_python_version( ) {
_p9k_cached_cmd_stdout_stderr python --version || return
2019-07-23 15:47:25 +02:00
[ [ $_p9k_ret = = ( #b)Python\ ([[:digit:].]##)* ]] && _p9k_ret=$match[1]
2019-06-20 09:14:09 +02:00
}
2019-06-01 17:54:53 +02:00
################################################################
# Prompt Segment Definitions
################################################################
################################################################
# Anaconda Environment
prompt_anaconda( ) {
local p = ${ CONDA_PREFIX :- $CONDA_ENV_PATH }
2019-06-20 09:14:09 +02:00
[ [ -n $p ] ] || return
local msg = ''
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_ANACONDA_SHOW_PYTHON_VERSION ) ) && _p9k_python_version; then
2019-07-29 16:10:28 +02:00
msg = " ${ _p9k_ret // \% //%% } "
2019-06-01 17:54:53 +02:00
fi
2019-07-23 15:47:25 +02:00
msg += " $_POWERLEVEL9K_ANACONDA_LEFT_DELIMITER ${ ${ p : t } // \% /%% } $_POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER "
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "blue" " $_p9k_color1 " 'PYTHON_ICON' 0 '' " $msg "
2019-06-01 17:54:53 +02:00
}
################################################################
# AWS Profile
prompt_aws( ) {
local aws_profile = " ${ AWS_PROFILE :- $AWS_DEFAULT_PROFILE } "
if [ [ -n " $aws_profile " ] ] ; then
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " red white 'AWS_ICON' 0 '' " ${ aws_profile // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# Current Elastic Beanstalk environment
prompt_aws_eb_env( ) {
[ [ -r .elasticbeanstalk/config.yml ] ] || return
2019-07-29 14:18:57 +02:00
local v = ( $( grep environment .elasticbeanstalk/config.yml 2>/dev/null) )
[ [ $# v > 1 && -n $v [ 2] ] ] || return
[ [ -n $v ] ] && _p9k_prompt_segment " $0 " black green 'AWS_EB_ICON' 0 '' " ${ v [2]// \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to indicate background jobs with an icon.
prompt_background_jobs( ) {
local msg
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE ) ) ; then
if ( ( _POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS ) ) ; then
2019-06-01 17:54:53 +02:00
msg = '${(%):-%j}'
else
msg = '${${(%):-%j}:#1}'
fi
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment $0 " $_p9k_color1 " cyan BACKGROUND_JOBS_ICON 1 '${${(%):-%j}:#0}' " $msg "
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment that indicates usage level of current partition.
prompt_disk_usage( ) {
( ( $+commands[ df] ) ) || return
2019-07-24 15:52:54 +02:00
local disk_usage = ${ ${ = ${ (f) " $( df -P . 2>/dev/null) " } [2] } [5]%%% }
2019-06-01 17:54:53 +02:00
local state bg fg
2019-07-23 15:47:25 +02:00
if ( ( disk_usage >= _POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL ) ) ; then
2019-06-01 17:54:53 +02:00
state = critical
bg = red
fg = white
2019-07-23 15:47:25 +02:00
elif ( ( disk_usage >= _POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL ) ) ; then
2019-06-01 17:54:53 +02:00
state = warning
bg = yellow
2019-07-24 14:34:26 +02:00
fg = $_p9k_color1
2019-06-01 17:54:53 +02:00
else
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_DISK_USAGE_ONLY_WARNING ) ) && return
2019-06-01 17:54:53 +02:00
state = normal
2019-07-24 14:34:26 +02:00
bg = $_p9k_color1
2019-06-01 17:54:53 +02:00
fg = yellow
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment $0 _$state $bg $fg DISK_ICON 0 '' " $disk_usage %% "
2019-06-01 17:54:53 +02:00
}
function _p9k_read_file( ) {
2019-07-23 15:47:25 +02:00
_p9k_ret = ''
2019-08-02 07:07:23 +02:00
[ [ -n $1 ] ] && IFS = '' read -r _p9k_ret <$1
2019-07-23 15:47:25 +02:00
[ [ -n $_p9k_ret ] ]
2019-06-01 17:54:53 +02:00
}
2019-07-23 15:47:25 +02:00
################################################################
# Segment that displays the battery status in levels and colors
2019-06-01 17:54:53 +02:00
prompt_battery( ) {
local state remain
local -i bat_percent
2019-07-24 14:34:26 +02:00
case $_p9k_os in
2019-06-01 17:54:53 +02:00
OSX)
( ( $+commands[ pmset] ) ) || return
2019-07-24 15:52:54 +02:00
local raw_data = ${ ${ (f) " $( pmset -g batt 2>/dev/null) " } [2] }
2019-06-01 17:54:53 +02:00
[ [ $raw_data = = *InternalBattery* ] ] || return
remain = ${ ${ (s : : ) ${ ${ (s : ; : )raw_data } [3] } } [1] }
[ [ $remain = = *no* ] ] && remain = "..."
[ [ $raw_data = ~ '([0-9]+)%' ] ] && bat_percent = $match [ 1]
case " ${ ${ (s : ; : )raw_data } [2] } " in
'charging' | 'finishing charge' | 'AC attached' )
2019-07-20 15:40:15 +02:00
state = CHARGING
2019-06-01 17:54:53 +02:00
; ;
'discharging' )
2019-07-23 15:47:25 +02:00
( ( bat_percent < _POWERLEVEL9K_BATTERY_LOW_THRESHOLD ) ) && state = LOW || state = DISCONNECTED
2019-06-01 17:54:53 +02:00
; ;
*)
2019-07-20 15:40:15 +02:00
state = CHARGED
2019-06-01 17:54:53 +02:00
remain = ''
; ;
esac
; ;
Linux| Android)
local -a bats = ( /sys/class/power_supply/( BAT*| battery) /( FN) )
( ( $# bats ) ) || return
local -i energy_now energy_full power_now
local -i is_full = 1 is_calculating is_charching
local dir
for dir in $bats ; do
2019-06-16 11:28:13 +02:00
local -i pow = 0 full = 0
if _p9k_read_file $dir /( energy_full| charge_full| charge_counter) ( N) ; then
2019-07-23 15:47:25 +02:00
( ( energy_full += ${ full : : =_p9k_ret } ) )
2019-06-16 11:28:13 +02:00
fi
2019-07-23 15:47:25 +02:00
if _p9k_read_file $dir /( power| current) _now( N) && ( ( $# _p9k_ret < 9 ) ) ; then
( ( power_now += ${ pow : : = $_p9k_ret } ) )
2019-06-16 11:28:13 +02:00
fi
if _p9k_read_file $dir /( energy| charge) _now( N) ; then
2019-07-23 15:47:25 +02:00
( ( energy_now += _p9k_ret ) )
2019-06-16 11:28:13 +02:00
elif _p9k_read_file $dir /capacity( N) ; then
2019-07-23 15:47:25 +02:00
( ( energy_now += _p9k_ret * full / 100. + 0.5 ) )
2019-06-16 11:28:13 +02:00
fi
2019-07-23 15:47:25 +02:00
_p9k_read_file $dir /status( N) && local bat_status = $_p9k_ret || continue
2019-06-01 17:54:53 +02:00
[ [ $bat_status != Full ] ] && is_full = 0
[ [ $bat_status = = Charging ] ] && is_charching = 1
[ [ $bat_status = = ( Charging| Discharging) && $pow = = 0 ] ] && is_calculating = 1
done
2019-06-16 11:28:13 +02:00
( ( energy_full ) ) || return
2019-06-16 12:31:07 +02:00
bat_percent = $(( 100 . * energy_now / energy_full + 0 .5 ))
2019-06-16 11:28:13 +02:00
( ( bat_percent > 100 ) ) && bat_percent = 100
2019-06-01 17:54:53 +02:00
2019-07-20 15:40:15 +02:00
if ( ( is_full || ( bat_percent = = 100 && is_charching) ) ) ; then
state = CHARGED
2019-06-01 17:54:53 +02:00
else
if ( ( is_charching ) ) ; then
2019-07-20 15:40:15 +02:00
state = CHARGING
2019-07-23 15:47:25 +02:00
elif ( ( bat_percent < _POWERLEVEL9K_BATTERY_LOW_THRESHOLD ) ) ; then
2019-07-20 15:40:15 +02:00
state = LOW
2019-06-01 17:54:53 +02:00
else
2019-07-20 15:40:15 +02:00
state = DISCONNECTED
2019-06-01 17:54:53 +02:00
fi
if ( ( power_now > 0 ) ) ; then
( ( is_charching ) ) && local -i e = $(( energy_full - energy_now)) || local -i e = energy_now
local -i minutes = $(( 60 * e / power_now ))
( ( minutes > 0 ) ) && remain = $(( minutes/60)) :${ (l#2##0#) $(( minutes%60)) }
elif ( ( is_calculating ) ) ; then
remain = "..."
fi
fi
; ;
*)
return
; ;
esac
2019-07-23 15:47:25 +02:00
( ( bat_percent >= _POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD ) ) && return
2019-06-01 17:54:53 +02:00
local msg = " $bat_percent %% "
2019-07-23 15:47:25 +02:00
[ [ $_POWERLEVEL9K_BATTERY_VERBOSE = = 1 && -n $remain ] ] && msg += " ( $remain ) "
2019-06-01 17:54:53 +02:00
2019-06-15 16:10:51 +02:00
local icon = BATTERY_ICON
2019-07-23 15:47:25 +02:00
if ( ( $# _POWERLEVEL9K_BATTERY_STAGES ) ) ; then
local -i idx = $# _POWERLEVEL9K_BATTERY_STAGES
( ( bat_percent < 100 ) ) && idx = $(( bat_percent * $# _POWERLEVEL9K_BATTERY_STAGES / 100 + 1 ))
icon = $'\1' $_POWERLEVEL9K_BATTERY_STAGES [ idx]
2019-06-15 16:10:51 +02:00
fi
2019-07-24 14:34:26 +02:00
local bg = $_p9k_color1
2019-07-23 15:47:25 +02:00
if ( ( $# _POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND ) ) ; then
local -i idx = $# _POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND
( ( bat_percent < 100 ) ) && idx = $(( bat_percent * $# _POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND / 100 + 1 ))
bg = $_POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND [ idx]
2019-06-01 17:54:53 +02:00
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment $0 _$state " $bg " " $_p9k_battery_states [ $state ] " $icon 0 '' $msg
2019-06-01 17:54:53 +02:00
}
################################################################
# Public IP segment
prompt_public_ip( ) {
local icon = 'PUBLIC_IP_ICON'
2019-07-23 15:47:25 +02:00
if [ [ -n $_POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ] ] ; then
_p9k_parse_ip $_POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE && icon = 'VPN_ICON'
2019-06-01 17:54:53 +02:00
fi
2019-07-24 14:34:26 +02:00
local ip = '${_p9k_public_ip:-$_POWERLEVEL9K_PUBLIC_IP_NONE}'
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " " $_p9k_color1 " " $_p9k_color2 " " $icon " 1 $ip $ip
2019-06-01 17:54:53 +02:00
}
################################################################
# Context: user@hostname (who am I and where am I)
prompt_context( ) {
2019-07-29 14:18:57 +02:00
if ! _p9k_cache_get $0 " ${ (%) :- %# } " ; then
2019-07-07 11:49:58 +02:00
local -i enabled = 1
2019-07-29 14:36:21 +02:00
local content
2019-08-20 11:19:11 +02:00
if [ [ $_POWERLEVEL9K_ALWAYS_SHOW_CONTEXT = = 0 && -n $DEFAULT_USER && $P9K_SSH = = 0 ] ] ; then
2019-07-29 14:18:57 +02:00
local user = " $( whoami) "
2019-07-29 14:36:21 +02:00
if [ [ $user = = $DEFAULT_USER ] ] ; then
if ( ( _POWERLEVEL9K_ALWAYS_SHOW_USER ) ) ; then
content = " ${ user // \% /%% } "
else
enabled = 0
fi
2019-07-07 11:49:58 +02:00
fi
2019-06-01 17:54:53 +02:00
fi
2019-07-29 14:36:21 +02:00
local state
2019-07-07 11:49:58 +02:00
if ( ( enabled ) ) ; then
state = "DEFAULT"
if [ [ " ${ (%) :- %# } " = = '#' ] ] ; then
state = "ROOT"
2019-08-20 11:19:11 +02:00
elif ( ( P9K_SSH ) ) ; then
2019-07-07 11:49:58 +02:00
if [ [ -n " $SUDO_COMMAND " ] ] ; then
state = "REMOTE_SUDO"
else
state = "REMOTE"
fi
elif [ [ -n " $SUDO_COMMAND " ] ] ; then
state = "SUDO"
fi
2019-07-29 14:36:21 +02:00
if [ [ -z $content ] ] ; then
local var = POWERLEVEL9K_CONTEXT_${ state } _TEMPLATE
if ( ( $+parameters[ $var ] ) ) ; then
2019-08-20 14:56:43 +02:00
[ [ -z $_p9k_locale ] ] || local LC_ALL = $_p9k_locale
2019-07-29 14:36:21 +02:00
content = ${ (P)var }
content = ${ (g : : )content }
else
content = $_POWERLEVEL9K_CONTEXT_TEMPLATE
fi
fi
2019-06-01 17:54:53 +02:00
fi
2019-07-07 11:49:58 +02:00
_p9k_cache_set " $enabled " " $state " " $content "
2019-06-01 17:54:53 +02:00
fi
2019-07-24 14:34:26 +02:00
( ( _p9k_cache_val[ 1] ) ) || return
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 _ $_p9k_cache_val [2] " " $_p9k_color1 " yellow '' 0 '' " $_p9k_cache_val [3] "
2019-06-01 17:54:53 +02:00
}
################################################################
# User: user (who am I)
prompt_user( ) {
2019-07-29 14:18:57 +02:00
if ! _p9k_cache_get $0 " ${ (%) :- %# } " ; then
local user = " $( whoami) "
2019-07-23 15:47:25 +02:00
if [ [ $_POWERLEVEL9K_ALWAYS_SHOW_USER = = 0 && $user = = $DEFAULT_USER ] ] ; then
2019-07-07 11:49:58 +02:00
_p9k_cache_set true
elif [ [ " ${ (%) :- %# } " = = '#' ] ] ; then
2019-07-24 21:07:28 +02:00
_p9k_cache_set _p9k_prompt_segment " ${ 0 } _ROOT " " ${ _p9k_color1 } " yellow ROOT_ICON 0 '' " $_POWERLEVEL9K_USER_TEMPLATE "
2019-07-07 11:49:58 +02:00
elif [ [ -n " $SUDO_COMMAND " ] ] ; then
2019-07-24 21:07:28 +02:00
_p9k_cache_set _p9k_prompt_segment " ${ 0 } _SUDO " " ${ _p9k_color1 } " yellow SUDO_ICON 0 '' " $_POWERLEVEL9K_USER_TEMPLATE "
2019-07-07 11:49:58 +02:00
else
2019-07-24 21:07:28 +02:00
_p9k_cache_set _p9k_prompt_segment " ${ 0 } _DEFAULT " " ${ _p9k_color1 } " yellow USER_ICON 0 '' " ${ user // \% /%% } "
2019-07-07 11:49:58 +02:00
fi
2019-06-01 17:54:53 +02:00
fi
2019-07-24 14:34:26 +02:00
" $_p9k_cache_val [@] "
2019-06-01 17:54:53 +02:00
}
################################################################
# Host: machine (where am I)
prompt_host( ) {
2019-08-20 11:19:11 +02:00
if ( ( P9K_SSH ) ) ; then
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 _REMOTE " " ${ _p9k_color1 } " yellow SSH_ICON 0 '' " $_POWERLEVEL9K_HOST_TEMPLATE "
2019-06-01 17:54:53 +02:00
else
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 _LOCAL " " ${ _p9k_color1 } " yellow HOST_ICON 0 '' " $_POWERLEVEL9K_HOST_TEMPLATE "
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# The 'custom` prompt provides a way for users to invoke commands and display
# the output in a segment.
2019-07-24 21:07:28 +02:00
_p9k_custom_prompt( ) {
local segment_name = ${ 1 : u }
2019-07-01 13:46:10 +02:00
local command = POWERLEVEL9K_CUSTOM_${ segment_name }
local -a cmd = ( " ${ (@Q) ${ (z) ${ (P)command } } } " )
2019-06-01 17:54:53 +02:00
whence $cmd [ 1] & >/dev/null || return
2019-07-29 14:18:57 +02:00
local content = " $( " $cmd [@] " ) "
2019-06-01 17:54:53 +02:00
[ [ -n $content ] ] || return
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " prompt_custom_ $segment_name " $_p9k_color2 $_p9k_color1 " CUSTOM_ ${ segment_name } _ICON " 0 '' " $content "
2019-06-01 17:54:53 +02:00
}
################################################################
# Display the duration the command needed to run.
prompt_command_execution_time( ) {
2019-08-16 20:26:28 +02:00
( ( $+P9K_COMMAND_DURATION_SECONDS ) ) || return
2019-07-24 18:34:29 +02:00
( ( P9K_COMMAND_DURATION_SECONDS >= _POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD ) ) || return
2019-06-14 12:26:40 +02:00
2019-07-20 12:41:52 +02:00
if ( ( P9K_COMMAND_DURATION_SECONDS < 60 ) ) ; then
2019-07-23 15:47:25 +02:00
if ( ( !_POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION ) ) ; then
2019-07-20 12:41:52 +02:00
local -i sec = $(( P9K_COMMAND_DURATION_SECONDS + 0 .5))
2019-07-16 20:35:18 +02:00
else
2019-07-23 15:47:25 +02:00
local -F $_POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION sec = P9K_COMMAND_DURATION_SECONDS
2019-07-20 12:41:52 +02:00
fi
local text = ${ sec } s
else
local -i d = $(( P9K_COMMAND_DURATION_SECONDS + 0 .5))
2019-07-23 15:47:25 +02:00
if [ [ $_POWERLEVEL9K_COMMAND_EXECUTION_TIME_FORMAT = = "H:M:S" ] ] ; then
2019-07-16 20:35:18 +02:00
local text = ${ (l.2..0.) $(( d % 60 )) }
if ( ( d >= 60 ) ) ; then
text = ${ (l.2..0.) $(( d / 60 % 60 )) } :$text
if ( ( d >= 36000 ) ) ; then
text = $(( d / 3600 )) :$text
elif ( ( d >= 3600 ) ) ; then
text = 0$(( d / 3600 )) :$text
fi
2019-06-14 12:26:40 +02:00
fi
2019-07-20 12:41:52 +02:00
else
local text = " $(( d % 60 )) s "
if ( ( d >= 60 ) ) ; then
text = " $(( d / 60 % 60 )) m $text "
if ( ( d >= 3600 ) ) ; then
text = " $(( d / 3600 % 24 )) h $text "
if ( ( d >= 86400 ) ) ; then
text = " $(( d / 86400 )) d $text "
fi
fi
fi
2019-06-01 17:54:53 +02:00
fi
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "red" "yellow1" 'EXECUTION_TIME_ICON' 0 '' $text
2019-06-01 17:54:53 +02:00
}
function _p9k_shorten_delim_len( ) {
local def = $1
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ _POWERLEVEL9K_SHORTEN_DELIMITER_LENGTH :- -1 }
( ( _p9k_ret >= 0 ) ) || _p9k_prompt_length $1
2019-06-01 17:54:53 +02:00
}
################################################################
# Dir: current working directory
prompt_dir( ) {
2019-08-07 08:38:04 +02:00
( ( _POWERLEVEL9K_DIR_PATH_ABSOLUTE ) ) && local p = $_p9k_pwd || local p = ${ (%) :- %~ }
2019-06-01 17:54:53 +02:00
if [ [ $p = = '~[' * ] ] ; then
# If "${(%):-%~}" expands to "~[a]/]/b", is the first component "~[a]" or "~[a]/]"?
# One would expect "${(%):-%-1~}" to give the right answer but alas it always simply
# gives the segment before the first slash, which would be "~[a]" in this case. Worse,
2019-07-17 19:34:01 +02:00
# for "~[a/b]" it'll give the nonsensical "~[a". To solve this problem we have to
2019-06-01 17:54:53 +02:00
# repeat what "${(%):-%~}" does and hope that it produces the same result.
local func = ''
local -a parts = ( )
for func in zsh_directory_name $zsh_directory_name_functions ; do
2019-08-07 08:38:04 +02:00
if ( ( $+functions[ $func ] ) ) && $func d $_p9k_pwd && [ [ $p = = '~[' $reply [ 1] ']' * ] ] ; then
2019-06-01 17:54:53 +02:00
parts += '~[' $reply [ 1] ']'
break
fi
done
if ( ( $# parts ) ) ; then
parts += ( ${ (s : / : ) ${ p # $parts [1] } } )
else
2019-08-07 08:38:04 +02:00
p = $_p9k_pwd
2019-06-01 17:54:53 +02:00
parts = ( " ${ (s : / : )p } " )
fi
else
local -a parts = ( " ${ (s : / : )p } " )
fi
2019-07-18 12:21:54 +02:00
local -i fake_first = 0 expand = 0
2019-07-23 15:47:25 +02:00
local delim = ${ _POWERLEVEL9K_SHORTEN_DELIMITER - $'\u2026' }
local -i shortenlen = ${ _POWERLEVEL9K_SHORTEN_DIR_LENGTH :- -1 }
2019-06-01 17:54:53 +02:00
2019-07-23 15:47:25 +02:00
case $_POWERLEVEL9K_SHORTEN_STRATEGY in
2019-06-01 17:54:53 +02:00
truncate_absolute| truncate_absolute_chars)
if ( ( shortenlen > 0 && $# p > shortenlen ) ) ; then
_p9k_shorten_delim_len $delim
2019-07-23 15:47:25 +02:00
if ( ( $# p > shortenlen + $_p9k_ret ) ) ; then
2019-06-01 17:54:53 +02:00
local -i n = shortenlen
local -i i = $# parts
while true; do
local dir = $parts [ i]
local -i len = $(( $# dir + ( i > 1 ) ))
if ( ( len <= n ) ) ; then
( ( n -= len ) )
( ( --i ) )
else
2019-07-04 17:40:54 +02:00
parts[ i] = $'\1' $dir [ -n,-1]
2019-06-01 17:54:53 +02:00
parts[ 1,i-1] = ( )
break
fi
done
fi
fi
; ;
truncate_with_package_name| truncate_middle| truncate_from_right)
( ) {
2019-07-23 15:47:25 +02:00
[ [ $_POWERLEVEL9K_SHORTEN_STRATEGY = = truncate_with_package_name &&
$+commands[ jq] = = 1 && $# _POWERLEVEL9K_DIR_PACKAGE_FILES > 0 ] ] || return
local pat = " ( ${ (j : | : )_POWERLEVEL9K_DIR_PACKAGE_FILES } ) "
2019-06-01 17:54:53 +02:00
local -i i = $# parts
2019-08-07 08:38:04 +02:00
local dir = $_p9k_pwd
2019-06-01 17:54:53 +02:00
for ( ( ; i > 0; --i ) ) ; do
local pkg_file = ''
for pkg_file in $dir /${ ~pat } ( N) ; do
local -H stat = ( )
zstat -H stat -- $pkg_file 2>/dev/null || return
if ! _p9k_cache_get $0 _pkg $stat [ inode] $stat [ mtime] $stat [ size] ; then
local pkg_name = ''
2019-07-29 14:18:57 +02:00
pkg_name = " $( jq -j '.name' <$pkg_file 2>/dev/null) " || pkg_name = ''
2019-06-01 17:54:53 +02:00
_p9k_cache_set " $pkg_name "
fi
2019-07-24 14:34:26 +02:00
[ [ -n $_p9k_cache_val [ 1] ] ] || return
parts[ 1,i] = ( $_p9k_cache_val [ 1] )
2019-06-01 17:54:53 +02:00
fake_first = 1
return
done
dir = ${ dir : h }
done
}
if ( ( shortenlen > 0 ) ) ; then
_p9k_shorten_delim_len $delim
2019-07-23 15:47:25 +02:00
local -i d = _p9k_ret pref = shortenlen suf = 0 i = 2
[ [ $_POWERLEVEL9K_SHORTEN_STRATEGY = = truncate_middle ] ] && suf = pref
2019-06-01 17:54:53 +02:00
for ( ( ; i < $# parts; ++i ) ) ; do
local dir = $parts [ i]
if ( ( $# dir > pref + suf + d ) ) ; then
2019-07-04 17:40:54 +02:00
dir[ pref+1,-suf-1] = $'\1'
2019-06-01 17:54:53 +02:00
parts[ i] = $dir
fi
done
fi
; ;
truncate_to_last)
fake_first = $(( $# parts > 1 ))
parts[ 1,-2] = ( )
; ;
truncate_to_first_and_last)
if ( ( shortenlen > 0 ) ) ; then
local -i i = $(( shortenlen + 1 ))
[ [ $p = = /* ] ] && ( ( ++i ) )
for ( ( ; i <= $# parts - shortenlen; ++i ) ) ; do
2019-07-04 17:40:54 +02:00
parts[ i] = $'\1'
2019-06-01 17:54:53 +02:00
done
fi
; ;
truncate_to_unique)
2019-07-18 12:21:54 +02:00
expand = 1
2019-07-23 15:47:25 +02:00
delim = ${ _POWERLEVEL9K_SHORTEN_DELIMITER - '*' }
2019-07-19 14:19:24 +02:00
local -i i = 2
2019-07-18 12:21:54 +02:00
[ [ $p [ 1] = = / ] ] && ( ( ++i ) )
2019-08-07 08:38:04 +02:00
local parent = " ${ _p9k_pwd %/ ${ (pj./.)parts[i,-1] } } "
2019-07-19 14:19:24 +02:00
if ( ( i <= $# parts ) ) ; then
local mtime = ( )
zstat -A mtime +mtime -- ${ (@) ${ :- { $i .. $# parts } } /( #b)(*)/$parent/${(pj./.)parts[i,$match[1]]}} 2>/dev/null || mtime=()
mtime = " ${ (pj : \1 : )mtime } "
else
local mtime = 'good'
fi
2019-07-24 14:34:26 +02:00
if ! _p9k_cache_get $0 " ${ parts [@] } " || [ [ -z $mtime || $mtime != $_p9k_cache_val [ 1] ] ] ; then
2019-07-19 14:19:24 +02:00
_p9k_prompt_length $delim
2019-07-23 15:47:25 +02:00
local -i real_delim_len = _p9k_ret n = 1 q = 0
2019-07-19 14:19:24 +02:00
[ [ -n $parts [ i-1] ] ] && parts[ i-1] = " \${(Q)\${:- ${ (qqq) ${ (q)parts[i-1] } } }} " $'\2'
[ [ $p [ i,-1] = = *[ "~!#\$^&*()\\\"'<>?{}[]" ] * ] ] && q = 1
2019-07-23 15:47:25 +02:00
local -i d = ${ _POWERLEVEL9K_SHORTEN_DELIMITER_LENGTH :- -1 }
2019-07-19 14:19:24 +02:00
( ( d >= 0 ) ) || d = real_delim_len
2019-07-23 15:47:25 +02:00
shortenlen = ${ _POWERLEVEL9K_SHORTEN_DIR_LENGTH :- 1 }
2019-07-19 14:19:24 +02:00
( ( shortenlen >= 0 ) ) && n = shortenlen
for ( ( ; i <= $# parts - n; ++i ) ) ; do
local dir = $parts [ i]
2019-07-23 15:47:25 +02:00
if [ [ -n $_POWERLEVEL9K_SHORTEN_FOLDER_MARKER &&
-n $parent /$dir /${ ~_POWERLEVEL9K_SHORTEN_FOLDER_MARKER } ( #qN) ]]; then
2019-07-19 14:19:24 +02:00
parent += /$dir
( ( q ) ) && parts[ i] = " \${(Q)\${:- ${ (qqq) ${ (q)dir } } }} "
parts[ i] += $'\2'
continue
fi
local -i j = 1
for ( ( ; j + d < $# dir; ++j ) ) ; do
local -a matching = ( $parent /$dir [ 1,j] */( N) )
( ( $# matching = = 1 ) ) && break
done
local -i saved = $(( $# dir - j - d))
if ( ( saved > 0 ) ) ; then
if ( ( q ) ) ; then
2019-07-24 14:34:26 +02:00
parts[ i] = '${${${_p9k_d:#-*}:+${(Q)${:-' ${ (qqq) ${ (q)dir } } '}}}:-${(Q)${:-'
parts[ i] += $'\3' ${ (qqq) ${ (q)dir[1,j] } } $'}}\1\3' '${$((_p9k_d+=' $saved '))+}}'
2019-07-19 14:19:24 +02:00
else
2019-07-24 14:34:26 +02:00
parts[ i] = '${${${_p9k_d:#-*}:+' $dir $'}:-\3' $dir [ 1,j] $'\1\3' '${$((_p9k_d+=' $saved '))+}}'
2019-07-19 14:19:24 +02:00
fi
else
( ( q ) ) && parts[ i] = " \${(Q)\${:- ${ (qqq) ${ (q)dir } } }} "
fi
2019-06-02 10:16:10 +02:00
parent += /$dir
2019-07-19 14:19:24 +02:00
done
for ( ( ; i <= $# parts; ++i) ) ; do
( ( q ) ) && parts[ i] = '${(Q)${:-' ${ (qqq) ${ (q)parts[i] } } '}}'
2019-07-18 14:20:04 +02:00
parts[ i] += $'\2'
2019-06-01 17:54:53 +02:00
done
2019-07-19 14:19:24 +02:00
_p9k_cache_set " $mtime " " ${ parts [@] } "
fi
2019-07-24 14:34:26 +02:00
parts = ( " ${ (@)_p9k_cache_val[2,-1] } " )
2019-06-01 17:54:53 +02:00
; ;
truncate_with_folder_marker)
2019-07-23 15:47:25 +02:00
if [ [ -n $_POWERLEVEL9K_SHORTEN_FOLDER_MARKER ] ] ; then
2019-08-07 08:38:04 +02:00
local dir = $_p9k_pwd
2019-06-01 17:54:53 +02:00
local -a m = ( )
local -i i = $(( $# parts - 1 ))
for ( ( ; i > 1; --i ) ) ; do
dir = ${ dir : h }
2019-07-23 15:47:25 +02:00
[ [ -n $dir /${ ~_POWERLEVEL9K_SHORTEN_FOLDER_MARKER } ( #qN) ]] && m+=$i
2019-06-01 17:54:53 +02:00
done
m += 1
for ( ( i = 1; i < $# m; ++i ) ) ; do
2019-07-04 17:40:54 +02:00
( ( m[ i] - m[ i+1] > 2 ) ) && parts[ m[ i+1] +1,m[ i] -1] = ( $'\1' )
2019-06-01 17:54:53 +02:00
done
fi
; ;
*)
if ( ( shortenlen > 0 ) ) ; then
local -i len = $# parts
[ [ -z $parts [ 1] ] ] && ( ( --len ) )
if ( ( len > shortenlen ) ) ; then
2019-07-04 17:40:54 +02:00
parts[ 1,-shortenlen-1] = ( $'\1' )
2019-06-01 17:54:53 +02:00
fi
fi
; ;
esac
2019-08-07 08:38:04 +02:00
[ [ $_POWERLEVEL9K_DIR_SHOW_WRITABLE = = 1 && ! -w $_p9k_pwd ] ]
2019-06-05 20:11:03 +02:00
local w = $?
2019-08-07 08:38:04 +02:00
if ! _p9k_cache_get $0 $_p9k_pwd $w $fake_first " ${ parts [@] } " ; then
2019-07-01 20:20:59 +02:00
local state = $0
local icon = ''
2019-06-05 20:11:03 +02:00
if ( ( ! w ) ) ; then
2019-07-01 20:20:59 +02:00
state += _NOT_WRITABLE
2019-06-05 20:11:03 +02:00
icon = LOCK_ICON
else
2019-07-01 20:20:59 +02:00
local a = '' b = '' c = ''
2019-07-23 15:47:25 +02:00
for a b c in " ${ _POWERLEVEL9K_DIR_CLASSES [@] } " ; do
2019-08-07 08:38:04 +02:00
if [ [ $_p9k_pwd = = ${ ~a } ] ] ; then
2019-07-01 20:20:59 +02:00
[ [ -n $b ] ] && state += _${ (U)b }
icon = $'\1' $c
break
fi
done
2019-06-05 20:11:03 +02:00
fi
2019-07-01 20:20:59 +02:00
2019-06-05 20:11:03 +02:00
local style = %b
2019-07-09 12:40:31 +02:00
_p9k_color $state BACKGROUND blue
2019-07-23 15:47:25 +02:00
_p9k_background $_p9k_ret
style += $_p9k_ret
2019-07-24 14:34:26 +02:00
_p9k_color $state FOREGROUND " $_p9k_color1 "
2019-07-23 15:47:25 +02:00
_p9k_foreground $_p9k_ret
style += $_p9k_ret
2019-07-18 12:21:54 +02:00
if ( ( expand ) ) ; then
2019-07-24 23:05:41 +02:00
_p9k_escape_style $style
2019-07-23 15:47:25 +02:00
style = $_p9k_ret
2019-07-18 12:21:54 +02:00
fi
2019-06-05 20:11:03 +02:00
2019-06-20 13:34:20 +02:00
parts = ( " ${ (@)parts// \% /%% } " )
2019-07-23 15:47:25 +02:00
if [ [ $_POWERLEVEL9K_HOME_FOLDER_ABBREVIATION != '~' && $fake_first = = 0 && $p = = ( '~' | '~/' *) ] ] ; then
( ( expand ) ) && _p9k_escape $_POWERLEVEL9K_HOME_FOLDER_ABBREVIATION || _p9k_ret = $_POWERLEVEL9K_HOME_FOLDER_ABBREVIATION
parts[ 1] = $_p9k_ret
[ [ $_p9k_ret = = *%* ] ] && parts[ 1] += $style
2019-07-18 12:21:54 +02:00
fi
2019-07-23 15:47:25 +02:00
[ [ $_POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER = = 1 && $# parts > 1 && -n $parts [ 2] ] ] && parts[ 1] = ( )
2019-06-05 20:11:03 +02:00
2019-07-18 14:20:04 +02:00
local last_style =
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD ) ) && last_style += %B
if ( ( $+_POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND ) ) ; then
_p9k_translate_color $_POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
_p9k_foreground $_p9k_ret
last_style += $_p9k_ret
2019-06-05 20:11:03 +02:00
fi
2019-07-18 14:20:04 +02:00
if [ [ -n $last_style ] ] ; then
2019-07-24 23:05:41 +02:00
( ( expand ) ) && _p9k_escape_style $last_style || _p9k_ret = $last_style
2019-07-23 15:47:25 +02:00
parts[ -1] = $_p9k_ret ${ parts [-1]// $'\1' / $'\1' $_p9k_ret } $style
2019-07-18 12:21:54 +02:00
fi
2019-07-18 14:20:04 +02:00
local anchor_style =
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_DIR_ANCHOR_BOLD ) ) && anchor_style += %B
if ( ( $+_POWERLEVEL9K_DIR_ANCHOR_FOREGROUND ) ) ; then
_p9k_translate_color $_POWERLEVEL9K_DIR_ANCHOR_FOREGROUND
_p9k_foreground $_p9k_ret
anchor_style += $_p9k_ret
2019-07-18 14:20:04 +02:00
fi
if [ [ -n $anchor_style ] ] ; then
2019-07-24 23:05:41 +02:00
( ( expand ) ) && _p9k_escape_style $anchor_style || _p9k_ret = $anchor_style
2019-07-18 14:20:04 +02:00
if [ [ -z $last_style ] ] ; then
2019-07-23 15:47:25 +02:00
parts = ( " ${ (@)parts/%(#b)(*) $'\2' / $_p9k_ret $match [1] $style } " )
2019-07-18 14:20:04 +02:00
else
2019-07-23 15:47:25 +02:00
( ( $# parts > 1 ) ) && parts[ 1,-2] = ( " ${ (@)parts[1,-2]/%(#b)(*) $'\2' / $_p9k_ret $match [1] $style } " )
2019-07-18 14:20:04 +02:00
parts[ -1] = ${ parts [-1]/ $'\2' }
fi
else
parts = ( " ${ (@)parts/ $'\2' } " )
fi
2019-07-23 15:47:25 +02:00
if ( ( $+_POWERLEVEL9K_DIR_SHORTENED_FOREGROUND ) ) ; then
_p9k_translate_color $_POWERLEVEL9K_DIR_SHORTENED_FOREGROUND
_p9k_foreground $_p9k_ret
2019-07-24 23:05:41 +02:00
( ( expand ) ) && _p9k_escape_style $_p9k_ret
2019-07-23 15:47:25 +02:00
local shortened_fg = $_p9k_ret
( ( expand ) ) && _p9k_escape $delim || _p9k_ret = $delim
[ [ $_p9k_ret = = *%* ] ] && _p9k_ret += $style $shortened_fg
parts = ( " ${ (@)parts/(#b) $'\3' (*) $'\1' (*) $'\3' / $shortened_fg $match [1] $_p9k_ret $match [2] $style } " )
parts = ( " ${ (@)parts/(#b)(*) $'\1' (*)/ $shortened_fg $match [1] $_p9k_ret $match [2] $style } " )
2019-07-18 16:29:45 +02:00
else
2019-07-23 15:47:25 +02:00
( ( expand ) ) && _p9k_escape $delim || _p9k_ret = $delim
[ [ $_p9k_ret = = *%* ] ] && _p9k_ret += $style
parts = ( " ${ (@)parts/ $'\1' / $_p9k_ret } " )
2019-07-18 16:29:45 +02:00
parts = ( " ${ (@)parts// $'\3' } " )
fi
2019-06-05 20:11:03 +02:00
2019-07-18 12:21:54 +02:00
local sep = ''
2019-07-23 15:47:25 +02:00
if ( ( $+_POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND ) ) ; then
_p9k_translate_color $_POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
_p9k_foreground $_p9k_ret
2019-07-24 23:05:41 +02:00
( ( expand ) ) && _p9k_escape_style $_p9k_ret
2019-07-23 15:47:25 +02:00
sep = $_p9k_ret
fi
( ( expand ) ) && _p9k_escape $_POWERLEVEL9K_DIR_PATH_SEPARATOR || _p9k_ret = $_POWERLEVEL9K_DIR_PATH_SEPARATOR
sep += $_p9k_ret
2019-07-18 12:21:54 +02:00
[ [ $sep = = *%* ] ] && sep += $style
2019-06-01 17:54:53 +02:00
2019-06-20 13:37:21 +02:00
local content = " ${ (pj. $sep .)parts } "
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_DIR_HYPERLINK ) ) ; then
2019-08-07 08:38:04 +02:00
local pref = $'%{\e]8;;file://' ${ ${ _p9k_pwd // \% /%%25 } // '#' /%%23 } $'\a%}'
2019-07-18 12:21:54 +02:00
local suf = $'%{\e]8;;\a%}'
if ( ( expand ) ) ; then
_p9k_escape $pref
2019-07-23 15:47:25 +02:00
pref = $_p9k_ret
2019-07-18 12:21:54 +02:00
_p9k_escape $suf
2019-07-23 15:47:25 +02:00
suf = $_p9k_ret
2019-07-18 12:21:54 +02:00
fi
content = $pref $content $suf
2019-06-20 13:37:21 +02:00
fi
2019-07-19 13:29:54 +02:00
2019-07-24 14:34:26 +02:00
( ( expand ) ) && eval " _p9k_prompt_length \"\${\${_p9k_d::=0}+} $content \" " || _p9k_ret =
2019-07-23 15:47:25 +02:00
_p9k_cache_set " $state " " $icon " " $expand " " $content " $_p9k_ret
2019-06-01 17:54:53 +02:00
fi
2019-07-19 13:29:54 +02:00
2019-07-24 14:34:26 +02:00
if ( ( _p9k_cache_val[ 3] ) ) ; then
if ( ( $+_p9k_dir ) ) ; then
_p9k_cache_val[ 4] = '${${_p9k_d::=-1024}+}' $_p9k_cache_val [ 4]
2019-07-18 12:21:54 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_dir = $_p9k_cache_val [ 4]
_p9k_dir_len = $_p9k_cache_val [ 5]
2019-07-24 23:05:41 +02:00
_p9k_cache_val[ 4] = '%{d%}' $_p9k_cache_val [ 4] '%{d%}'
2019-07-18 12:21:54 +02:00
fi
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $_p9k_cache_val [1] " "blue" " $_p9k_color1 " " $_p9k_cache_val [2] " " $_p9k_cache_val [3] " "" " $_p9k_cache_val [4] "
2019-06-01 17:54:53 +02:00
}
################################################################
# Docker machine
prompt_docker_machine( ) {
if [ [ -n " $DOCKER_MACHINE_NAME " ] ] ; then
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "magenta" " $_p9k_color1 " 'SERVER_ICON' 0 '' " ${ DOCKER_MACHINE_NAME // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# GO prompt
prompt_go_version( ) {
_p9k_cached_cmd_stdout go version || return
local -a match
2019-07-23 15:47:25 +02:00
[ [ $_p9k_ret = = ( #b)*go([[:digit:].]##)* ]] || return
2019-06-01 17:54:53 +02:00
local v = $match [ 1]
2019-08-12 08:56:47 +02:00
if ( ( _POWERLEVEL9K_GO_VERSION_PROJECT_ONLY ) ) ; then
local p = $GOPATH
if [ [ -z $p ] ] ; then
if [ [ -d $HOME /go ] ] ; then
p = $HOME /go
else
p = " $( go env GOPATH 2>/dev/null) " && [ [ -n $p ] ] || return
fi
fi
if [ [ $_p9k_pwd / != $p /* && $_p9k_pwd_a / != $p /* ] ] ; then
local dir = $_p9k_pwd_a
while true; do
[ [ $dir = = / ] ] && return
[ [ -e $dir /go.mod ] ] && break
dir = ${ dir : h }
done
2019-06-01 17:54:53 +02:00
fi
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "green" "grey93" "GO_ICON" 0 '' " ${ v // \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Command number (in local history)
prompt_history( ) {
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "grey50" " $_p9k_color1 " '' 0 '' '%h'
2019-06-01 17:54:53 +02:00
}
################################################################
# Detection for virtualization (systemd based systems only)
prompt_detect_virt( ) {
( ( $+commands[ systemd-detect-virt] ) ) || return
2019-07-29 14:18:57 +02:00
local virt = " $( systemd-detect-virt 2>/dev/null) "
2019-06-01 17:54:53 +02:00
if [ [ " $virt " = = "none" ] ] ; then
2019-07-24 15:52:54 +02:00
[ [ " $( ls -di /) " != "2 /" ] ] && virt = "chroot"
2019-06-01 17:54:53 +02:00
fi
if [ [ -n " ${ virt } " ] ] ; then
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " " $_p9k_color1 " "yellow" '' 0 '' " ${ virt // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# Segment to display the current IP address
prompt_ip( ) {
2019-07-23 15:47:25 +02:00
_p9k_parse_ip $_POWERLEVEL9K_IP_INTERFACE || return
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "cyan" " $_p9k_color1 " 'NETWORK_ICON' 0 '' " ${ _p9k_ret // \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to display if VPN is active
prompt_vpn_ip( ) {
2019-07-23 15:47:25 +02:00
_p9k_parse_ip $_POWERLEVEL9K_VPN_IP_INTERFACE || return
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "cyan" " $_p9k_color1 " 'VPN_ICON' 0 '' " ${ _p9k_ret // \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to display laravel version
prompt_laravel_version( ) {
local laravel_version = " $( php artisan --version 2> /dev/null) "
if [ [ -n " ${ laravel_version } " && " ${ laravel_version } " = ~ "Laravel Framework" ] ] ; then
# Strip out everything but the version
laravel_version = " ${ laravel_version //Laravel Framework / } "
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "maroon" "white" 'LARAVEL_ICON' 0 '' " ${ laravel_version // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# Segment to display load
prompt_load( ) {
local bucket = 2
2019-07-23 15:47:25 +02:00
case $_POWERLEVEL9K_LOAD_WHICH in
2019-06-01 17:54:53 +02:00
1) bucket = 1; ;
5) bucket = 2; ;
15) bucket = 3; ;
esac
local load
2019-07-24 14:34:26 +02:00
case $_p9k_os in
2019-06-01 17:54:53 +02:00
OSX| BSD)
( ( $+commands[ sysctl] ) ) || return
2019-07-29 14:18:57 +02:00
load = " $( sysctl -n vm.loadavg 2>/dev/null) " || return
2019-06-01 17:54:53 +02:00
load = ${ ${ (A)=load } [bucket+1]//,/. }
; ;
*)
2019-06-06 11:52:17 +02:00
[ [ -r /proc/loadavg ] ] || return
2019-06-01 17:54:53 +02:00
_p9k_read_file /proc/loadavg || return
2019-07-23 15:47:25 +02:00
load = ${ ${ (A)=_p9k_ret } [bucket]//,/. }
2019-06-01 17:54:53 +02:00
; ;
esac
2019-07-24 14:34:26 +02:00
( ( _p9k_num_cpus ) ) || return
2019-06-01 17:54:53 +02:00
2019-07-24 14:34:26 +02:00
if ( ( load > 0.7 * _p9k_num_cpus ) ) ; then
2019-06-01 17:54:53 +02:00
local state = critical bg = red
2019-07-24 14:34:26 +02:00
elif ( ( load > 0.5 * _p9k_num_cpus ) ) ; then
2019-06-01 17:54:53 +02:00
local state = warning bg = yellow
else
local state = normal bg = green
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment $0 _$state $bg " $_p9k_color1 " LOAD_ICON 0 '' $load
2019-06-01 17:54:53 +02:00
}
function _p9k_cached_cmd_stdout( ) {
local cmd = $commands [ $1 ]
[ [ -n $cmd ] ] || return
shift
local -H stat
zstat -H stat -- $cmd 2>/dev/null || return
if ! _p9k_cache_get $0 $stat [ inode] $stat [ mtime] $stat [ size] $stat [ mode] $cmd " $@ " ; then
local out
2019-07-29 14:18:57 +02:00
out = " $( $cmd " $@ " 2>/dev/null) "
2019-06-01 17:54:53 +02:00
_p9k_cache_set $(( ! $? )) " $out "
fi
2019-07-24 14:34:26 +02:00
( ( $_p9k_cache_val [ 1] ) ) || return
_p9k_ret = $_p9k_cache_val [ 2]
2019-06-01 17:54:53 +02:00
}
function _p9k_cached_cmd_stdout_stderr( ) {
local cmd = $commands [ $1 ]
[ [ -n $cmd ] ] || return
shift
local -H stat
zstat -H stat -- $cmd 2>/dev/null || return
if ! _p9k_cache_get $0 $stat [ inode] $stat [ mtime] $stat [ size] $stat [ mode] $cmd " $@ " ; then
local out
2019-07-29 14:18:57 +02:00
out = " $( $cmd " $@ " 2>& 1) " # this line is the only diff with _p9k_cached_cmd_stdout
2019-06-01 17:54:53 +02:00
_p9k_cache_set $(( ! $? )) " $out "
fi
2019-07-24 14:34:26 +02:00
( ( $_p9k_cache_val [ 1] ) ) || return
_p9k_ret = $_p9k_cache_val [ 2]
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to diplay Node version
prompt_node_version( ) {
( ( $+commands[ node] ) ) || return
2019-07-24 14:34:26 +02:00
if ( ( _POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY ) ) ; then
2019-08-07 08:38:04 +02:00
local dir = $_p9k_pwd
2019-06-01 17:54:53 +02:00
while true; do
[ [ $dir = = / ] ] && return
[ [ -e $dir /package.json ] ] && break
dir = ${ dir : h }
done
fi
2019-07-23 15:47:25 +02:00
_p9k_cached_cmd_stdout node --version && [ [ $_p9k_ret = = v?* ] ] || return
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "green" "white" 'NODE_ICON' 0 '' " ${ _p9k_ret #v } "
2019-06-01 17:54:53 +02:00
}
# Almost the same as `nvm_version default` but faster. The differences shouldn't affect
# the observable behavior of Powerlevel10k.
function _p9k_nvm_ls_default( ) {
local v = default
local -a seen = ( $v )
2019-08-02 07:07:23 +02:00
while [ [ -r $NVM_DIR /alias/$v ] ] ; do
local target =
IFS = '' read -r target <$NVM_DIR /alias/$v
[ [ -z $target ] ] && break
( ( $seen [ ( I) $target ] ) ) && return
2019-06-01 17:54:53 +02:00
seen += $target
v = $target
done
case $v in
default| N/A)
return 1
; ;
system| v)
2019-07-23 15:47:25 +02:00
_p9k_ret = system
2019-06-01 17:54:53 +02:00
return
; ;
iojs-[ 0-9] *)
v = iojs-v${ v #iojs- }
; ;
[ 0-9] *)
v = v$v
; ;
esac
if [ [ $v = = v*.*.* ] ] ; then
if [ [ -x $NVM_DIR /versions/node/$v /bin/node || -x $NVM_DIR /$v /bin/node ] ] ; then
2019-07-23 15:47:25 +02:00
_p9k_ret = $v
2019-06-01 17:54:53 +02:00
return
elif [ [ -x $NVM_DIR /versions/io.js/$v /bin/node ] ] ; then
2019-07-23 15:47:25 +02:00
_p9k_ret = iojs-$v
2019-06-01 17:54:53 +02:00
return
else
return 1
fi
fi
local -a dirs = ( )
case $v in
node| node-| stable)
dirs = ( $NVM_DIR /versions/node $NVM_DIR )
v = '(v[1-9]*|v0.*[02468].*)'
; ;
unstable)
dirs = ( $NVM_DIR /versions/node $NVM_DIR )
v = 'v0.*[13579].*'
; ;
iojs*)
dirs = ( $NVM_DIR /versions/io.js)
v = v${ ${ ${ v #iojs } #- } #v } '*'
; ;
*)
dirs = ( $NVM_DIR /versions/node $NVM_DIR $NVM_DIR /versions/io.js)
v = v${ v #v } '*'
; ;
esac
local -a matches = ( ${ ^dirs } /${ ~v } ( /N) )
( ( $# matches ) ) || return
local max path
local -a match
for path in ${ (Oa)matches } ; do
[ [ ${ path : t } = = ( #b)v(*).(*).(*) ]] || continue
v = ${ (j : : ) ${ (@l : 6 : : 0 : )match } }
[ [ $v > $max ] ] || continue
max = $v
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ path : t }
[ [ ${ path : h : t } != io.js ] ] || _p9k_ret = iojs-$_p9k_ret
2019-06-01 17:54:53 +02:00
done
[ [ -n $max ] ]
}
# The same as `nvm_version current` but faster.
_p9k_nvm_ls_current( ) {
local node_path = ${ commands [node] : A }
[ [ -n $node_path ] ] || return
local nvm_dir = ${ NVM_DIR : A }
if [ [ -n $nvm_dir && $node_path = = $nvm_dir /versions/io.js/* ] ] ; then
_p9k_cached_cmd_stdout iojs --version || return
2019-07-23 15:47:25 +02:00
_p9k_ret = iojs-v${ _p9k_ret #v }
2019-06-01 17:54:53 +02:00
elif [ [ -n $nvm_dir && $node_path = = $nvm_dir /* ] ] ; then
_p9k_cached_cmd_stdout node --version || return
2019-07-23 15:47:25 +02:00
_p9k_ret = v${ _p9k_ret #v }
2019-06-01 17:54:53 +02:00
else
2019-07-23 15:47:25 +02:00
_p9k_ret = system
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# Segment to display Node version from NVM
# Only prints the segment if different than the default value
prompt_nvm( ) {
2019-08-13 08:17:27 +02:00
( ( $+commands[ nvm] || $+functions[ nvm] ) ) || return
2019-06-01 17:54:53 +02:00
[ [ -n $NVM_DIR ] ] && _p9k_nvm_ls_current || return
2019-07-23 15:47:25 +02:00
local current = $_p9k_ret
! _p9k_nvm_ls_default || [ [ $_p9k_ret != $current ] ] || return
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "magenta" "black" 'NODE_ICON' 0 '' " ${ ${ current #v } // \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to display NodeEnv
prompt_nodeenv( ) {
2019-07-29 16:10:28 +02:00
[ [ -n " $NODE_VIRTUAL_ENV " ] ] || return
local msg
if ( ( _POWERLEVEL9K_NODEENV_SHOW_NODE_VERSION ) ) && _p9k_cached_cmd_stdout node --version; then
msg = " ${ _p9k_ret // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
2019-07-29 16:10:28 +02:00
msg += " $_POWERLEVEL9K_NODEENV_LEFT_DELIMITER ${ ${ NODE_VIRTUAL_ENV : t } // \% /%% } $_POWERLEVEL9K_NODEENV_RIGHT_DELIMITER "
_p9k_prompt_segment " $0 " "black" "green" 'NODE_ICON' 0 '' " $msg "
2019-06-01 17:54:53 +02:00
}
2019-07-16 23:03:49 +02:00
function _p9k_read_nodenv_version_file( ) {
[ [ -r $1 ] ] || return
local rest
2019-07-23 15:47:25 +02:00
read _p9k_ret rest <$1 2>/dev/null
[ [ -n $_p9k_ret ] ]
2019-07-16 23:03:49 +02:00
}
function _p9k_nodeenv_version_transform( ) {
local dir = ${ NODENV_ROOT :- $HOME /.nodenv } /versions
2019-07-23 15:47:25 +02:00
[ [ -z $1 || $1 = = system ] ] && _p9k_ret = $1 && return
[ [ -d $dir /$1 ] ] && _p9k_ret = $1 && return
[ [ -d $dir /${ 1 /v } ] ] && _p9k_ret = ${ 1 /v } && return
[ [ -d $dir /${ 1 #node- } ] ] && _p9k_ret = ${ 1 #node- } && return
[ [ -d $dir /${ 1 #node-v } ] ] && _p9k_ret = ${ 1 #node-v } && return
2019-07-16 23:03:49 +02:00
return 1
}
function _p9k_nodenv_global_version( ) {
2019-07-23 15:47:25 +02:00
_p9k_read_nodenv_version_file ${ NODENV_ROOT :- $HOME /.nodenv } /version || _p9k_ret = system
2019-07-16 23:03:49 +02:00
}
################################################################
# Segment to display nodenv information
# https://github.com/nodenv/nodenv
prompt_nodenv( ) {
2019-08-13 08:17:27 +02:00
( ( $+commands[ nodenv] || $+functions[ nodenv] ) ) || return
2019-07-23 15:47:25 +02:00
_p9k_ret = $NODENV_VERSION
if [ [ -z $_p9k_ret ] ] ; then
2019-08-12 08:56:47 +02:00
[ [ $NODENV_DIR = = /* ] ] && local dir = $NODENV_DIR || local dir = " $_p9k_pwd_a / $NODENV_DIR "
2019-07-16 23:03:49 +02:00
while [ [ $dir != //[ ^/] # ]]; do
_p9k_read_nodenv_version_file $dir /.node-version && break
[ [ $dir = = / ] ] && break
dir = ${ dir : h }
done
2019-07-23 15:47:25 +02:00
if [ [ -z $_p9k_ret ] ] ; then
( ( _POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW ) ) || return
2019-07-16 23:03:49 +02:00
_p9k_nodenv_global_version
fi
fi
2019-07-23 15:47:25 +02:00
_p9k_nodeenv_version_transform $_p9k_ret || return
local v = $_p9k_ret
2019-07-16 23:03:49 +02:00
2019-07-23 15:47:25 +02:00
if ( ( !_POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW ) ) ; then
2019-07-16 23:03:49 +02:00
_p9k_nodenv_global_version
2019-07-23 15:47:25 +02:00
_p9k_nodeenv_version_transform $_p9k_ret && [ [ $v = = $_p9k_ret ] ] && return
2019-07-16 23:03:49 +02:00
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "black" "green" 'NODE_ICON' 0 '' " ${ v // \% /%% } "
2019-07-16 23:03:49 +02:00
}
2019-06-01 17:54:53 +02:00
################################################################
# Segment to print a little OS icon
prompt_os_icon( ) {
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "black" "white" '' 0 '' " $_p9k_os_icon "
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to display PHP version number
prompt_php_version( ) {
_p9k_cached_cmd_stdout php --version || return
local -a match
2019-07-23 15:47:25 +02:00
[ [ $_p9k_ret = = ( #b)(*$'\n')#(PHP [[:digit:].]##)* ]] || return
2019-06-01 17:54:53 +02:00
local v = $match [ 2]
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "fuchsia" "grey93" '' 0 '' " ${ v // \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to display free RAM and used Swap
prompt_ram( ) {
local -F free_bytes
2019-07-24 14:34:26 +02:00
case $_p9k_os in
2019-06-01 17:54:53 +02:00
OSX)
( ( $+commands[ vm_stat] ) ) || return
2019-07-29 14:18:57 +02:00
local stat && stat = " $( vm_stat 2>/dev/null) " || return
2019-06-01 17:54:53 +02:00
[ [ $stat = ~ 'Pages free:[[:space:]]+([0-9]+)' ] ] || return
( ( free_bytes += match[ 1] ) )
[ [ $stat = ~ 'Pages inactive:[[:space:]]+([0-9]+)' ] ] || return
( ( free_bytes += match[ 1] ) )
( ( free_bytes *= 4096 ) )
; ;
BSD)
2019-07-29 14:18:57 +02:00
local stat && stat = " $( grep -F 'avail memory' /var/run/dmesg.boot 2>/dev/null) " || return
2019-06-01 17:54:53 +02:00
free_bytes = ${ ${ (A)=stat } [4] }
; ;
*)
2019-07-29 10:07:42 +02:00
[ [ -r /proc/meminfo ] ] || return
local stat && stat = " $( </proc/meminfo) " || return
[ [ $stat = = ( #b)*'MemAvailable:'[[:space:]]#(<->)* ]] || return
free_bytes = $(( $match [ 1 ] * 1024 ))
2019-06-01 17:54:53 +02:00
; ;
esac
_p9k_human_readable_bytes $free_bytes
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment $0 yellow " $_p9k_color1 " RAM_ICON 0 '' $_p9k_ret
2019-06-01 17:54:53 +02:00
}
function _p9k_read_rbenv_version_file( ) {
[ [ -r $1 ] ] || return
2019-08-02 07:07:23 +02:00
local rest
read _p9k_ret rest <$1 2>/dev/null
2019-07-23 15:47:25 +02:00
[ [ -n $_p9k_ret ] ]
2019-06-01 17:54:53 +02:00
}
function _p9k_rbenv_global_version( ) {
2019-07-23 15:47:25 +02:00
_p9k_read_rbenv_version_file ${ RBENV_ROOT :- $HOME /.rbenv } /version || _p9k_ret = system
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to display rbenv information
# https://github.com/rbenv/rbenv#choosing-the-ruby-version
prompt_rbenv( ) {
2019-08-13 08:17:27 +02:00
( ( $+commands[ rbenv] || $+functions[ rbenv] ) ) || return
2019-06-01 17:54:53 +02:00
local v = $RBENV_VERSION
if [ [ -z $v ] ] ; then
2019-08-12 08:56:47 +02:00
[ [ $RBENV_DIR = = /* ] ] && local dir = $RBENV_DIR || local dir = " $_p9k_pwd_a / $RBENV_DIR "
2019-06-01 17:54:53 +02:00
while true; do
if _p9k_read_rbenv_version_file $dir /.ruby-version; then
2019-07-23 15:47:25 +02:00
v = $_p9k_ret
2019-06-01 17:54:53 +02:00
break
fi
if [ [ $dir = = / ] ] ; then
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW ) ) || return
2019-06-01 17:54:53 +02:00
_p9k_rbenv_global_version
2019-07-23 15:47:25 +02:00
v = $_p9k_ret
2019-06-01 17:54:53 +02:00
break
fi
dir = ${ dir : h }
done
fi
2019-07-23 15:47:25 +02:00
if ( ( !_POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW ) ) ; then
2019-06-01 17:54:53 +02:00
_p9k_rbenv_global_version
2019-07-23 15:47:25 +02:00
[ [ $v = = $_p9k_ret ] ] && return
2019-06-01 17:54:53 +02:00
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "red" " $_p9k_color1 " 'RUBY_ICON' 0 '' " ${ v // \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to display chruby information
# see https://github.com/postmodern/chruby/issues/245 for chruby_auto issue with ZSH
prompt_chruby( ) {
2019-06-20 09:21:29 +02:00
[ [ -n $RUBY_ENGINE ] ] || return
local v = ''
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_CHRUBY_SHOW_ENGINE ) ) && v = $RUBY_ENGINE
if [ [ $_POWERLEVEL9K_CHRUBY_SHOW_VERSION = = 1 && -n $RUBY_VERSION ] ] && v += ${ v : + } $RUBY_VERSION
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "red" " $_p9k_color1 " 'RUBY_ICON' 0 '' " ${ v // \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to print an icon if user is root.
prompt_root_indicator( ) {
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " " $_p9k_color1 " "yellow" 'ROOT_ICON' 0 '${${(%):-%#}:#%}' ''
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to display Rust version number
prompt_rust_version( ) {
_p9k_cached_cmd_stdout rustc --version || return
2019-07-23 15:47:25 +02:00
local v = ${ ${ _p9k_ret #rustc } %% * }
2019-06-01 17:54:53 +02:00
[ [ -n $v ] ] || return
2019-08-12 08:56:47 +02:00
if ( ( _POWERLEVEL9K_RUST_VERSION_PROJECT_ONLY ) ) ; then
local dir = $_p9k_pwd_a
while true; do
[ [ $dir = = / ] ] && return
[ [ -e $dir /Cargo.toml ] ] && break
dir = ${ dir : h }
done
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "darkorange" " $_p9k_color1 " 'RUST_ICON' 0 '' " ${ v // \% /%% } "
2019-06-01 17:54:53 +02:00
}
# RSpec test ratio
prompt_rspec_stats( ) {
if [ [ -d app && -d spec ] ] ; then
local -a code = ( app/**/*.rb( N) )
( ( $# code ) ) || return
local tests = ( spec/**/*.rb( N) )
2019-07-24 21:07:28 +02:00
_p9k_build_test_stats " $0 " " $# code " " $# tests " "RSpec" 'TEST_ICON'
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# Segment to display Ruby Version Manager information
prompt_rvm( ) {
2019-08-13 08:17:27 +02:00
( ( $+commands[ rvm-prompt] || $+functions[ rvm-prompt] ) ) || return
2019-06-20 12:52:05 +02:00
[ [ $GEM_HOME = = *rvm* && $ruby_string != $rvm_path /bin/ruby ] ] || return
2019-08-10 10:47:22 +02:00
local v = ${ GEM_HOME : t }
( ( _POWERLEVEL9K_RVM_SHOW_GEMSET ) ) || v = ${ v %% ${ rvm_gemset_separator :- @ } * }
( ( _POWERLEVEL9K_RVM_SHOW_PREFIX ) ) || v = ${ v #*- }
2019-06-20 12:52:05 +02:00
[ [ -n $v ] ] || return
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "240" " $_p9k_color1 " 'RUBY_ICON' 0 '' " ${ v // \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to display SSH icon when connected
prompt_ssh( ) {
2019-08-20 11:19:11 +02:00
if ( ( P9K_SSH ) ) ; then
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " " $_p9k_color1 " "yellow" 'SSH_ICON' 0 '' ''
2019-06-01 17:54:53 +02:00
fi
}
2019-07-23 15:47:25 +02:00
################################################################
# Status: When an error occur, return the error code, or a cross icon if option is set
# Display an ok icon when no error occur, or hide the segment if option is set to false
2019-06-01 17:54:53 +02:00
prompt_status( ) {
2019-07-27 12:09:09 +02:00
if ! _p9k_cache_get $0 $_p9k_status $_p9k_pipestatus ; then
( ( _p9k_status ) ) && local state = ERROR || local state = OK
2019-07-26 15:35:46 +02:00
if ( ( _POWERLEVEL9K_STATUS_EXTENDED_STATES ) ) ; then
2019-07-27 12:09:09 +02:00
if ( ( _p9k_status ) ) ; then
if ( ( $# _p9k_pipestatus > 1 ) ) ; then
2019-07-26 15:35:46 +02:00
state += _PIPE
2019-07-27 12:09:09 +02:00
elif ( ( _p9k_status > 128 ) ) ; then
2019-07-26 15:35:46 +02:00
state += _SIGNAL
fi
2019-07-27 12:09:09 +02:00
elif [ [ " $_p9k_pipestatus " = = *[ 1-9] * ] ] ; then
2019-07-26 15:35:46 +02:00
state += _PIPE
2019-06-01 17:54:53 +02:00
fi
fi
2019-07-26 15:35:46 +02:00
_p9k_cache_val = ( :)
if ( ( _POWERLEVEL9K_STATUS_$state ) ) ; then
2019-07-27 12:09:09 +02:00
if ( ( _POWERLEVEL9K_STATUS_SHOW_PIPESTATUS ) ) ; then
local text = ${ (j : | : ) ${ (@)_p9k_pipestatus : /(#b)(*)/ $_p9k_exitcode2str [ $match [1]+1] } }
else
local text = $_p9k_exitcode2str [ _p9k_status+1]
fi
if ( ( _p9k_status ) ) ; then
2019-07-26 15:35:46 +02:00
if ( ( !_POWERLEVEL9K_STATUS_CROSS && _POWERLEVEL9K_STATUS_VERBOSE ) ) ; then
_p9k_cache_val = ( $0 _$state red yellow1 CARRIAGE_RETURN_ICON 0 '' " $text " )
else
_p9k_cache_val = ( $0 _$state $_p9k_color1 red FAIL_ICON 0 '' '' )
fi
elif ( ( _POWERLEVEL9K_STATUS_VERBOSE || _POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE ) ) ; then
[ [ $state = = OK ] ] && text = ''
_p9k_cache_val = ( $0 _$state " $_p9k_color1 " green OK_ICON 0 '' " $text " )
2019-06-01 17:54:53 +02:00
fi
fi
2019-07-27 12:09:09 +02:00
if ( ( $# _p9k_pipestatus < 3 ) ) ; then
2019-07-24 14:34:26 +02:00
_p9k_cache_set " ${ (@)_p9k_cache_val } "
2019-06-01 17:54:53 +02:00
fi
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " ${ (@)_p9k_cache_val } "
2019-06-01 17:54:53 +02:00
}
2019-07-12 15:46:53 +02:00
prompt_prompt_char( ) {
2019-07-27 12:09:09 +02:00
if ( ( _p9k_status ) ) ; then
2019-08-09 09:18:00 +02:00
_p9k_prompt_segment $0 _ERROR_VIINS " $_p9k_color1 " 196 '' 0 '${${KEYMAP:-0}:#(vicmd|vivis|vivli)}' '❯'
_p9k_prompt_segment $0 _ERROR_VICMD " $_p9k_color1 " 196 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#vicmd0}' '❮'
_p9k_prompt_segment $0 _ERROR_VIVIS " $_p9k_color1 " 196 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#(vicmd1|vivis?|vivli?)}' 'Ⅴ'
2019-07-12 15:46:53 +02:00
else
2019-08-09 09:18:00 +02:00
_p9k_prompt_segment $0 _OK_VIINS " $_p9k_color1 " 76 '' 0 '${${KEYMAP:-0}:#(vicmd|vivis|vivli)}' '❯'
_p9k_prompt_segment $0 _OK_VICMD " $_p9k_color1 " 76 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#vicmd0}' '❮'
_p9k_prompt_segment $0 _OK_VIVIS " $_p9k_color1 " 76 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#(vicmd1|vivis?|vivli?)}' 'Ⅴ'
2019-07-12 15:46:53 +02:00
fi
}
2019-06-01 17:54:53 +02:00
################################################################
# Segment to display Swap information
prompt_swap( ) {
local -F used_bytes
2019-07-24 14:34:26 +02:00
if [ [ " $_p9k_os " = = "OSX" ] ] ; then
2019-06-01 17:54:53 +02:00
( ( $+commands[ sysctl] ) ) || return
2019-07-24 15:52:54 +02:00
[ [ " $( sysctl vm.swapusage 2>/dev/null) " = ~ "used = ([0-9,.]+)([A-Z]+)" ] ] || return
2019-06-01 17:54:53 +02:00
used_bytes = ${ match [1]//,/. }
case ${ match [2] } in
'K' ) ( ( used_bytes *= 1024 ) ) ; ;
'M' ) ( ( used_bytes *= 1048576 ) ) ; ;
'G' ) ( ( used_bytes *= 1073741824 ) ) ; ;
'T' ) ( ( used_bytes *= 1099511627776 ) ) ; ;
*) return ; ;
esac
else
2019-07-29 14:18:57 +02:00
local meminfo && meminfo = " $( grep -F 'Swap' /proc/meminfo 2>/dev/null) " || return
2019-06-01 17:54:53 +02:00
[ [ $meminfo = ~ 'SwapTotal:[[:space:]]+([0-9]+)' ] ] || return
( ( used_bytes += match[ 1] ) )
[ [ $meminfo = ~ 'SwapFree:[[:space:]]+([0-9]+)' ] ] || return
( ( used_bytes-= match[ 1] ) )
( ( used_bytes *= 1024 ) )
fi
_p9k_human_readable_bytes $used_bytes
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment $0 yellow " $_p9k_color1 " SWAP_ICON 0 '' $_p9k_ret
2019-06-01 17:54:53 +02:00
}
################################################################
# Symfony2-PHPUnit test ratio
prompt_symfony2_tests( ) {
if [ [ -d src && -d app && -f app/AppKernel.php ] ] ; then
local -a all = ( src/**/*.php( N) )
local -a code = ( ${ (@)all##*Tests* } )
( ( $# code ) ) || return
2019-07-24 21:07:28 +02:00
_p9k_build_test_stats " $0 " " $# code " " $(( $# all - $# code)) " "SF2" 'TEST_ICON'
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# Segment to display Symfony2-Version
prompt_symfony2_version( ) {
if [ [ -r app/bootstrap.php.cache ] ] ; then
2019-07-24 15:52:54 +02:00
local v = " ${ $( grep -F " VERSION " app/bootstrap.php.cache 2>/dev/null) //[![ : digit : ].] } "
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "grey35" " $_p9k_color1 " 'SYMFONY_ICON' 0 '' " ${ v // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# Show a ratio of tests vs code
2019-07-24 21:07:28 +02:00
_p9k_build_test_stats( ) {
local code_amount = " $2 "
local tests_amount = " $3 "
local headline = " $4 "
2019-06-01 17:54:53 +02:00
( ( code_amount > 0 ) ) || return
local -F 2 ratio = $(( 100 . * tests_amount / code_amount ))
2019-07-24 21:07:28 +02:00
( ( ratio >= 75 ) ) && _p9k_prompt_segment " ${ 1 } _GOOD " "cyan" " $_p9k_color1 " " $5 " 0 '' " $headline : $ratio %% "
( ( ratio >= 50 && ratio < 75 ) ) && _p9k_prompt_segment " $1 _AVG " "yellow" " $_p9k_color1 " " $5 " 0 '' " $headline : $ratio %% "
( ( ratio < 50 ) ) && _p9k_prompt_segment " $1 _BAD " "red" " $_p9k_color1 " " $5 " 0 '' " $headline : $ratio %% "
2019-06-01 17:54:53 +02:00
}
################################################################
# System time
prompt_time( ) {
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME ) ) ; then
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " " $_p9k_color2 " " $_p9k_color1 " "TIME_ICON" 0 '' " $_POWERLEVEL9K_TIME_FORMAT "
2019-07-17 23:24:53 +02:00
else
2019-07-23 15:47:25 +02:00
local t = ${ ${ (%)_POWERLEVEL9K_TIME_FORMAT } // \% /%% }
if ( ( _POWERLEVEL9K_TIME_UPDATE_ON_COMMAND ) ) ; then
2019-07-17 23:24:53 +02:00
_p9k_escape $t
2019-07-23 15:47:25 +02:00
t = $_p9k_ret
_p9k_escape $_POWERLEVEL9K_TIME_FORMAT
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " " $_p9k_color2 " " $_p9k_color1 " "TIME_ICON" 1 '' \
2019-07-27 12:09:09 +02:00
" \${_p9k_line_finished- $t }\${_p9k_line_finished+ $_p9k_ret } "
2019-07-17 08:45:11 +02:00
else
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " " $_p9k_color2 " " $_p9k_color1 " "TIME_ICON" 0 '' $t
2019-07-17 08:45:11 +02:00
fi
fi
2019-06-01 17:54:53 +02:00
}
################################################################
# System date
prompt_date( ) {
2019-07-23 15:47:25 +02:00
local d = ${ ${ (%)_POWERLEVEL9K_DATE_FORMAT } // \% /%% }
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " " $_p9k_color2 " " $_p9k_color1 " "DATE_ICON" 0 '' " $d "
2019-06-01 17:54:53 +02:00
}
################################################################
# todo.sh: shows the number of tasks in your todo.sh file
prompt_todo( ) {
local todo = $commands [ todo.sh]
2019-07-24 14:34:26 +02:00
[ [ -n $todo && -r $_p9k_todo_file ] ] || return
2019-06-01 17:54:53 +02:00
local -H stat
2019-07-24 14:34:26 +02:00
zstat -H stat -- $_p9k_todo_file 2>/dev/null || return
2019-06-01 17:54:53 +02:00
if ! _p9k_cache_get $0 $stat [ inode] $stat [ mtime] $stat [ size] ; then
2019-07-24 14:34:26 +02:00
local count = " $( $todo -p ls | tail -1) "
2019-06-01 17:54:53 +02:00
if [ [ $count = = ( #b)'TODO: '[[:digit:]]##' of '([[:digit:]]##)' '* ]]; then
_p9k_cache_set 1 $match [ 1]
else
_p9k_cache_set 0 0
fi
fi
2019-07-24 14:34:26 +02:00
( ( $_p9k_cache_val [ 1] ) ) || return
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "grey50" " $_p9k_color1 " 'TODO_ICON' 0 '' " ${ _p9k_cache_val [2] } "
2019-06-01 17:54:53 +02:00
}
################################################################
# VCS segment: shows the state of your repository, if you are in a folder under
# version control
2019-07-10 20:06:19 +02:00
# The vcs segment can have 4 different states - defaults to 'CLEAN'.
2019-07-24 14:34:26 +02:00
typeset -gA __p9k_vcs_states = (
2019-07-09 16:08:43 +02:00
'CLEAN' '2'
'MODIFIED' '3'
'UNTRACKED' '2'
'LOADING' '8'
2019-06-01 17:54:53 +02:00
)
2019-07-24 15:01:26 +02:00
function +vi-git-untracked( ) {
[ [ -z " ${ vcs_comm [gitdir] } " || " ${ vcs_comm [gitdir] } " = = "." ] ] && return
# get the root for the current repo or submodule
2019-07-24 15:52:54 +02:00
local repoTopLevel = " $( git rev-parse --show-toplevel 2> /dev/null) "
2019-07-24 15:01:26 +02:00
# dump out if we're outside a git repository (which includes being in the .git folder)
[ [ $? != 0 || -z $repoTopLevel ] ] && return
2019-07-29 14:18:57 +02:00
local untrackedFiles = " $( git ls-files --others --exclude-standard " ${ repoTopLevel } " 2> /dev/null) "
2019-07-24 15:01:26 +02:00
if [ [ -z $untrackedFiles && $_POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY = = 1 ] ] ; then
2019-07-29 14:18:57 +02:00
untrackedFiles += " $( git submodule foreach --quiet --recursive 'git ls-files --others --exclude-standard' 2> /dev/null) "
2019-07-24 15:01:26 +02:00
fi
[ [ -z $untrackedFiles ] ] && return
hook_com[ unstaged] += " $( print_icon 'VCS_UNTRACKED_ICON' ) "
VCS_WORKDIR_HALF_DIRTY = true
}
function +vi-git-aheadbehind( ) {
2019-07-24 21:07:28 +02:00
local ahead behind
local -a gitstatus
2019-07-24 15:01:26 +02:00
2019-07-24 21:07:28 +02:00
# for git prior to 1.7
# ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
2019-07-29 14:18:57 +02:00
ahead = " $( git rev-list --count " ${ hook_com [branch] } " @{ upstream} ..HEAD 2>/dev/null) "
2019-07-24 21:07:28 +02:00
( ( ahead ) ) && gitstatus += ( " $( print_icon 'VCS_OUTGOING_CHANGES_ICON' ) ${ ahead // / } " )
2019-07-24 15:01:26 +02:00
2019-07-24 21:07:28 +02:00
# for git prior to 1.7
# behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
2019-07-29 14:18:57 +02:00
behind = " $( git rev-list --count HEAD.." ${ hook_com [branch] } " @{ upstream} 2>/dev/null) "
2019-07-24 21:07:28 +02:00
( ( behind ) ) && gitstatus += ( " $( print_icon 'VCS_INCOMING_CHANGES_ICON' ) ${ behind // / } " )
2019-07-24 15:01:26 +02:00
2019-07-24 21:07:28 +02:00
hook_com[ misc] += ${ (j : : )gitstatus }
2019-07-24 15:01:26 +02:00
}
function +vi-git-remotebranch( ) {
2019-07-24 21:07:28 +02:00
local remote
local branch_name = " ${ hook_com [branch] } "
# Are we on a remote-tracking branch?
2019-07-29 14:18:57 +02:00
remote = " $( git rev-parse --verify HEAD@{ upstream} --symbolic-full-name 2>/dev/null) "
remote = ${ remote /refs \/ (remotes|heads) \/ }
2019-07-24 21:07:28 +02:00
if ( ( $+_POWERLEVEL9K_VCS_SHORTEN_LENGTH && $+_POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH ) ) ; then
if ( ( ${# hook_com [branch] } > _POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH && ${# hook_com [branch] } > _POWERLEVEL9K_VCS_SHORTEN_LENGTH ) ) ; then
case $_POWERLEVEL9K_VCS_SHORTEN_STRATEGY in
truncate_middle)
hook_com[ branch] = " ${ branch_name : 0 : $_POWERLEVEL9K_VCS_SHORTEN_LENGTH } ${ _POWERLEVEL9K_VCS_SHORTEN_DELIMITER } ${ branch_name : - $_POWERLEVEL9K_VCS_SHORTEN_LENGTH } "
; ;
truncate_from_right)
hook_com[ branch] = " ${ branch_name : 0 : $_POWERLEVEL9K_VCS_SHORTEN_LENGTH } ${ _POWERLEVEL9K_VCS_SHORTEN_DELIMITER } "
; ;
esac
2019-07-24 15:01:26 +02:00
fi
2019-07-24 21:07:28 +02:00
fi
if ( ( _POWERLEVEL9K_HIDE_BRANCH_ICON ) ) ; then
hook_com[ branch] = " ${ hook_com [branch] } "
else
hook_com[ branch] = " $( print_icon 'VCS_BRANCH_ICON' ) ${ hook_com [branch] } "
fi
# Always show the remote
#if [[ -n ${remote} ]] ; then
# Only show the remote if it differs from the local
if [ [ -n ${ remote } ] ] && [ [ " ${ remote #*/ } " != " ${ branch_name } " ] ] ; then
hook_com[ branch] += " $( print_icon 'VCS_REMOTE_BRANCH_ICON' ) ${ remote // / } "
fi
2019-07-24 15:01:26 +02:00
}
function +vi-git-tagname( ) {
if ( ( !_POWERLEVEL9K_VCS_HIDE_TAGS ) ) ; then
2019-07-24 21:07:28 +02:00
# If we are on a tag, append the tagname to the current branch string.
local tag
2019-07-29 14:18:57 +02:00
tag = " $( git describe --tags --exact-match HEAD 2>/dev/null) "
2019-07-24 21:07:28 +02:00
if [ [ -n " ${ tag } " ] ] ; then
# There is a tag that points to our current commit. Need to determine if we
# are also on a branch, or are in a DETACHED_HEAD state.
2019-07-29 14:18:57 +02:00
if [ [ -z " $( git symbolic-ref HEAD 2>/dev/null) " ] ] ; then
2019-07-24 21:07:28 +02:00
# DETACHED_HEAD state. We want to append the tag name to the commit hash
# and print it. Unfortunately, `vcs_info` blows away the hash when a tag
# exists, so we have to manually retrieve it and clobber the branch
# string.
local revision
2019-07-29 14:18:57 +02:00
revision = " $( git rev-list -n 1 --abbrev-commit --abbrev= ${ _POWERLEVEL9K_CHANGESET_HASH_LENGTH } HEAD) "
2019-07-24 21:07:28 +02:00
if ( ( _POWERLEVEL9K_HIDE_BRANCH_ICON ) ) ; then
hook_com[ branch] = " ${ revision } $( print_icon 'VCS_TAG_ICON' ) ${ tag } "
else
hook_com[ branch] = " $( print_icon 'VCS_BRANCH_ICON' ) ${ revision } $( print_icon 'VCS_TAG_ICON' ) ${ tag } "
fi
else
# We are on both a tag and a branch; print both by appending the tag name.
hook_com[ branch] += " $( print_icon 'VCS_TAG_ICON' ) ${ tag } "
2019-07-24 15:01:26 +02:00
fi
2019-07-24 21:07:28 +02:00
fi
2019-07-24 15:01:26 +02:00
fi
}
# Show count of stashed changes
# Port from https://github.com/whiteinge/dotfiles/blob/5dfd08d30f7f2749cfc60bc55564c6ea239624d9/.zsh_shouse_prompt#L268
function +vi-git-stash( ) {
if [ [ -s " ${ vcs_comm [gitdir] } /logs/refs/stash " ] ] ; then
local -a stashes = ( " ${ (@f) " $( <${ vcs_comm [gitdir] } /logs/refs/stash) " } " )
hook_com[ misc] += " $( print_icon 'VCS_STASH_ICON' ) ${# stashes } "
fi
}
function +vi-hg-bookmarks( ) {
if [ [ -n " ${ hgbmarks [@] } " ] ] ; then
hook_com[ hg-bookmark-string] = " $( print_icon 'VCS_BOOKMARK_ICON' ) ${ hgbmarks [@] } "
# To signal that we want to use the sting we just generated, set the special
# variable `ret' to something other than the default zero:
ret = 1
return 0
fi
}
function +vi-vcs-detect-changes( ) {
if [ [ " ${ hook_com [vcs] } " = = "git" ] ] ; then
2019-07-29 14:18:57 +02:00
local remote = " $( git ls-remote --get-url 2> /dev/null) "
2019-07-24 15:01:26 +02:00
if [ [ " $remote " = ~ "github" ] ] then
vcs_visual_identifier = 'VCS_GIT_GITHUB_ICON'
elif [ [ " $remote " = ~ "bitbucket" ] ] then
vcs_visual_identifier = 'VCS_GIT_BITBUCKET_ICON'
elif [ [ " $remote " = ~ "stash" ] ] then
vcs_visual_identifier = 'VCS_GIT_BITBUCKET_ICON'
elif [ [ " $remote " = ~ "gitlab" ] ] then
vcs_visual_identifier = 'VCS_GIT_GITLAB_ICON'
else
vcs_visual_identifier = 'VCS_GIT_ICON'
fi
elif [ [ " ${ hook_com [vcs] } " = = "hg" ] ] ; then
vcs_visual_identifier = 'VCS_HG_ICON'
elif [ [ " ${ hook_com [vcs] } " = = "svn" ] ] ; then
vcs_visual_identifier = 'VCS_SVN_ICON'
fi
if [ [ -n " ${ hook_com [staged] } " ] ] || [ [ -n " ${ hook_com [unstaged] } " ] ] ; then
VCS_WORKDIR_DIRTY = true
else
VCS_WORKDIR_DIRTY = false
fi
}
function +vi-svn-detect-changes( ) {
local svn_status = " $( svn status) "
if [ [ -n " $( echo " $svn_status " | \g rep \^ \? ) " ] ] ; then
hook_com[ unstaged] += " $( print_icon 'VCS_UNTRACKED_ICON' ) "
VCS_WORKDIR_HALF_DIRTY = true
fi
if [ [ -n " $( echo " $svn_status " | \g rep \^ \M ) " ] ] ; then
hook_com[ unstaged] += " $( print_icon 'VCS_UNSTAGED_ICON' ) "
VCS_WORKDIR_DIRTY = true
fi
if [ [ -n " $( echo " $svn_status " | \g rep \^ \A ) " ] ] ; then
hook_com[ staged] += " $( print_icon 'VCS_STAGED_ICON' ) "
VCS_WORKDIR_DIRTY = true
fi
}
2019-07-24 21:07:28 +02:00
_p9k_vcs_info_init( ) {
2019-06-01 17:54:53 +02:00
autoload -Uz vcs_info
2019-07-23 15:47:25 +02:00
local prefix = ''
if ( ( _POWERLEVEL9K_SHOW_CHANGESET ) ) ; then
_p9k_get_icon '' VCS_COMMIT_ICON
prefix = " $_p9k_ret %0. ${ _POWERLEVEL9K_CHANGESET_HASH_LENGTH } i "
2019-06-01 17:54:53 +02:00
fi
zstyle ':vcs_info:*' check-for-changes true
2019-07-23 15:47:25 +02:00
zstyle ':vcs_info:*' formats " $prefix %b%c%u%m "
zstyle ':vcs_info:*' actionformats " %b %F{ $_POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND }| %a%f "
_p9k_get_icon '' VCS_STAGED_ICON
zstyle ':vcs_info:*' stagedstr " $_p9k_ret "
_p9k_get_icon '' VCS_UNSTAGED_ICON
zstyle ':vcs_info:*' unstagedstr " $_p9k_ret "
zstyle ':vcs_info:git*+set-message:*' hooks $_POWERLEVEL9K_VCS_GIT_HOOKS
zstyle ':vcs_info:hg*+set-message:*' hooks $_POWERLEVEL9K_VCS_HG_HOOKS
zstyle ':vcs_info:svn*+set-message:*' hooks $_POWERLEVEL9K_VCS_SVN_HOOKS
2019-06-01 17:54:53 +02:00
# For Hg, only show the branch name
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_HIDE_BRANCH_ICON ) ) ; then
zstyle ':vcs_info:hg*:*' branchformat "%b"
else
_p9k_get_icon '' VCS_BRANCH_ICON
zstyle ':vcs_info:hg*:*' branchformat " $_p9k_ret %b "
fi
2019-06-01 17:54:53 +02:00
# The `get-revision` function must be turned on for dirty-check to work for Hg
zstyle ':vcs_info:hg*:*' get-revision true
zstyle ':vcs_info:hg*:*' get-bookmarks true
zstyle ':vcs_info:hg*+gen-hg-bookmark-string:*' hooks hg-bookmarks
# TODO: fix the %b (branch) format for svn. Using %b breaks color-encoding of the foreground
# for the rest of the powerline.
2019-07-23 15:47:25 +02:00
zstyle ':vcs_info:svn*:*' formats " $prefix %c%u "
zstyle ':vcs_info:svn*:*' actionformats " $prefix %c%u %F{ $_POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND }| %a%f "
2019-06-01 17:54:53 +02:00
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_SHOW_CHANGESET ) ) ; then
2019-06-01 17:54:53 +02:00
zstyle ':vcs_info:*' get-revision true
2019-07-24 21:07:28 +02:00
else
zstyle ':vcs_info:*' get-revision false
2019-06-01 17:54:53 +02:00
fi
}
2019-07-07 19:03:21 +02:00
function _p9k_vcs_status_save( ) {
local z = $'\0'
2019-07-24 14:34:26 +02:00
_p9k_last_git_prompt[ $VCS_STATUS_WORKDIR ] = $VCS_STATUS_ACTION $z $VCS_STATUS_COMMIT \
2019-07-08 16:54:26 +02:00
$z $VCS_STATUS_COMMITS_AHEAD $z $VCS_STATUS_COMMITS_BEHIND $z $VCS_STATUS_HAS_CONFLICTED \
$z $VCS_STATUS_HAS_STAGED $z $VCS_STATUS_HAS_UNSTAGED $z $VCS_STATUS_HAS_UNTRACKED \
$z $VCS_STATUS_INDEX_SIZE $z $VCS_STATUS_LOCAL_BRANCH $z $VCS_STATUS_NUM_CONFLICTED \
$z $VCS_STATUS_NUM_STAGED $z $VCS_STATUS_NUM_UNSTAGED $z $VCS_STATUS_NUM_UNTRACKED \
$z $VCS_STATUS_REMOTE_BRANCH $z $VCS_STATUS_REMOTE_NAME $z $VCS_STATUS_REMOTE_URL \
$z $VCS_STATUS_RESULT $z $VCS_STATUS_STASHES $z $VCS_STATUS_TAG
2019-07-07 19:03:21 +02:00
}
function _p9k_vcs_status_restore( ) {
2019-07-08 16:54:26 +02:00
for VCS_STATUS_ACTION VCS_STATUS_COMMIT VCS_STATUS_COMMITS_AHEAD VCS_STATUS_COMMITS_BEHIND \
VCS_STATUS_HAS_CONFLICTED VCS_STATUS_HAS_STAGED VCS_STATUS_HAS_UNSTAGED \
VCS_STATUS_HAS_UNTRACKED VCS_STATUS_INDEX_SIZE VCS_STATUS_LOCAL_BRANCH \
VCS_STATUS_NUM_CONFLICTED VCS_STATUS_NUM_STAGED VCS_STATUS_NUM_UNSTAGED \
VCS_STATUS_NUM_UNTRACKED VCS_STATUS_REMOTE_BRANCH VCS_STATUS_REMOTE_NAME \
VCS_STATUS_REMOTE_URL VCS_STATUS_RESULT VCS_STATUS_STASHES VCS_STATUS_TAG \
2019-07-07 19:03:21 +02:00
in " ${ (@0)1 } " ; do done
}
function _p9k_vcs_status_for_dir( ) {
local dir = $1
while true; do
2019-07-24 14:34:26 +02:00
_p9k_ret = $_p9k_last_git_prompt [ $dir ]
2019-07-23 15:47:25 +02:00
[ [ -n $_p9k_ret ] ] && return 0
2019-07-07 19:03:21 +02:00
[ [ $dir = = / ] ] && return 1
dir = ${ dir : h }
done
}
function _p9k_vcs_status_purge( ) {
local dir = $1
while true; do
2019-07-19 14:27:16 +02:00
# unset doesn't work if $dir contains weird shit
2019-07-24 14:34:26 +02:00
_p9k_last_git_prompt[ $dir ] = ""
_p9k_git_slow[ $dir ] = ""
2019-07-07 19:03:21 +02:00
[ [ $dir = = / ] ] && break
dir = ${ dir : h }
done
}
2019-07-08 16:54:26 +02:00
function _p9k_vcs_icon( ) {
case " $VCS_STATUS_REMOTE_URL " in
2019-07-23 15:47:25 +02:00
*github*) _p9k_ret = VCS_GIT_GITHUB_ICON; ;
*bitbucket*) _p9k_ret = VCS_GIT_BITBUCKET_ICON; ;
*stash*) _p9k_ret = VCS_GIT_GITHUB_ICON; ;
*gitlab*) _p9k_ret = VCS_GIT_GITLAB_ICON; ;
*) _p9k_ret = VCS_GIT_ICON; ;
2019-07-08 16:54:26 +02:00
esac
}
2019-06-01 17:54:53 +02:00
function _p9k_vcs_render( ) {
2019-07-07 19:03:21 +02:00
local state
2019-07-24 14:34:26 +02:00
if ( ( $+_p9k_next_vcs_dir ) ) ; then
2019-08-07 08:38:04 +02:00
if _p9k_vcs_status_for_dir ${ ${ GIT_DIR : A } :- $_p9k_pwd_a } ; then
2019-07-23 15:47:25 +02:00
_p9k_vcs_status_restore $_p9k_ret
2019-07-07 19:03:21 +02:00
state = LOADING
2019-06-01 17:54:53 +02:00
else
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment prompt_vcs_LOADING " ${ __p9k_vcs_states [LOADING] } " " $_p9k_color1 " VCS_LOADING_ICON 0 '' " $_POWERLEVEL9K_VCS_LOADING_TEXT "
2019-07-07 19:03:21 +02:00
return 0
2019-06-01 17:54:53 +02:00
fi
2019-07-07 19:03:21 +02:00
elif [ [ $VCS_STATUS_RESULT != ok-* ] ] ; then
return 1
2019-06-01 17:54:53 +02:00
fi
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING ) ) ; then
2019-07-08 16:54:26 +02:00
if [ [ -z $state ] ] ; then
if [ [ $VCS_STATUS_HAS_STAGED != 0 || $VCS_STATUS_HAS_UNSTAGED != 0 ] ] ; then
state = MODIFIED
elif [ [ $VCS_STATUS_HAS_UNTRACKED != 0 ] ] ; then
state = UNTRACKED
else
state = CLEAN
fi
fi
_p9k_vcs_icon
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment prompt_vcs_$state " ${ __p9k_vcs_states [ $state ] } " " $_p9k_color1 " " $_p9k_ret " 0 '' ""
2019-07-08 16:54:26 +02:00
return 0
fi
2019-07-23 15:47:25 +02:00
( ( ${ _POWERLEVEL9K_VCS_GIT_HOOKS [(I)git-untracked] } ) ) || VCS_STATUS_HAS_UNTRACKED = 0
( ( ${ _POWERLEVEL9K_VCS_GIT_HOOKS [(I)git-aheadbehind] } ) ) || { VCS_STATUS_COMMITS_AHEAD = 0 && VCS_STATUS_COMMITS_BEHIND = 0 }
( ( ${ _POWERLEVEL9K_VCS_GIT_HOOKS [(I)git-stash] } ) ) || VCS_STATUS_STASHES = 0
( ( ${ _POWERLEVEL9K_VCS_GIT_HOOKS [(I)git-remotebranch] } ) ) || VCS_STATUS_REMOTE_BRANCH = ""
( ( ${ _POWERLEVEL9K_VCS_GIT_HOOKS [(I)git-tagname] } ) ) || VCS_STATUS_TAG = ""
2019-06-01 17:54:53 +02:00
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM >= 0 && VCS_STATUS_COMMITS_AHEAD > _POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM ) ) &&
VCS_STATUS_COMMITS_AHEAD = $_POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM
2019-06-04 10:39:21 +02:00
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM >= 0 && VCS_STATUS_COMMITS_BEHIND > _POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM ) ) &&
VCS_STATUS_COMMITS_BEHIND = $_POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM
2019-06-04 10:39:21 +02:00
2019-06-01 17:54:53 +02:00
local -a cache_key = (
" $VCS_STATUS_LOCAL_BRANCH "
" $VCS_STATUS_REMOTE_BRANCH "
" $VCS_STATUS_REMOTE_URL "
" $VCS_STATUS_ACTION "
" $VCS_STATUS_NUM_STAGED "
" $VCS_STATUS_NUM_UNSTAGED "
" $VCS_STATUS_NUM_UNTRACKED "
" $VCS_STATUS_HAS_STAGED "
" $VCS_STATUS_HAS_UNSTAGED "
" $VCS_STATUS_HAS_UNTRACKED "
" $VCS_STATUS_COMMITS_AHEAD "
" $VCS_STATUS_COMMITS_BEHIND "
" $VCS_STATUS_STASHES "
" $VCS_STATUS_TAG "
)
2019-07-23 15:47:25 +02:00
if [ [ $_POWERLEVEL9K_SHOW_CHANGESET = = 1 || -z $VCS_STATUS_LOCAL_BRANCH ] ] ; then
2019-06-01 17:54:53 +02:00
cache_key += $VCS_STATUS_COMMIT
fi
2019-07-24 21:07:28 +02:00
if ! _p9k_cache_get " $state " " ${ (@)cache_key } " ; then
2019-07-07 19:03:21 +02:00
local icon
2019-07-08 12:32:46 +02:00
local content
2019-06-01 17:54:53 +02:00
2019-07-23 15:47:25 +02:00
if ( ( ${ _POWERLEVEL9K_VCS_GIT_HOOKS [(I)vcs-detect-changes] } ) ) ; then
2019-06-01 17:54:53 +02:00
if [ [ $VCS_STATUS_HAS_STAGED != 0 || $VCS_STATUS_HAS_UNSTAGED != 0 ] ] ; then
2019-07-07 19:03:21 +02:00
: ${ state : =MODIFIED }
2019-06-01 17:54:53 +02:00
elif [ [ $VCS_STATUS_HAS_UNTRACKED != 0 ] ] ; then
2019-07-07 19:03:21 +02:00
: ${ state : =UNTRACKED }
2019-06-01 17:54:53 +02:00
fi
# It's weird that removing vcs-detect-changes from POWERLEVEL9K_VCS_GIT_HOOKS gets rid
# of the GIT icon. That's what vcs_info does, so we do the same in the name of compatiblity.
2019-07-03 14:07:11 +02:00
case " $VCS_STATUS_REMOTE_URL " in
*github*) icon = VCS_GIT_GITHUB_ICON; ;
*bitbucket*) icon = VCS_GIT_BITBUCKET_ICON; ;
*stash*) icon = VCS_GIT_GITHUB_ICON; ;
*gitlab*) icon = VCS_GIT_GITLAB_ICON; ;
*) icon = VCS_GIT_ICON; ;
esac
2019-06-01 17:54:53 +02:00
fi
2019-07-07 19:03:21 +02:00
: ${ state : =CLEAN }
function _$0 _fmt( ) {
2019-07-09 13:32:45 +02:00
_p9k_vcs_style $state $1
2019-07-23 15:47:25 +02:00
content += " $_p9k_ret $2 "
2019-07-07 19:03:21 +02:00
}
2019-06-01 17:54:53 +02:00
local ws
2019-07-23 15:47:25 +02:00
if [ [ $_POWERLEVEL9K_SHOW_CHANGESET = = 1 || -z $VCS_STATUS_LOCAL_BRANCH ] ] ; then
2019-07-09 12:40:31 +02:00
_p9k_get_icon prompt_vcs_$state VCS_COMMIT_ICON
2019-07-23 15:47:25 +02:00
_$0 _fmt COMMIT " $_p9k_ret ${ ${ VCS_STATUS_COMMIT : 0 : $_POWERLEVEL9K_CHANGESET_HASH_LENGTH } :- HEAD } "
2019-06-01 17:54:53 +02:00
ws = ' '
fi
if [ [ -n $VCS_STATUS_LOCAL_BRANCH ] ] ; then
2019-08-14 07:24:09 +02:00
local branch = $ws
if ( ( !_POWERLEVEL9K_HIDE_BRANCH_ICON ) ) ; then
_p9k_get_icon prompt_vcs_$state VCS_BRANCH_ICON
branch += $_p9k_ret
fi
if ( ( $+_POWERLEVEL9K_VCS_SHORTEN_LENGTH && $+_POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH &&
$# VCS_STATUS_LOCAL_BRANCH > _POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH &&
$# VCS_STATUS_LOCAL_BRANCH > _POWERLEVEL9K_VCS_SHORTEN_LENGTH ) ) &&
[ [ $_POWERLEVEL9K_VCS_SHORTEN_STRATEGY = = ( truncate_middle| truncate_from_right) ] ] ; then
branch += ${ VCS_STATUS_LOCAL_BRANCH [1,_POWERLEVEL9K_VCS_SHORTEN_LENGTH]// \% /%% } ${ _POWERLEVEL9K_VCS_SHORTEN_DELIMITER }
if [ [ $_POWERLEVEL9K_VCS_SHORTEN_STRATEGY = = truncate_middle ] ] ; then
_p9k_vcs_style $state BRANCH
branch += ${ _p9k_ret } ${ VCS_STATUS_LOCAL_BRANCH [-_POWERLEVEL9K_VCS_SHORTEN_LENGTH,-1]// \% /%% }
fi
else
branch += ${ VCS_STATUS_LOCAL_BRANCH // \% /%% }
fi
_$0 _fmt BRANCH $branch
2019-06-01 17:54:53 +02:00
fi
2019-07-23 15:47:25 +02:00
if [ [ $_POWERLEVEL9K_VCS_HIDE_TAGS = = 0 && -n $VCS_STATUS_TAG ] ] ; then
2019-07-09 12:40:31 +02:00
_p9k_get_icon prompt_vcs_$state VCS_TAG_ICON
2019-07-23 15:47:25 +02:00
_$0 _fmt TAG " $_p9k_ret ${ VCS_STATUS_TAG // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
if [ [ -n $VCS_STATUS_ACTION ] ] ; then
2019-06-20 13:34:20 +02:00
_$0 _fmt ACTION " | ${ VCS_STATUS_ACTION // \% /%% } "
2019-06-01 17:54:53 +02:00
else
if [ [ -n $VCS_STATUS_REMOTE_BRANCH &&
$VCS_STATUS_LOCAL_BRANCH != $VCS_STATUS_REMOTE_BRANCH ] ] ; then
2019-07-09 12:40:31 +02:00
_p9k_get_icon prompt_vcs_$state VCS_REMOTE_BRANCH_ICON
2019-07-23 15:47:25 +02:00
_$0 _fmt REMOTE_BRANCH " $_p9k_ret ${ VCS_STATUS_REMOTE_BRANCH // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
2019-06-20 18:50:07 +02:00
if [ [ $VCS_STATUS_HAS_STAGED = = 1 || $VCS_STATUS_HAS_UNSTAGED = = 1 || $VCS_STATUS_HAS_UNTRACKED = = 1 ] ] ; then
2019-07-09 12:40:31 +02:00
_p9k_get_icon prompt_vcs_$state VCS_DIRTY_ICON
2019-07-23 15:47:25 +02:00
_$0 _fmt DIRTY " $_p9k_ret "
2019-06-20 18:50:07 +02:00
if [ [ $VCS_STATUS_HAS_STAGED = = 1 ] ] ; then
2019-07-09 12:40:31 +02:00
_p9k_get_icon prompt_vcs_$state VCS_STAGED_ICON
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_VCS_STAGED_MAX_NUM != 1 ) ) && _p9k_ret += $VCS_STATUS_NUM_STAGED
_$0 _fmt STAGED " $_p9k_ret "
2019-06-20 18:50:07 +02:00
fi
if [ [ $VCS_STATUS_HAS_UNSTAGED = = 1 ] ] ; then
2019-07-09 12:40:31 +02:00
_p9k_get_icon prompt_vcs_$state VCS_UNSTAGED_ICON
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM != 1 ) ) && _p9k_ret += $VCS_STATUS_NUM_UNSTAGED
_$0 _fmt UNSTAGED " $_p9k_ret "
2019-06-20 18:50:07 +02:00
fi
if [ [ $VCS_STATUS_HAS_UNTRACKED = = 1 ] ] ; then
2019-07-09 12:40:31 +02:00
_p9k_get_icon prompt_vcs_$state VCS_UNTRACKED_ICON
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM != 1 ) ) && _p9k_ret += $VCS_STATUS_NUM_UNTRACKED
_$0 _fmt UNTRACKED " $_p9k_ret "
2019-06-20 18:50:07 +02:00
fi
2019-06-01 17:54:53 +02:00
fi
if [ [ $VCS_STATUS_COMMITS_BEHIND -gt 0 ] ] ; then
2019-07-09 12:40:31 +02:00
_p9k_get_icon prompt_vcs_$state VCS_INCOMING_CHANGES_ICON
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM != 1 ) ) && _p9k_ret += $VCS_STATUS_COMMITS_BEHIND
_$0 _fmt INCOMING_CHANGES " $_p9k_ret "
2019-06-01 17:54:53 +02:00
fi
2019-06-04 10:44:48 +02:00
if [ [ $VCS_STATUS_COMMITS_AHEAD -gt 0 ] ] ; then
2019-07-09 12:40:31 +02:00
_p9k_get_icon prompt_vcs_$state VCS_OUTGOING_CHANGES_ICON
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM != 1 ) ) && _p9k_ret += $VCS_STATUS_COMMITS_AHEAD
_$0 _fmt OUTGOING_CHANGES " $_p9k_ret "
2019-06-04 10:44:48 +02:00
fi
2019-06-01 17:54:53 +02:00
if [ [ $VCS_STATUS_STASHES -gt 0 ] ] ; then
2019-07-09 12:40:31 +02:00
_p9k_get_icon prompt_vcs_$state VCS_STASH_ICON
2019-07-23 15:47:25 +02:00
_$0 _fmt STASH " $_p9k_ret $VCS_STATUS_STASHES "
2019-06-01 17:54:53 +02:00
fi
fi
2019-07-24 21:07:28 +02:00
_p9k_cache_set " prompt_vcs_ $state " " ${ __p9k_vcs_states [ $state ] } " " $_p9k_color1 " " $icon " 0 '' " $content "
2019-06-01 17:54:53 +02:00
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $_p9k_cache_val [@] "
2019-06-01 17:54:53 +02:00
return 0
}
function _p9k_vcs_resume( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-06-01 17:54:53 +02:00
if [ [ $VCS_STATUS_RESULT = = ok-async ] ] ; then
2019-07-24 14:34:26 +02:00
local latency = $(( EPOCHREALTIME - _p9k_gitstatus_start_time))
2019-07-23 15:47:25 +02:00
if ( ( latency > _POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS ) ) ; then
2019-07-24 14:34:26 +02:00
_p9k_git_slow[ $VCS_STATUS_WORKDIR ] = 1
2019-07-23 15:47:25 +02:00
elif ( ( $1 && latency < 0.8 * _POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS ) ) ; then # 0.8 to avoid flip-flopping
2019-07-24 14:34:26 +02:00
_p9k_git_slow[ $VCS_STATUS_WORKDIR ] = 0
2019-06-01 17:54:53 +02:00
fi
2019-07-07 19:03:21 +02:00
_p9k_vcs_status_save
2019-06-01 17:54:53 +02:00
fi
2019-07-24 14:34:26 +02:00
if [ [ -z $_p9k_next_vcs_dir ] ] ; then
unset _p9k_next_vcs_dir
2019-06-01 17:54:53 +02:00
case $VCS_STATUS_RESULT in
2019-08-07 08:38:04 +02:00
norepo-async) ( ( $1 ) ) && _p9k_vcs_status_purge ${ ${ GIT_DIR : A } :- $_p9k_pwd_a } ; ;
ok-async) ( ( $1 ) ) || _p9k_next_vcs_dir = ${ ${ GIT_DIR : A } :- $_p9k_pwd_a } ; ;
2019-06-01 17:54:53 +02:00
esac
fi
2019-07-07 19:03:21 +02:00
2019-07-24 14:34:26 +02:00
if [ [ -n $_p9k_next_vcs_dir ] ] ; then
if ! gitstatus_query -d $_p9k_next_vcs_dir -t 0 -c '_p9k_vcs_resume 1' POWERLEVEL9K; then
unset _p9k_next_vcs_dir
2019-07-07 19:03:21 +02:00
unset VCS_STATUS_RESULT
else
case $VCS_STATUS_RESULT in
2019-07-24 14:34:26 +02:00
tout) _p9k_next_vcs_dir = '' ; _p9k_gitstatus_start_time = $EPOCHREALTIME ; ;
norepo-sync) _p9k_vcs_status_purge $_p9k_next_vcs_dir ; unset _p9k_next_vcs_dir; ;
ok-sync) _p9k_vcs_status_save; unset _p9k_next_vcs_dir; ;
2019-07-07 19:03:21 +02:00
esac
fi
fi
_p9k_update_prompt gitstatus
2019-06-01 17:54:53 +02:00
}
function _p9k_vcs_gitstatus( ) {
2019-07-24 14:34:26 +02:00
if [ [ $_p9k_refresh_reason = = precmd ] ] ; then
if ( ( $+_p9k_next_vcs_dir ) ) ; then
2019-08-07 08:38:04 +02:00
_p9k_next_vcs_dir = ${ ${ GIT_DIR : A } :- $_p9k_pwd_a }
2019-06-01 17:54:53 +02:00
else
2019-08-07 08:38:04 +02:00
local dir = ${ ${ GIT_DIR : A } :- $_p9k_pwd_a }
2019-07-23 15:47:25 +02:00
local -F timeout = _POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS
2019-07-07 19:03:21 +02:00
if ! _p9k_vcs_status_for_dir $dir ; then
gitstatus_query -d $dir -t $timeout -p -c '_p9k_vcs_resume 0' POWERLEVEL9K || return 1
case $VCS_STATUS_RESULT in
2019-07-24 14:34:26 +02:00
tout) _p9k_next_vcs_dir = '' ; _p9k_gitstatus_start_time = $EPOCHREALTIME ; return 0; ;
2019-07-07 19:03:21 +02:00
norepo-sync) return 0; ;
ok-sync) _p9k_vcs_status_save; ;
2019-06-01 17:54:53 +02:00
esac
2019-07-07 19:03:21 +02:00
else
while true; do
2019-07-24 14:34:26 +02:00
case $_p9k_git_slow [ $dir ] in
2019-07-07 19:03:21 +02:00
"" ) [ [ $dir = = / ] ] && break; dir = ${ dir : h } ; ;
0) break; ;
1) timeout = 0; break; ;
esac
done
2019-08-07 08:38:04 +02:00
dir = ${ ${ GIT_DIR : A } :- $_p9k_pwd_a }
2019-07-07 19:03:21 +02:00
fi
if ! gitstatus_query -d $dir -t $timeout -c '_p9k_vcs_resume 1' POWERLEVEL9K; then
unset VCS_STATUS_RESULT
return 1
fi
case $VCS_STATUS_RESULT in
2019-07-24 14:34:26 +02:00
tout) _p9k_next_vcs_dir = '' ; _p9k_gitstatus_start_time = $EPOCHREALTIME ; ;
2019-07-07 19:03:21 +02:00
norepo-sync) _p9k_vcs_status_purge $dir ; ;
ok-sync) _p9k_vcs_status_save; ;
esac
2019-06-01 17:54:53 +02:00
fi
fi
return 0
}
################################################################
# Segment to show VCS information
prompt_vcs( ) {
2019-07-23 15:47:25 +02:00
local -a backends = ( $_POWERLEVEL9K_VCS_BACKENDS )
2019-08-05 10:37:04 +02:00
if ( ( ${ backends [(I)git] } && !_POWERLEVEL9K_DISABLE_GITSTATUS ) ) && _p9k_vcs_gitstatus; then
2019-07-24 21:07:28 +02:00
_p9k_vcs_render && return
2019-06-01 17:54:53 +02:00
backends = ( ${ backends : #git } )
fi
if ( ( $# backends ) ) ; then
VCS_WORKDIR_DIRTY = false
VCS_WORKDIR_HALF_DIRTY = false
local current_state = ""
# Actually invoke vcs_info manually to gather all information.
zstyle ':vcs_info:*' enable ${ backends }
vcs_info
local vcs_prompt = " ${ vcs_info_msg_0_ } "
if [ [ -n " $vcs_prompt " ] ] ; then
if [ [ " $VCS_WORKDIR_DIRTY " = = true ] ] ; then
# $vcs_visual_identifier gets set in +vi-vcs-detect-changes in functions/vcs.zsh,
# as we have there access to vcs_info internal hooks.
2019-07-09 16:08:43 +02:00
current_state = 'MODIFIED'
2019-06-01 17:54:53 +02:00
else
if [ [ " $VCS_WORKDIR_HALF_DIRTY " = = true ] ] ; then
2019-07-09 16:08:43 +02:00
current_state = 'UNTRACKED'
2019-06-01 17:54:53 +02:00
else
2019-07-09 16:08:43 +02:00
current_state = 'CLEAN'
2019-06-01 17:54:53 +02:00
fi
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " ${ 0 } _ ${ (U)current_state } " " ${ __p9k_vcs_states [ $current_state ] } " " $_p9k_color1 " " $vcs_visual_identifier " 0 '' " $vcs_prompt "
2019-06-01 17:54:53 +02:00
fi
fi
}
################################################################
# Vi Mode: show editing mode (NORMAL|INSERT|VISUAL)
prompt_vi_mode( ) {
2019-07-23 15:47:25 +02:00
if [ [ -n $_POWERLEVEL9K_VI_INSERT_MODE_STRING ] ] ; then
2019-07-27 00:19:04 +02:00
_p9k_prompt_segment $0 _INSERT " $_p9k_color1 " blue '' 0 '${${KEYMAP:-0}:#(vicmd|vivis|vivli)}' " $_POWERLEVEL9K_VI_INSERT_MODE_STRING "
2019-06-01 17:54:53 +02:00
fi
2019-07-23 15:47:25 +02:00
if ( ( $+_POWERLEVEL9K_VI_VISUAL_MODE_STRING ) ) ; then
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment $0 _NORMAL " $_p9k_color1 " white '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#vicmd0}' " $_POWERLEVEL9K_VI_COMMAND_MODE_STRING "
2019-07-27 00:19:04 +02:00
_p9k_prompt_segment $0 _VISUAL " $_p9k_color1 " white '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#(vicmd1|vivis?|vivli?)}' " $_POWERLEVEL9K_VI_VISUAL_MODE_STRING "
2019-07-12 11:55:32 +02:00
else
2019-07-27 00:19:04 +02:00
_p9k_prompt_segment $0 _NORMAL " $_p9k_color1 " white '' 0 '${(M)KEYMAP:#(vicmd|vivis|vivli)}' " $_POWERLEVEL9K_VI_COMMAND_MODE_STRING "
2019-07-12 11:55:32 +02:00
fi
2019-06-01 17:54:53 +02:00
}
################################################################
# Virtualenv: current working virtualenv
# More information on virtualenv (Python):
# https://virtualenv.pypa.io/en/latest/
prompt_virtualenv( ) {
2019-06-20 09:37:40 +02:00
[ [ -n $VIRTUAL_ENV ] ] || return
local msg = ''
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION ) ) && _p9k_python_version; then
2019-07-29 16:10:28 +02:00
msg = " ${ _p9k_ret // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
2019-07-23 15:47:25 +02:00
msg += " $_POWERLEVEL9K_VIRTUALENV_LEFT_DELIMITER ${ ${ VIRTUAL_ENV : t } // \% /%% } $_POWERLEVEL9K_VIRTUALENV_RIGHT_DELIMITER "
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "blue" " $_p9k_color1 " 'PYTHON_ICON' 0 '' " $msg "
2019-06-01 17:54:53 +02:00
}
function _p9k_read_pyenv_version_file( ) {
[ [ -r $1 ] ] || return
local content
2019-08-02 07:07:23 +02:00
IFS = '' read -rd $'\0' content <$1 2>/dev/null
2019-07-23 15:47:25 +02:00
_p9k_ret = ${ ${ (j. : .) ${ (@) ${ =content } #python- } :- system } }
2019-06-01 17:54:53 +02:00
}
function _p9k_pyenv_global_version( ) {
2019-07-23 15:47:25 +02:00
_p9k_read_pyenv_version_file ${ PYENV_ROOT :- $HOME /.pyenv } /version || _p9k_ret = system
2019-06-01 17:54:53 +02:00
}
################################################################
# Segment to display pyenv information
# https://github.com/pyenv/pyenv#choosing-the-python-version
prompt_pyenv( ) {
2019-08-13 08:17:27 +02:00
( ( $+commands[ pyenv] || $+functions[ pyenv] ) ) || return
2019-06-01 17:54:53 +02:00
local v = ${ (j. : .) ${ (@) ${ (s. : .)PYENV_VERSION } #python- } }
if [ [ -z $v ] ] ; then
2019-08-12 08:56:47 +02:00
[ [ $PYENV_DIR = = /* ] ] && local dir = $PYENV_DIR || local dir = " $_p9k_pwd_a / $PYENV_DIR "
2019-06-01 17:54:53 +02:00
while true; do
if _p9k_read_pyenv_version_file $dir /.python-version; then
2019-07-23 15:47:25 +02:00
v = $_p9k_ret
2019-06-01 17:54:53 +02:00
break
fi
if [ [ $dir = = / ] ] ; then
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW ) ) || return
2019-06-01 17:54:53 +02:00
_p9k_pyenv_global_version
2019-07-23 15:47:25 +02:00
v = $_p9k_ret
2019-06-01 17:54:53 +02:00
break
fi
dir = ${ dir : h }
done
fi
2019-07-23 15:47:25 +02:00
if ( ( !_POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW ) ) ; then
2019-06-01 17:54:53 +02:00
_p9k_pyenv_global_version
2019-07-23 15:47:25 +02:00
[ [ $v = = $_p9k_ret ] ] && return
2019-06-01 17:54:53 +02:00
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "blue" " $_p9k_color1 " 'PYTHON_ICON' 0 '' " ${ v // \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Display openfoam information
prompt_openfoam( ) {
local wm_project_version = " $WM_PROJECT_VERSION "
local wm_fork = " $WM_FORK "
if [ [ -n " $wm_project_version " && -z " $wm_fork " ] ] ; then
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "yellow" " $_p9k_color1 " '' 0 '' " OF: ${ ${ wm_project_version : t } // \% /%% } "
2019-06-01 17:54:53 +02:00
elif [ [ -n " $wm_project_version " && -n " $wm_fork " ] ] ; then
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "yellow" " $_p9k_color1 " '' 0 '' " F-X: ${ ${ wm_project_version : t } // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# Segment to display Swift version
prompt_swift_version( ) {
_p9k_cached_cmd_stdout swift --version || return
2019-07-23 15:47:25 +02:00
[ [ $_p9k_ret = = ( #b)[^[:digit:]]#([[:digit:].]##)* ]] || return
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "magenta" "white" 'SWIFT_ICON' 0 '' " ${ match [1]// \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# dir_writable: Display information about the user's permission to write in the current directory
prompt_dir_writable( ) {
2019-08-07 08:38:04 +02:00
if [ [ ! -w " $_p9k_pwd " ] ] ; then
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 _FORBIDDEN " "red" "yellow1" 'LOCK_ICON' 0 '' ''
2019-06-01 17:54:53 +02:00
fi
}
################################################################
# Kubernetes Current Context/Namespace
prompt_kubecontext( ) {
( ( $+commands[ kubectl] ) ) || return
2019-07-30 09:02:46 +02:00
2019-06-01 17:54:53 +02:00
local cfg
local -a key
for cfg in ${ (s. : .) ${ KUBECONFIG :- $HOME /.kube/config } } ; do
local -H stat
zstat -H stat -- $cfg 2>/dev/null || continue
key += ( $cfg $stat [ inode] $stat [ mtime] $stat [ size] $stat [ mode] )
done
if ! _p9k_cache_get $0 " ${ key [@] } " ; then
2019-07-30 09:02:46 +02:00
local name namespace cluster cloud_name cloud_account cloud_zone cloud_cluster text state
2019-07-29 21:56:15 +02:00
( ) {
2019-07-30 07:52:26 +02:00
local cfg && cfg = ( ${ (f) " $( kubectl config view -o= yaml 2>/dev/null) " } ) || return
2019-07-30 07:55:18 +02:00
local ctx = ( ${ (@M)cfg : #current-context : [^ \" \' \| \> ]* } )
2019-07-29 21:56:15 +02:00
( ( $# ctx = = 1 ) ) || return
2019-07-30 09:02:46 +02:00
name = ${ ctx [1]#current-context : }
2019-07-29 21:56:15 +02:00
local -i pos = ${ cfg [(i)contexts : ] }
( ( pos <= $# cfg ) ) || return
shift $pos cfg
2019-07-30 09:02:46 +02:00
pos = ${ cfg [(i) name : $name ] }
2019-07-29 21:56:15 +02:00
( ( pos <= $# cfg ) ) || return
( ( --pos ) )
for ( ( ; pos > 0; --pos) ) ; do
local line = $cfg [ pos]
2019-07-30 07:52:26 +02:00
if [ [ $line = = '- context:' ] ] ; then
return
elif [ [ $line = = ( #b)' cluster: '([^\"\'\|\>]*) ]]; then
cluster = $match [ 1]
elif [ [ $line = = ( #b)' namespace: '([^\"\'\|\>]*) ]]; then
namespace = $match [ 1]
fi
2019-07-29 21:56:15 +02:00
done
}
2019-07-30 09:02:46 +02:00
if [ [ -n $name ] ] ; then
2019-07-30 09:38:27 +02:00
: ${ namespace : =default }
2019-07-30 09:02:46 +02:00
# gke_my-account_us-east1-a_cluster-01
2019-07-30 20:00:00 +02:00
# gke_my-account_us-east1_cluster-01
if [ [ $cluster = = ( #b)gke_(?*)_(asia|australia|europe|northamerica|southamerica|us)-([a-z]##<->)(-[a-z]|)_(?*) ]]; then
2019-07-30 09:02:46 +02:00
cloud_name = gke
cloud_account = $match [ 1]
2019-07-30 20:00:00 +02:00
cloud_zone = $match [ 2] -$match [ 3] -$match [ 4]
cloud_cluster = $match [ 5]
2019-07-30 17:24:46 +02:00
if ( ( ${ _POWERLEVEL9K_KUBECONTEXT_SHORTEN [(I)gke] } ) ) ; then
2019-07-30 09:02:46 +02:00
text = $cloud_cluster
fi
# arn:aws:eks:us-east-1:123456789012:cluster/cluster-01
elif [ [ $cluster = = ( #b)arn:aws:eks:([[:alnum:]-]##):([[:digit:]]##):cluster/(?*) ]]; then
cloud_name = eks
cloud_zone = $match [ 1]
cloud_account = $match [ 2]
cloud_cluster = $match [ 3]
2019-07-30 17:24:46 +02:00
if ( ( ${ _POWERLEVEL9K_KUBECONTEXT_SHORTEN [(I)eks] } ) ) ; then
2019-07-30 09:02:46 +02:00
text = $cloud_cluster
fi
fi
if [ [ -z $text ] ] ; then
text = $name
2019-07-30 09:38:27 +02:00
if [ [ $_POWERLEVEL9K_KUBECONTEXT_SHOW_DEFAULT_NAMESPACE = = 1 || $namespace != ( default| $name ) ] ] ; then
text += " / $namespace "
2019-07-30 09:02:46 +02:00
fi
fi
2019-06-01 17:54:53 +02:00
local pat class
2019-07-23 15:47:25 +02:00
for pat class in " ${ _POWERLEVEL9K_KUBECONTEXT_CLASSES [@] } " ; do
2019-07-29 21:56:15 +02:00
if [ [ $text = = ${ ~pat } ] ] ; then
2019-07-30 09:02:46 +02:00
[ [ -n $class ] ] && state = _${ (U)class }
2019-06-01 17:54:53 +02:00
break
fi
done
fi
2019-07-30 09:02:46 +02:00
_p9k_cache_set " $name " " $namespace " " $cluster " " $cloud_name " " $cloud_account " " $cloud_zone " " $cloud_cluster " " $text " " $state "
2019-06-01 17:54:53 +02:00
fi
2019-07-30 09:02:46 +02:00
2019-07-29 21:56:15 +02:00
typeset -g P9K_KUBECONTEXT_NAME = $_p9k_cache_val [ 1]
2019-07-30 09:02:46 +02:00
typeset -g P9K_KUBECONTEXT_NAMESPACE = $_p9k_cache_val [ 2]
typeset -g P9K_KUBECONTEXT_CLUSTER = $_p9k_cache_val [ 3]
typeset -g P9K_KUBECONTEXT_CLOUD_NAME = $_p9k_cache_val [ 4]
typeset -g P9K_KUBECONTEXT_CLOUD_ACCOUNT = $_p9k_cache_val [ 5]
typeset -g P9K_KUBECONTEXT_CLOUD_ZONE = $_p9k_cache_val [ 6]
typeset -g P9K_KUBECONTEXT_CLOUD_CLUSTER = $_p9k_cache_val [ 7]
[ [ -n $_p9k_cache_val [ 8] ] ] || return
_p9k_prompt_segment $0 $_p9k_cache_val [ 9] magenta white KUBERNETES_ICON 0 '' " ${ _p9k_cache_val [8]// \% /%% } "
2019-06-01 17:54:53 +02:00
}
################################################################
# Dropbox status
prompt_dropbox( ) {
( ( $+commands[ dropbox-cli] ) ) || return
# The first column is just the directory, so cut it
2019-07-24 15:52:54 +02:00
local dropbox_status = " $( dropbox-cli filestatus . | cut -d\ -f2-) "
2019-06-01 17:54:53 +02:00
# Only show if the folder is tracked and dropbox is running
if [ [ " $dropbox_status " != 'unwatched' && " $dropbox_status " != "isn't running!" ] ] ; then
# If "up to date", only show the icon
if [ [ " $dropbox_status " = ~ 'up to date' ] ] ; then
dropbox_status = ""
fi
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "white" "blue" "DROPBOX_ICON" 0 '' " ${ dropbox_status // \% /%% } "
2019-06-01 17:54:53 +02:00
fi
}
# print Java version number
prompt_java_version( ) {
_p9k_cached_cmd_stdout_stderr java -fullversion || return
2019-07-23 15:47:25 +02:00
local v = $_p9k_ret
2019-06-01 17:54:53 +02:00
v = ${ ${ v #* \" } % \" * }
2019-07-23 15:47:25 +02:00
( ( _POWERLEVEL9K_JAVA_VERSION_FULL ) ) || v = ${ v %%-* }
2019-06-01 17:54:53 +02:00
[ [ -n $v ] ] || return
2019-07-24 21:07:28 +02:00
_p9k_prompt_segment " $0 " "red" "white" "JAVA_ICON" 0 '' " ${ v // \% /%% } "
2019-06-01 17:54:53 +02:00
}
2019-07-25 14:11:04 +02:00
typeset -gra __p9k_nordvpn_tag = (
P9K_NORDVPN_STATUS
2019-08-01 23:18:13 +02:00
P9K_NORDVPN_TECHNOLOGY
2019-07-25 14:11:04 +02:00
P9K_NORDVPN_PROTOCOL
P9K_NORDVPN_IP_ADDRESS
P9K_NORDVPN_SERVER
P9K_NORDVPN_COUNTRY
P9K_NORDVPN_CITY
)
function _p9k_fetch_nordvpn_status( ) {
setopt err_return
local REPLY
2019-07-25 17:54:12 +02:00
zsocket /run/nordvpnd.sock
2019-07-25 14:11:04 +02:00
local -i fd = $REPLY
{
>& $fd echo -nE - $'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n\0\0\0\4\1\0\0\0\0\0\0N\1\4\0\0\0\1\203\206E\221bA\226\223\325\\k\337\31i=LnH\323j?A\223\266\243y\270\303\fYmLT{$\357]R.\203\223\257_\213\35u\320b\r&=LMedz\212\232\312\310\264\307`+\210K\203@\2te\206M\2035\5\261\37\0\0\5\0\1\0\0\0\1\0\0\0\0\0'
local tag len val
local -i n
2019-07-25 17:54:12 +02:00
IFS = '' read -t 0.25 -r tag <& 3
2019-07-25 14:11:04 +02:00
tag = $'\015'
while true; do
2019-08-20 14:22:27 +02:00
tag = $(( #tag))
2019-07-25 14:11:04 +02:00
( ( ( tag >>= 3) && tag <= $# __p9k_nordvpn_tag ) ) || break
tag = $__p9k_nordvpn_tag [ tag]
2019-07-25 17:54:12 +02:00
sysread -c n -s 1 -t 0.25 len <& 3
2019-08-20 14:22:27 +02:00
len = $(( #len))
2019-07-25 14:11:04 +02:00
val =
( ( ! len ) ) || {
2019-07-25 17:54:12 +02:00
sysread -c n -s $len -t 0.25 val <& 3
2019-07-25 14:11:04 +02:00
( ( n = = len ) )
}
typeset -g $tag = $val
2019-07-25 17:54:12 +02:00
sysread -c n -s 1 -t 0.25 tag <& 3
2019-07-25 14:11:04 +02:00
done
} always {
exec { fd} >& -
}
}
2019-07-26 10:20:40 +02:00
# Shows the state of NordVPN connection. Works only on Linux. Can be in the following 5 states.
#
# MISSING: NordVPN is not installed or nordvpnd is not running. By default the segment is not
# shown in this state. To make it visible, override POWERLEVEL9K_NORDVPN_MISSING_CONTENT_EXPANSION
# and/or POWERLEVEL9K_NORDVPN_MISSING_VISUAL_IDENTIFIER_EXPANSION.
#
# # Display this icon when NordVPN is not installed or nordvpnd is not running
# POWERLEVEL9K_NORDVPN_MISSING_VISUAL_IDENTIFIER_EXPANSION='⭐'
#
# CONNECTED: NordVPN is connected. By default shows LOCK_ICON as icon and country code as content.
# In addition, the following variables are set for the use by
# POWERLEVEL9K_NORDVPN_CONNECTED_VISUAL_IDENTIFIER_EXPANSION and
# POWERLEVEL9K_NORDVPN_CONNECTED_CONTENT_EXPANSION:
#
# - P9K_NORDVPN_STATUS
# - P9K_NORDVPN_PROTOCOL
2019-08-01 23:18:13 +02:00
# - P9K_NORDVPN_TECHNOLOGY
2019-07-26 10:20:40 +02:00
# - P9K_NORDVPN_IP_ADDRESS
# - P9K_NORDVPN_SERVER
# - P9K_NORDVPN_COUNTRY
# - P9K_NORDVPN_CITY
# - P9K_NORDVPN_COUNTRY_CODE
#
# The last variable is trivially derived from P9K_NORDVPN_SERVER. The rest correspond to the output
# lines of `nordvpn status` command. Example of using these variables:
#
# # Display the name of the city where VPN servers are located when connected to NordVPN.
# POWERLEVEL9K_NORDVPN_CONNECTED_CONTENT_EXPANSION='${P9K_NORDVPN_CITY}'
#
# DISCONNECTED, CONNECTING, DISCONNECTING: NordVPN is disconnected/connecting/disconnecting. By
# default shows LOCK_ICON as icon and FAIL_ICON as content. In state CONNECTING the same
# P9K_NORDVPN_* variables are set as in CONNECTED. In states DISCONNECTED and DISCONNECTING only
# P9K_NORDVPN_STATUS is set. Example customizations:
#
# # Hide NordVPN segment when disconnected (segments with no icon and no content are not shown).
# POWERLEVEL9K_NORDVPN_DISCONNECTED_CONTENT_EXPANSION=
# POWERLEVEL9K_NORDVPN_DISCONNECTED_VISUAL_IDENTIFIER_EXPANSION=
#
# # When NordVPN is connecting, show country code on cyan background.
# POWERLEVEL9K_NORDVPN_CONNECTING_CONTENT_EXPANSION='${P9K_NORDVPN_COUNTRY_CODE}'
# POWERLEVEL9K_NORDVPN_CONNECTING_BACKGROUND=cyan
2019-07-25 14:11:04 +02:00
function prompt_nordvpn( ) {
2019-07-25 17:54:12 +02:00
unset $__p9k_nordvpn_tag P9K_NORDVPN_COUNTRY_CODE
if [ [ $+commands[ nordvpn] = = 1 && -e /run/nordvpnd.sock ] ] ; then
_p9k_fetch_nordvpn_status 2>/dev/null
if [ [ $P9K_NORDVPN_SERVER = = ( #b)([[:alpha:]]##)[[:digit:]]##.nordvpn.com ]]; then
typeset -g P9K_NORDVPN_COUNTRY_CODE = ${ (U)match[1] }
fi
fi
2019-07-25 14:11:04 +02:00
case $P9K_NORDVPN_STATUS in
Connected)
2019-07-26 10:20:40 +02:00
_p9k_prompt_segment $0 _CONNECTED blue white LOCK_ICON 0 '' " $P9K_NORDVPN_COUNTRY_CODE " ; ;
Disconnected| Connecting| Disconnecting)
local state = ${ (U)P9K_NORDVPN_STATUS }
_p9k_get_icon $0 _$state FAIL_ICON
_p9k_prompt_segment $0 _$state yellow white LOCK_ICON 0 '' " $_p9k_ret " ; ;
2019-07-25 14:11:04 +02:00
*)
2019-07-26 10:20:40 +02:00
_p9k_prompt_segment $0 _MISSING blue white '' 0 '' '' ; ;
2019-07-25 14:11:04 +02:00
esac
}
2019-08-17 10:01:06 +02:00
function prompt_ranger( ) {
[ [ -n $RANGER_LEVEL ] ] || return
_p9k_prompt_segment $0 $_p9k_color1 yellow RANGER_ICON 0 '' $RANGER_LEVEL
}
2019-08-19 16:07:59 +02:00
function prompt_terraform( ) {
( ( $+commands[ terraform] ) ) || return
local ws = default
if [ [ -n $TF_WORKSPACE ] ] ; then
ws = $TF_WORKSPACE
else
local f = ${ TF_DATA_DIR :- .terraform } /environment
[ [ -r $f ] ] && _p9k_read_file $f && ws = $_p9k_ret
fi
2019-08-19 16:35:26 +02:00
ws = ${ ${ ws ##[[ : space : ]]# } %%[[ : space : ]]# }
2019-08-19 16:07:59 +02:00
[ [ $ws = = default ] ] || _p9k_prompt_segment $0 $_p9k_color1 blue TERRAFORM_ICON 0 '' $ws
}
2019-07-24 21:07:28 +02:00
_p9k_preexec( ) {
2019-07-24 19:11:43 +02:00
if ( ( $+_p9k_real_zle_rprompt_indent ) ) ; then
2019-07-24 14:34:26 +02:00
if [ [ -n $_p9k_real_zle_rprompt_indent ] ] ; then
ZLE_RPROMPT_INDENT = $_p9k_real_zle_rprompt_indent
2019-06-14 16:14:04 +02:00
else
unset ZLE_RPROMPT_INDENT
fi
2019-07-24 19:11:43 +02:00
unset _p9k_real_zle_rprompt_indent
2019-06-14 16:14:04 +02:00
fi
2019-07-27 12:09:09 +02:00
_p9k_preexec_cmd = $2
_p9k_timer_start = EPOCHREALTIME
2019-06-14 16:14:04 +02:00
}
2019-06-01 17:54:53 +02:00
2019-07-16 16:19:16 +02:00
function _p9k_build_segment( ) {
2019-07-24 14:34:26 +02:00
_p9k_segment_name = ${ _p9k_segment_name %_joined }
if [ [ $_p9k_segment_name = = custom_* ] ] ; then
2019-07-24 21:07:28 +02:00
_p9k_custom_prompt $_p9k_segment_name [ 8,-1]
2019-07-24 14:34:26 +02:00
elif ( ( $+functions[ prompt_$_p9k_segment_name ] ) ) ; then
2019-07-24 21:07:28 +02:00
prompt_$_p9k_segment_name
2019-07-16 16:19:16 +02:00
fi
2019-07-24 14:34:26 +02:00
( ( ++_p9k_segment_index) )
2019-07-16 16:19:16 +02:00
}
2019-06-01 17:54:53 +02:00
function _p9k_set_prompt( ) {
2019-08-02 07:07:23 +02:00
local ifs = $IFS
IFS = $' \t\n\0'
2019-08-07 08:38:04 +02:00
_p9k_pwd = ${ (%) :- %/ }
_p9k_pwd_a = ${ _p9k_pwd : A }
2019-07-24 14:34:26 +02:00
PROMPT = $_p9k_prompt_prefix_left
2019-06-01 17:54:53 +02:00
RPROMPT =
2019-07-24 14:34:26 +02:00
local -i left_idx = 1 right_idx = 1 num_lines = $# _p9k_line_segments_left i
2019-07-16 16:19:16 +02:00
for i in { 1..$num_lines } ; do
2019-07-18 12:21:54 +02:00
local right =
2019-07-23 15:47:25 +02:00
if ( ( !_POWERLEVEL9K_DISABLE_RPROMPT ) ) ; then
2019-07-24 14:34:26 +02:00
_p9k_dir =
_p9k_prompt =
_p9k_segment_index = right_idx
_p9k_prompt_side = right
for _p9k_segment_name in ${ (@0)_p9k_line_segments_right[i] } ; do
2019-07-16 16:19:16 +02:00
_p9k_build_segment
done
2019-07-24 14:34:26 +02:00
right_idx = _p9k_segment_index
if [ [ -n $_p9k_prompt || $_p9k_line_never_empty_right [ i] = = 1 ] ] ; then
right = $_p9k_line_prefix_right [ i] $_p9k_prompt $_p9k_line_suffix_right [ i]
2019-07-16 16:19:16 +02:00
fi
fi
2019-07-24 14:34:26 +02:00
unset _p9k_dir
_p9k_prompt = $_p9k_line_prefix_left [ i]
_p9k_segment_index = left_idx
_p9k_prompt_side = left
for _p9k_segment_name in ${ (@0)_p9k_line_segments_left[i] } ; do
2019-07-16 16:19:16 +02:00
_p9k_build_segment
done
2019-07-24 14:34:26 +02:00
left_idx = _p9k_segment_index
_p9k_prompt += $_p9k_line_suffix_left [ i]
if ( ( $+_p9k_dir || ( i != num_lines && $# right) ) ) ; then
2019-07-27 12:09:09 +02:00
PROMPT += '${${:-${_p9k_d::=0}${_p9k_rprompt::='
[ [ -o transient_rprompt ] ] && PROMPT += '${_p9k_line_finished-' $right '}' || PROMPT += $right
PROMPT += '}${_p9k_lprompt::=' $_p9k_prompt '}}+}'
2019-07-24 14:34:26 +02:00
PROMPT += $_p9k_gap_pre
if ( ( $+_p9k_dir ) ) ; then
2019-07-23 15:47:25 +02:00
if ( ( i = = num_lines && ( _POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS > 0 || _POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT > 0) ) ) ; then
local a = $_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS
2019-07-24 14:34:26 +02:00
local f = $(( 0 .01*_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT)) '*_p9k_clm'
PROMPT += " \${\${_p9k_g::= $(( ( $a <$f ) * $f + ( $a >= $f ) * $a )) }+} "
2019-07-19 13:29:54 +02:00
else
2019-07-24 14:34:26 +02:00
PROMPT += '${${_p9k_g::=0}+}'
2019-07-19 13:29:54 +02:00
fi
2019-07-23 15:47:25 +02:00
if [ [ $_POWERLEVEL9K_DIR_MAX_LENGTH = = <->( '%' | ) ] ] ; then
2019-07-19 13:29:54 +02:00
local lim
2019-07-23 15:47:25 +02:00
if [ [ $_POWERLEVEL9K_DIR_MAX_LENGTH [ -1] = = '%' ] ] ; then
2019-07-24 14:34:26 +02:00
lim = " $_p9k_dir_len - $(( 0 .01*$_POWERLEVEL9K_DIR_MAX_LENGTH [ 1 ,-2] )) *_p9k_clm "
2019-07-19 13:29:54 +02:00
else
2019-07-24 14:34:26 +02:00
lim = $(( _p9k_dir_len-_POWERLEVEL9K_DIR_MAX_LENGTH))
2019-07-19 13:29:54 +02:00
( ( lim <= 0) ) && lim =
fi
if [ [ -n $lim ] ] ; then
2019-07-24 14:34:26 +02:00
PROMPT += '${${${$((_p9k_g<_p9k_m+' $lim ')):#1}:-${_p9k_g::=$((_p9k_m+' $lim '))}}+}'
2019-07-19 13:29:54 +02:00
fi
2019-07-18 12:49:32 +02:00
fi
2019-07-24 14:34:26 +02:00
PROMPT += '${${_p9k_d::=$((_p9k_m-_p9k_g))}+}'
PROMPT += '${_p9k_lprompt/\%\{d\%\}*\%\{d\%\}/' $_p9k_dir '}'
PROMPT += '${${_p9k_m::=$((_p9k_d+_p9k_g))}+}'
2019-07-18 12:49:32 +02:00
else
2019-07-24 14:34:26 +02:00
PROMPT += '${_p9k_lprompt}'
2019-07-18 12:49:32 +02:00
fi
2019-07-24 14:34:26 +02:00
( ( i != num_lines && $# right) ) && PROMPT += $_p9k_line_gap_post [ i]
2019-07-17 19:34:01 +02:00
else
2019-07-24 14:34:26 +02:00
PROMPT += $_p9k_prompt
2019-07-16 16:19:16 +02:00
fi
2019-07-18 12:21:54 +02:00
if ( ( i = = num_lines ) ) ; then
RPROMPT = $right
elif [ [ -z $right ] ] ; then
PROMPT += $'\n'
fi
2019-07-16 16:19:16 +02:00
done
2019-06-09 09:18:16 +02:00
2019-06-20 18:50:07 +02:00
PROMPT = ${ ${ PROMPT // $' %{\b' / '%{%G' } // $' \b' }
RPROMPT = ${ ${ RPROMPT // $' %{\b' / '%{%G' } // $' \b' }
2019-06-14 16:14:04 +02:00
2019-07-24 14:34:26 +02:00
PROMPT += $_p9k_prompt_suffix_left
[ [ -n $RPROMPT ] ] && RPROMPT = $_p9k_prompt_prefix_right $RPROMPT $_p9k_prompt_suffix_right
2019-07-17 19:34:01 +02:00
2019-07-27 13:18:09 +02:00
_p9k_prompt_side =
2019-07-24 18:34:29 +02:00
( ( $# _p9k_cache < _POWERLEVEL9K_MAX_CACHE_SIZE ) ) || _p9k_cache = ( )
2019-08-02 07:07:23 +02:00
IFS = $ifs
2019-06-01 17:54:53 +02:00
}
function _p9k_update_prompt( ) {
2019-07-24 14:34:26 +02:00
_p9k_refresh_reason = $1
2019-06-01 17:54:53 +02:00
_p9k_set_prompt
2019-07-24 14:34:26 +02:00
_p9k_refresh_reason = ''
2019-06-01 17:54:53 +02:00
zle && zle .reset-prompt && zle -R
}
powerlevel9k_refresh_prompt_inplace( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-07-24 18:34:29 +02:00
( ( __p9k_enabled ) ) || return
2019-07-24 14:34:26 +02:00
_p9k_refresh_reason = precmd
2019-06-01 17:54:53 +02:00
_p9k_set_prompt
2019-07-24 14:34:26 +02:00
_p9k_refresh_reason = ''
2019-06-01 17:54:53 +02:00
}
2019-07-24 21:07:28 +02:00
p9k_refresh_prompt_inplace( ) { powerlevel9k_refresh_prompt_inplace }
2019-07-27 12:27:56 +02:00
typeset -gi __p9k_new_status
typeset -ga __p9k_new_pipestatus
2019-07-27 12:09:09 +02:00
_p9k_save_status( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-07-27 12:09:09 +02:00
local -i pipe
if ( ( !$+_p9k_line_finished ) ) ; then
: # SIGINT
elif ( ( !$+_p9k_preexec_cmd ) ) ; then
# Empty line, comment or parse error.
#
# This case is handled incorrectly:
#
# true | false
# |
#
# Here status=1 and pipestatus=(0 1). Ideally we should ignore pipestatus but we won't.
#
# This works though (unless pipefail is set):
#
# false | true
# |
#
# We get status=1 and pipestatus=(1 0) and correctly ignore pipestatus.
2019-07-27 12:27:56 +02:00
( ( _p9k_status = = __p9k_new_status ) ) && return
elif ( ( $__p9k_new_pipestatus [ ( I) $__p9k_new_status ] ) ) ; then # just in case
2019-07-27 12:09:09 +02:00
local cmd = ( ${ (z)_p9k_preexec_cmd } )
if [ [ $# cmd != 0 && $cmd [ 1] != '!' && ${ (Q)cmd[1] } != coproc ] ] ; then
local arg
for arg in ${ (z)_p9k_preexec_cmd } ; do
# '()' is for functions, *';' is for complex commands.
if [ [ $arg = = ( '()' | '&&' | '||' | '&' | '&|' | '&!' | *';' ) ] ] ; then
pipe = 0
break
elif [ [ $arg = = *( '|' | '|&' ) * ] ] ; then
pipe = 1
fi
done
fi
fi
2019-07-27 12:27:56 +02:00
_p9k_status = $__p9k_new_status
2019-07-27 12:09:09 +02:00
if ( ( pipe ) ) ; then
2019-07-27 12:27:56 +02:00
_p9k_pipestatus = ( $__p9k_new_pipestatus )
2019-07-27 12:09:09 +02:00
else
2019-07-27 12:27:56 +02:00
_p9k_pipestatus = ( $_p9k_status )
2019-07-27 12:09:09 +02:00
fi
}
2019-07-24 21:07:28 +02:00
_p9k_precmd( ) {
2019-07-27 12:27:56 +02:00
__p9k_new_status = $?
__p9k_new_pipestatus = ( $pipestatus )
2019-07-24 18:34:29 +02:00
2019-07-24 19:11:43 +02:00
if ( ( $+_p9k_real_zle_rprompt_indent ) ) ; then
if [ [ -n $_p9k_real_zle_rprompt_indent ] ] ; then
ZLE_RPROMPT_INDENT = $_p9k_real_zle_rprompt_indent
else
unset ZLE_RPROMPT_INDENT
fi
unset _p9k_real_zle_rprompt_indent
fi
2019-07-30 15:11:58 +02:00
if _p9k_must_init; then
if ( ( !__p9k_configured ) ) ; then
__p9k_configured = 1
2019-07-31 10:00:27 +02:00
if [ [ " ${ parameters [(I)POWERLEVEL9K_*] } " = = ( POWERLEVEL9K_MODE| ) ] ] && _p9k_can_configure -q; then
2019-07-30 15:11:58 +02:00
if $__p9k_root_dir /internal/wizard.zsh -d $__p9k_root_dir ; then
source $__p9k_cfg_path
_p9k_must_init
fi
fi
fi
_p9k_init
fi
2019-06-01 17:54:53 +02:00
unsetopt localoptions
prompt_opts = ( cr percent sp subst)
setopt nopromptbang prompt{ cr,percent,sp,subst}
2019-07-27 12:27:56 +02:00
_p9k_timer_end = EPOCHREALTIME
2019-08-16 20:26:28 +02:00
if ( ( _p9k_timer_start ) ) ; then
typeset -gF P9K_COMMAND_DURATION_SECONDS = $(( _p9k_timer_end - _p9k_timer_start))
else
unset P9K_COMMAND_DURATION_SECONDS
fi
2019-07-27 12:09:09 +02:00
_p9k_save_status
2019-06-01 17:54:53 +02:00
powerlevel9k_refresh_prompt_inplace
2019-07-24 18:34:29 +02:00
2019-07-27 12:09:09 +02:00
unset _p9k_line_finished
unset _p9k_preexec_cmd
_p9k_timer_start = 0
2019-07-24 18:34:29 +02:00
_p9k_region_active = 0
2019-06-01 17:54:53 +02:00
}
function _p9k_zle_keymap_select( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-06-01 17:54:53 +02:00
zle && zle .reset-prompt && zle -R
}
2019-07-24 15:52:54 +02:00
_p9k_deinit_async_pump( ) {
if ( ( _p9k_async_pump_lock_fd ) ) ; then
zsystem flock -u $_p9k_async_pump_lock_fd
_p9k_async_pump_lock_fd = 0
fi
if ( ( _p9k_async_pump_fd ) ) ; then
zle -F $_p9k_async_pump_fd
exec { _p9k_async_pump_fd} >& -
_p9k_async_pump_fd = 0
fi
if ( ( _p9k_async_pump_pid ) ) ; then
kill -- -$_p9k_async_pump_pid & >/dev/null
_p9k_async_pump_pid = 0
fi
if [ [ -n $_p9k_async_pump_fifo ] ] ; then
rm -f $_p9k_async_pump_fifo
_p9k_async_pump_fifo = ''
fi
if [ [ -n $_p9k_async_pump_lock ] ] ; then
rm -f $_p9k_async_pump_lock
_p9k_async_pump_lock = ''
fi
2019-08-06 09:57:04 +02:00
_p9k_async_pump_subshell = -1
_p9k_async_pump_shell_pid = -1
2019-07-24 15:52:54 +02:00
add-zsh-hook -D zshexit _p9k_kill_async_pump
}
function _p9k_on_async_message( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-07-24 18:34:29 +02:00
( ( ARGC = = 1 ) ) || return
local msg = '' IFS = ''
while read -r -t -u $1 msg; do
[ [ $__p9k_enabled = = 1 && $1 = = $_p9k_async_pump_fd ] ] && eval $_p9k_async_pump_line $msg
2019-07-24 15:52:54 +02:00
_p9k_async_pump_line =
msg =
done
_p9k_async_pump_line += $msg
2019-07-24 18:34:29 +02:00
[ [ $__p9k_enabled = = 1 && $1 = = $_p9k_async_pump_fd ] ] && zle && zle .reset-prompt && zle -R
2019-07-24 15:52:54 +02:00
}
function _p9k_async_pump( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh || return
setopt no_aliases no_hist_expand extended_glob || return
setopt no_prompt_bang prompt_{ cr,percent,subst,sp} || return
zmodload zsh/system zsh/datetime || return
echo $$ || return
2019-07-24 15:52:54 +02:00
local ip last_ip
local -F next_ip_time
while ! zsystem flock -t 0 $lock 2>/dev/null && kill -0 $parent_pid ; do
if ( ( time_realtime ) ) ; then
echo || break
# SIGWINCH is a workaround for a bug in zsh. After a background job completes, callbacks
# registered with `zle -F` stop firing until the user presses any key or the process
# receives a signal (any signal at all).
# Fix: https://github.com/zsh-users/zsh/commit/5e11082349bf72897f93f3a4493a97a2caf15984.
kill -WINCH $parent_pid
fi
if ( ( public_ip && EPOCHREALTIME >= next_ip_time ) ) ; then
ip =
local method = ''
local -F start = EPOCHREALTIME
next_ip_time = $(( start + 5 ))
for method in $ip_methods $ip_methods ; do
case $method in
dig)
if ( ( $+commands[ dig] ) ) ; then
2019-07-29 14:18:57 +02:00
ip = " $( dig +tries= 1 +short -4 A myip.opendns.com @resolver1.opendns.com 2>/dev/null) "
2019-07-24 15:52:54 +02:00
[ [ $ip = = ';' * ] ] && ip =
if [ [ -z $ip ] ] ; then
2019-07-29 14:18:57 +02:00
ip = " $( dig +tries= 1 +short -6 AAAA myip.opendns.com @resolver1.opendns.com 2>/dev/null) "
2019-07-24 15:52:54 +02:00
[ [ $ip = = ';' * ] ] && ip =
fi
fi
; ;
curl)
if ( ( $+commands[ curl] ) ) ; then
2019-07-29 14:18:57 +02:00
ip = " $( curl --max-time 5 -w '\n' " $ip_url " 2>/dev/null) "
2019-07-24 15:52:54 +02:00
fi
; ;
wget)
if ( ( $+commands[ wget] ) ) ; then
2019-07-29 14:18:57 +02:00
ip = " $( wget -T 5 -qO- " $ip_url " 2>/dev/null) "
2019-07-24 15:52:54 +02:00
fi
; ;
esac
[ [ $ip = ~ '^[0-9a-f.:]+$' ] ] || ip = ''
if [ [ -n $ip ] ] ; then
next_ip_time = $(( start + tout))
break
fi
done
if [ [ $ip != $last_ip ] ] ; then
last_ip = $ip
echo _p9k_public_ip = ${ (q) ${ ${ ip // \% /%% } // $'\n' } } || break
kill -WINCH $parent_pid
fi
fi
sleep 1
done
rm -f $lock $fifo
}
function _p9k_kill_async_pump( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-08-06 09:57:04 +02:00
if [ [ $ZSH_SUBSHELL = = $_p9k_async_pump_subshell && $$ = = $_p9k_async_pump_shell_pid ] ] ; then
2019-07-24 15:52:54 +02:00
_p9k_deinit_async_pump
fi
}
2019-06-21 19:49:36 +02:00
_p9k_init_async_pump( ) {
local -i public_ip time_realtime
2019-07-24 21:07:28 +02:00
_p9k_segment_in_use public_ip && public_ip = 1
_p9k_segment_in_use time && ( ( _POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME ) ) && time_realtime = 1
2019-06-21 19:49:36 +02:00
( ( public_ip || time_realtime ) ) || return
2019-06-01 17:54:53 +02:00
2019-06-21 19:49:36 +02:00
_p9k_start_async_pump( ) {
2019-06-01 17:54:53 +02:00
setopt err_return no_bg_nice
2019-07-29 14:18:57 +02:00
_p9k_async_pump_lock = " $( mktemp ${ TMPDIR :- /tmp } /p9k-$$ -async-pump-lock.XXXXXXXXXX) "
_p9k_async_pump_fifo = " $( mktemp -u ${ TMPDIR :- /tmp } /p9k-$$ -async-pump-fifo.XXXXXXXXXX) "
2019-07-24 14:34:26 +02:00
mkfifo $_p9k_async_pump_fifo
sysopen -rw -o cloexec,sync -u _p9k_async_pump_fd $_p9k_async_pump_fifo
zle -F $_p9k_async_pump_fd _p9k_on_async_message
2019-07-24 15:52:54 +02:00
zsystem flock -f _p9k_async_pump_lock_fd $_p9k_async_pump_lock
2019-06-21 19:49:36 +02:00
2019-07-24 19:42:47 +02:00
local cmd = "
2019-06-21 19:49:36 +02:00
local -i public_ip = $public_ip time_realtime = $time_realtime parent_pid = $$
2019-07-23 15:47:25 +02:00
local -a ip_methods = ( $_POWERLEVEL9K_PUBLIC_IP_METHODS )
local -F tout = $_POWERLEVEL9K_PUBLIC_IP_TIMEOUT
local ip_url = $_POWERLEVEL9K_PUBLIC_IP_HOST
2019-07-24 14:34:26 +02:00
local lock = $_p9k_async_pump_lock
local fifo = $_p9k_async_pump_fifo
2019-07-24 19:42:47 +02:00
$functions [ _p9k_async_pump] "
2019-06-21 19:49:36 +02:00
2019-07-24 19:42:47 +02:00
local setsid = ${ commands [setsid] :- /usr/local/opt/util-linux/bin/setsid }
[ [ -f $setsid ] ] && setsid = ${ (q)setsid } || setsid =
cmd = " $setsid zsh -dfxc ${ (q)cmd } &! "
zsh -dfmxc $cmd </dev/null >& $_p9k_async_pump_fd 2>/dev/null & !
2019-06-21 19:49:36 +02:00
2019-08-02 07:07:23 +02:00
IFS = '' read -t 5 -r -u $_p9k_async_pump_fd _p9k_async_pump_pid && ( ( _p9k_async_pump_pid ) )
2019-06-01 17:54:53 +02:00
2019-07-24 19:42:47 +02:00
_p9k_async_pump_subshell = $ZSH_SUBSHELL
2019-08-06 09:57:04 +02:00
_p9k_async_pump_shell_pid = $$
2019-06-21 19:49:36 +02:00
add-zsh-hook zshexit _p9k_kill_async_pump
2019-06-01 17:54:53 +02:00
}
2019-06-21 19:49:36 +02:00
if ! _p9k_start_async_pump ; then
2019-08-05 10:37:04 +02:00
>& 2 print -rP -- "%F{red}[ERROR]%f Powerlevel10k failed to start async worker. The following segments may malfunction: "
( ( public_ip ) ) && >& 2 print -rP -- " - %F{green}public_ip%f"
( ( time_realtime ) ) && >& 2 print -rP -- " - %F{green}time%f"
2019-07-24 15:52:54 +02:00
_p9k_deinit_async_pump
2019-06-01 17:54:53 +02:00
fi
}
# Does ZSH have a certain off-by-one bug that triggers when PROMPT overflows to a new line?
#
# Bug: https://github.com/zsh-users/zsh/commit/d8d9fee137a5aa2cf9bf8314b06895bfc2a05518.
# ZSH_PATCHLEVEL=zsh-5.4.2-159-gd8d9fee13. Released in 5.5.
#
# Fix: https://github.com/zsh-users/zsh/commit/64d13738357c9b9c212adbe17f271716abbcf6ea.
# ZSH_PATCHLEVEL=zsh-5.7.1-50-g64d137383.
#
# Test: PROMPT="${(pl:$((COLUMNS))::-:)}<%1(l.%2(l.FAIL.PASS).FAIL)> " zsh -dfis <<<exit
# Workaround: PROMPT="${(pl:$((COLUMNS))::-:)}%{%G%}<%1(l.%2(l.FAIL.PASS).FAIL)> " zsh -dfis <<<exit
function _p9k_prompt_overflow_bug( ) {
[ [ $ZSH_PATCHLEVEL = ~ '^zsh-5\.4\.2-([0-9]+)-' ] ] && return $(( match[ 1 ] < 159 ))
[ [ $ZSH_PATCHLEVEL = ~ '^zsh-5\.7\.1-([0-9]+)-' ] ] && return $(( match[ 1 ] >= 50 ))
is-at-least 5.5 && ! is-at-least 5.7.2
}
2019-07-24 14:34:26 +02:00
_p9k_init_vars( ) {
2019-07-27 12:09:09 +02:00
typeset -gi _p9k_reset_on_line_finish
typeset -gF _p9k_timer_start
typeset -gF _p9k_timer_end
typeset -gi _p9k_status
typeset -ga _p9k_pipestatus
2019-07-24 18:34:29 +02:00
typeset -g _p9k_param_sig
2019-07-24 14:34:26 +02:00
typeset -g _p9k_ret
typeset -g _p9k_cache_key
typeset -ga _p9k_cache_val
typeset -gA _p9k_cache
typeset -ga _p9k_t
typeset -g _p9k_n
typeset -gi _p9k_i
typeset -g _p9k_bg
2019-07-24 18:34:29 +02:00
typeset -ga _p9k_left_join
typeset -ga _p9k_right_join
2019-07-24 14:34:26 +02:00
typeset -g _p9k_public_ip
typeset -g _p9k_todo_file
# git workdir => the last prompt we've shown for it
typeset -gA _p9k_last_git_prompt
# git workdir => 1 if gitstatus is slow on it, 0 if it's fast.
typeset -gA _p9k_git_slow
typeset -gF _p9k_gitstatus_start_time
typeset -g _p9k_prompt
typeset -g _p9k_rprompt
typeset -g _p9k_lprompt
typeset -g _p9k_prompt_side
typeset -g _p9k_segment_name
typeset -gi _p9k_segment_index
typeset -g _p9k_refresh_reason
typeset -gi _p9k_region_active
typeset -g _p9k_async_pump_line
typeset -g _p9k_async_pump_fifo
typeset -g _p9k_async_pump_lock
2019-07-24 15:52:54 +02:00
typeset -gi _p9k_async_pump_lock_fd
2019-07-24 14:34:26 +02:00
typeset -gi _p9k_async_pump_fd
typeset -gi _p9k_async_pump_pid
typeset -gi _p9k_async_pump_subshell
2019-08-06 09:57:04 +02:00
typeset -gi _p9k_async_pump_shell_pid
2019-07-24 14:34:26 +02:00
typeset -ga _p9k_line_segments_left
typeset -ga _p9k_line_segments_right
typeset -ga _p9k_line_prefix_left
typeset -ga _p9k_line_prefix_right
typeset -ga _p9k_line_suffix_left
typeset -ga _p9k_line_suffix_right
typeset -ga _p9k_line_never_empty_right
typeset -ga _p9k_line_gap_post
typeset -g _p9k_xy
typeset -g _p9k_clm
typeset -g _p9k_p
typeset -gi _p9k_x
typeset -gi _p9k_y
typeset -gi _p9k_m
typeset -gi _p9k_d
typeset -gi _p9k_g
typeset -gi _p9k_ind
typeset -g _p9k_gap_pre
typeset -g _p9k_prompt_prefix_left
typeset -g _p9k_prompt_prefix_right
typeset -g _p9k_prompt_suffix_left
typeset -g _p9k_prompt_suffix_right
typeset -gi _p9k_emulate_zero_rprompt_indent
typeset -gA _p9k_battery_states
typeset -g _p9k_os
typeset -g _p9k_os_icon
typeset -g _p9k_color1
typeset -g _p9k_color2
typeset -g _p9k_s
typeset -g _p9k_ss
typeset -g _p9k_sss
typeset -g _p9k_v
typeset -g _p9k_c
typeset -g _p9k_e
typeset -g _p9k_w
typeset -gi _p9k_dir_len
typeset -gi _p9k_num_cpus
2019-08-07 08:38:04 +02:00
typeset -g _p9k_pwd
typeset -g _p9k_pwd_a
2019-07-24 14:34:26 +02:00
2019-07-24 18:34:29 +02:00
typeset -g P9K_VISUAL_IDENTIFIER
typeset -g P9K_CONTENT
typeset -g P9K_GAP
2019-07-24 14:34:26 +02:00
}
2019-07-23 15:47:25 +02:00
_p9k_init_params( ) {
_p9k_declare -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS -- context dir vcs
_p9k_declare -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS -- status root_indicator background_jobs history time
_p9k_declare -b POWERLEVEL9K_DISABLE_RPROMPT 0
_p9k_declare -b POWERLEVEL9K_PROMPT_ADD_NEWLINE 0
2019-07-24 12:47:56 +02:00
_p9k_declare -b POWERLEVEL9K_PROMPT_ON_NEWLINE 0
_p9k_declare -b POWERLEVEL9K_RPROMPT_ON_NEWLINE 0
2019-07-23 15:47:25 +02:00
_p9k_declare -b POWERLEVEL9K_SHOW_RULER 0
_p9k_declare -i POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT 1
_p9k_declare -s POWERLEVEL9K_COLOR_SCHEME dark
_p9k_declare -s POWERLEVEL9K_GITSTATUS_DIR ""
_p9k_declare -b POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY 0
_p9k_declare -i POWERLEVEL9K_VCS_SHORTEN_LENGTH
_p9k_declare -i POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
_p9k_declare -s POWERLEVEL9K_VCS_SHORTEN_STRATEGY
2019-08-14 07:24:09 +02:00
_p9k_declare -e POWERLEVEL9K_VCS_SHORTEN_DELIMITER '\u2026'
2019-07-23 15:47:25 +02:00
_p9k_declare -b POWERLEVEL9K_HIDE_BRANCH_ICON 0
_p9k_declare -b POWERLEVEL9K_VCS_HIDE_TAGS 0
_p9k_declare -i POWERLEVEL9K_CHANGESET_HASH_LENGTH 8
# Specifies the maximum number of elements in the cache. When the cache grows over this limit,
# it gets cleared. This is meant to avoid memory leaks when a rogue prompt is filling the cache
# with data.
_p9k_declare -i POWERLEVEL9K_MAX_CACHE_SIZE 10000
_p9k_declare -e POWERLEVEL9K_ANACONDA_LEFT_DELIMITER "("
_p9k_declare -e POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER ")"
_p9k_declare -b POWERLEVEL9K_ANACONDA_SHOW_PYTHON_VERSION 1
_p9k_declare -b POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE 1
_p9k_declare -b POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS 0
_p9k_declare -b POWERLEVEL9K_DISK_USAGE_ONLY_WARNING 0
_p9k_declare -i POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90
_p9k_declare -i POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL 95
_p9k_declare -i POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10
_p9k_declare -i POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD 999
_p9k_declare -a POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND --
_p9k_declare -b POWERLEVEL9K_BATTERY_VERBOSE 1
if [ [ $parameters [ POWERLEVEL9K_BATTERY_STAGES] = = scalar ] ] ; then
_p9k_declare -e POWERLEVEL9K_BATTERY_STAGES
else
2019-08-20 14:56:43 +02:00
[ [ -z $_p9k_locale ] ] || local LC_ALL = $_p9k_locale
2019-07-23 15:47:25 +02:00
_p9k_declare -a POWERLEVEL9K_BATTERY_STAGES --
_POWERLEVEL9K_BATTERY_STAGES = ( " ${ (@g : : )_POWERLEVEL9K_BATTERY_STAGES } " )
fi
_p9k_declare -F POWERLEVEL9K_PUBLIC_IP_TIMEOUT 300
_p9k_declare -a POWERLEVEL9K_PUBLIC_IP_METHODS -- dig curl wget
_p9k_declare -e POWERLEVEL9K_PUBLIC_IP_NONE ""
_p9k_declare -s POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me"
_p9k_declare -s POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ""
_p9k_declare -b POWERLEVEL9K_ALWAYS_SHOW_CONTEXT 0
_p9k_declare -b POWERLEVEL9K_ALWAYS_SHOW_USER 0
_p9k_declare -e POWERLEVEL9K_CONTEXT_TEMPLATE "%n@%m"
_p9k_declare -e POWERLEVEL9K_USER_TEMPLATE "%n"
_p9k_declare -e POWERLEVEL9K_HOST_TEMPLATE "%m"
_p9k_declare -F POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD 3
_p9k_declare -i POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION 2
# Other options: "d h m s".
_p9k_declare -s POWERLEVEL9K_COMMAND_EXECUTION_TIME_FORMAT "H:M:S"
_p9k_declare -e POWERLEVEL9K_DIR_PATH_SEPARATOR "/"
_p9k_declare -e POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~"
_p9k_declare -b POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD 0
_p9k_declare -b POWERLEVEL9K_DIR_ANCHORS_BOLD 0
_p9k_declare -b POWERLEVEL9K_DIR_PATH_ABSOLUTE 0
_p9k_declare -b POWERLEVEL9K_DIR_SHOW_WRITABLE 0
_p9k_declare -b POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER 0
_p9k_declare -b POWERLEVEL9K_DIR_HYPERLINK 0
_p9k_declare -s POWERLEVEL9K_SHORTEN_STRATEGY ""
_p9k_declare -s POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
_p9k_declare -s POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
_p9k_declare -s POWERLEVEL9K_DIR_ANCHOR_FOREGROUND
_p9k_declare -s POWERLEVEL9K_DIR_SHORTENED_FOREGROUND
_p9k_declare -s POWERLEVEL9K_SHORTEN_FOLDER_MARKER "(.shorten_folder_marker|.bzr|CVS|.git|.hg|.svn|.terraform|.citc)"
# Shorten directory if it's longer than this even if there is space for it.
# The value can be either absolute (e.g., '80') or a percentage of terminal
# width (e.g, '50%'). If empty, directory will be shortened only when prompt
# doesn't fit. Applies only when POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique.
_p9k_declare -s POWERLEVEL9K_DIR_MAX_LENGTH 0
# Individual elements are patterns. They are expanded with the options set
# by `emulate zsh && setopt extended_glob`.
_p9k_declare -a POWERLEVEL9K_DIR_PACKAGE_FILES -- package.json composer.json
# When dir is on the last prompt line, try to shorten it enough to leave at least this many
# columns for typing commands. Applies only when POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique.
_p9k_declare -i POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS 40
# When dir is on the last prompt line, try to shorten it enough to leave at least
# COLUMNS * POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT * 0.01 columns for typing commands. Applies
# only when POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique.
_p9k_declare -F POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT 50
# POWERLEVEL9K_DIR_CLASSES allow you to specify custom styling and icons for different
# directories.
#
# POWERLEVEL9K_DIR_CLASSES must be an array with 3 * N elements. Each triplet consists of:
#
# 1. A pattern against which the current directory is matched. Matching is done with
# extended_glob option enabled.
# 2. Directory class for the purpose of styling.
# 3. Icon.
#
# Triplets are tried in order. The first triplet whose pattern matches $PWD wins. If there are no
# matches, there will be no icon and the styling is done according to POWERLEVEL9K_DIR_BACKGROUND,
# POWERLEVEL9K_DIR_FOREGROUND, etc.
#
# Example:
#
# POWERLEVEL9K_DIR_CLASSES=(
# '~/work(/*)#' WORK '(╯°□°)╯︵ ┻━┻'
# '~(/*)#' HOME '⌂'
# '*' DEFAULT '')
#
# POWERLEVEL9K_DIR_WORK_BACKGROUND=red
# POWERLEVEL9K_DIR_HOME_BACKGROUND=blue
# POWERLEVEL9K_DIR_DEFAULT_BACKGROUND=yellow
#
# With these settings, the current directory in the prompt may look like this:
#
# (╯°□°)╯︵ ┻━┻ ~/work/projects/important/urgent
#
# ⌂ ~/best/powerlevel10k
2019-07-24 14:34:26 +02:00
_p9k_declare -a POWERLEVEL9K_DIR_CLASSES
2019-07-23 15:47:25 +02:00
_p9k_declare -i POWERLEVEL9K_SHORTEN_DELIMITER_LENGTH
_p9k_declare -e POWERLEVEL9K_SHORTEN_DELIMITER
_p9k_declare -i POWERLEVEL9K_SHORTEN_DIR_LENGTH
_p9k_declare -s POWERLEVEL9K_IP_INTERFACE "^[^ ]+"
_p9k_declare -s POWERLEVEL9K_VPN_IP_INTERFACE "tun"
_p9k_declare -i POWERLEVEL9K_LOAD_WHICH 5
_p9k_declare -b POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW 0
2019-07-23 23:17:01 +02:00
_p9k_declare -b POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY 0
2019-08-12 08:56:47 +02:00
_p9k_declare -b POWERLEVEL9K_GO_VERSION_PROJECT_ONLY 1
_p9k_declare -b POWERLEVEL9K_RUST_VERSION_PROJECT_ONLY 1
2019-07-23 15:47:25 +02:00
_p9k_declare -b POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW 0
2019-08-10 10:47:22 +02:00
_p9k_declare -b POWERLEVEL9K_RVM_SHOW_GEMSET 0
_p9k_declare -b POWERLEVEL9K_RVM_SHOW_PREFIX 0
2019-07-23 15:47:25 +02:00
_p9k_declare -b POWERLEVEL9K_CHRUBY_SHOW_VERSION 1
_p9k_declare -b POWERLEVEL9K_CHRUBY_SHOW_ENGINE 1
_p9k_declare -b POWERLEVEL9K_STATUS_CROSS 0
_p9k_declare -b POWERLEVEL9K_STATUS_OK 1
2019-07-26 15:35:46 +02:00
_p9k_declare -b POWERLEVEL9K_STATUS_OK_PIPE 1
_p9k_declare -b POWERLEVEL9K_STATUS_ERROR 1
_p9k_declare -b POWERLEVEL9K_STATUS_ERROR_PIPE 1
_p9k_declare -b POWERLEVEL9K_STATUS_ERROR_SIGNAL 1
2019-07-23 15:47:25 +02:00
_p9k_declare -b POWERLEVEL9K_STATUS_SHOW_PIPESTATUS 1
_p9k_declare -b POWERLEVEL9K_STATUS_HIDE_SIGNAME 0
2019-07-26 15:35:46 +02:00
_p9k_declare -b POWERLEVEL9K_STATUS_VERBOSE_SIGNAME 1
_p9k_declare -b POWERLEVEL9K_STATUS_EXTENDED_STATES 0
2019-07-23 15:47:25 +02:00
_p9k_declare -b POWERLEVEL9K_STATUS_VERBOSE 1
_p9k_declare -b POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE 0
# Format for the current time: 09:51:02. See `man 3 strftime`.
_p9k_declare -e POWERLEVEL9K_TIME_FORMAT "%D{%H:%M:%S}"
# If set to true, time will update every second.
_p9k_declare -b POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME 0
# If set to true, time will update when you hit enter. This way prompts for the past
# commands will contain the start times of their commands as opposed to the default
# behavior where they contain the end times of their preceding commands.
_p9k_declare -b POWERLEVEL9K_TIME_UPDATE_ON_COMMAND 0
_p9k_declare -e POWERLEVEL9K_DATE_FORMAT "%D{%d.%m.%y}"
_p9k_declare -s POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND 1
_p9k_declare -b POWERLEVEL9K_SHOW_CHANGESET 0
_p9k_declare -e POWERLEVEL9K_VCS_LOADING_TEXT loading
_p9k_declare -a POWERLEVEL9K_VCS_GIT_HOOKS -- vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname
_p9k_declare -a POWERLEVEL9K_VCS_HG_HOOKS -- vcs-detect-changes
_p9k_declare -a POWERLEVEL9K_VCS_SVN_HOOKS -- vcs-detect-changes svn-detect-changes
# If it takes longer than this to fetch git repo status, display the prompt with a greyed out
# vcs segment and fix it asynchronously when the results come it.
_p9k_declare -F POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS 0.05
_p9k_declare -a POWERLEVEL9K_VCS_BACKENDS -- git
_p9k_declare -b POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING 0
_p9k_declare -i POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY -1
_p9k_declare -i POWERLEVEL9K_VCS_STAGED_MAX_NUM 1
_p9k_declare -i POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM 1
_p9k_declare -i POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM 1
2019-08-05 22:26:23 +02:00
_p9k_declare -i POWERLEVEL9K_VCS_CONFLICTED_MAX_NUM 1
2019-07-23 15:47:25 +02:00
_p9k_declare -i POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM -1
_p9k_declare -i POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM -1
_p9k_declare -b POWERLEVEL9K_DISABLE_GITSTATUS 0
_p9k_declare -e POWERLEVEL9K_VI_INSERT_MODE_STRING "INSERT"
_p9k_declare -e POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL"
# VISUAL mode is shown as NORMAL unless POWERLEVEL9K_VI_VISUAL_MODE_STRING is explicitly set.
_p9k_declare -e POWERLEVEL9K_VI_VISUAL_MODE_STRING
_p9k_declare -b POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION 1
_p9k_declare -e POWERLEVEL9K_VIRTUALENV_LEFT_DELIMITER "("
_p9k_declare -e POWERLEVEL9K_VIRTUALENV_RIGHT_DELIMITER ")"
_p9k_declare -b POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW 0
2019-07-29 16:10:28 +02:00
_p9k_declare -b POWERLEVEL9K_NODEENV_SHOW_NODE_VERSION 1
_p9k_declare -e POWERLEVEL9K_NODEENV_LEFT_DELIMITER "["
_p9k_declare -e POWERLEVEL9K_NODEENV_RIGHT_DELIMITER "]"
2019-07-23 15:47:25 +02:00
_p9k_declare -b POWERLEVEL9K_KUBECONTEXT_SHOW_DEFAULT_NAMESPACE 1
2019-07-30 07:14:51 +02:00
_p9k_declare -a POWERLEVEL9K_KUBECONTEXT_SHORTEN --
2019-07-23 15:47:25 +02:00
# Defines context classes for the purpose of applying different styling to different contexts.
#
# POWERLEVEL9K_KUBECONTEXT_CLASSES must be an array with even number of elements. The first
# element in each pair defines a pattern against which the current context (in the format it is
# displayed in the prompt) gets matched. The second element defines context class. Patterns are
# tried in order. The first match wins.
#
# If a non-empty class <C> is assigned to a context, the segment is styled with
# POWERLEVEL9K_KUBECONTEXT_<U>_BACKGROUND and POWERLEVEL9K_KUBECONTEXT_<U>_FOREGROUND where <U> is
# uppercased <C>. Otherwise with POWERLEVEL9K_KUBECONTEXT_BACKGROUND and
# POWERLEVEL9K_KUBECONTEXT_FOREGROUND.
#
# Example: Use red background for contexts containing "prod", green for "testing" and yellow for
# everything else.
#
# POWERLEVEL9K_KUBECONTEXT_CLASSES=(
# '*prod*' prod
# '*testing*' testing
# '*' other)
#
# POWERLEVEL9K_KUBECONTEXT_PROD_BACKGROUND=red
# POWERLEVEL9K_KUBECONTEXT_TESTING_BACKGROUND=green
# POWERLEVEL9K_KUBECONTEXT_OTHER_BACKGROUND=yellow
_p9k_declare -a POWERLEVEL9K_KUBECONTEXT_CLASSES --
# Specifies the format of java version.
#
# POWERLEVEL9K_JAVA_VERSION_FULL=true => 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03
# POWERLEVEL9K_JAVA_VERSION_FULL=false => 1.8.0_212
#
# These correspond to `java -fullversion` and `java -version` respectively.
_p9k_declare -b POWERLEVEL9K_JAVA_VERSION_FULL 1
2019-06-01 17:54:53 +02:00
}
2019-07-24 15:52:54 +02:00
typeset -ga __p9k_wrapped_zle_widgets
2019-07-12 11:55:32 +02:00
# _p9k_wrap_zle_widget zle-keymap-select _p9k_zle_keymap_select
_p9k_wrap_zle_widget( ) {
local widget = $1
local hook = $2
2019-07-24 15:52:54 +02:00
( ( __p9k_wrapped_zle_widgets[ ( I) $widget :$hook ] ) ) && return
__p9k_wrapped_zle_widgets += $widget :$hook
2019-07-12 11:55:32 +02:00
local orig = p9k-orig-$widget
case $widgets [ $widget ] in
2019-07-16 10:33:53 +02:00
user:*)
zle -N $orig ${ widgets [ $widget ]#user : }
; ;
builtin )
eval " _p9k_orig_ ${ (q)widget } () { zle . ${ (q)widget } } "
zle -N $orig _p9k_orig_$widget
; ;
esac
2019-07-12 11:55:32 +02:00
local wrapper = _p9k_wrapper_$widget_ $hook
eval " function ${ (q)wrapper } () {
${ (q)hook } \" \$ @\"
( ( \$ +widgets[ ${ (q)orig } ] ) ) && zle ${ (q)orig } -- \" \$ @\"
2019-07-16 10:33:53 +02:00
} "
2019-07-12 11:55:32 +02:00
2019-07-16 10:33:53 +02:00
zle -N -- $widget $wrapper
2019-07-12 11:55:32 +02:00
}
2019-07-24 15:52:54 +02:00
function _p9k_zle_line_finish( ) {
( ( __p9k_enabled ) ) || return
2019-07-27 12:09:09 +02:00
_p9k_line_finished =
2019-08-05 10:37:04 +02:00
if ( ( _p9k_reset_on_line_finish ) ) ; then
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
zle && zle .reset-prompt && zle -R
fi
2019-07-24 15:52:54 +02:00
}
function _p9k_zle_line_pre_redraw( ) {
( ( __p9k_enabled ) ) || return
[ [ ${ KEYMAP :- } = = vicmd ] ] || return 0
local region = ${ ${ REGION_ACTIVE :- 0 } /2/1 }
[ [ $region != $_p9k_region_active ] ] || return 0
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-07-24 15:52:54 +02:00
_p9k_region_active = $region
zle && zle .reset-prompt && zle -R
}
2019-07-16 16:19:16 +02:00
prompt__p9k_internal_nothing( ) {
2019-07-24 14:34:26 +02:00
_p9k_prompt += '${_p9k_sss::=}'
2019-07-16 16:19:16 +02:00
}
2019-07-21 10:48:57 +02:00
# _p9k_build_gap_post <first|newline>
_p9k_build_gap_post( ) {
_p9k_get_icon '' MULTILINE_${ (U)1 } _PROMPT_GAP_CHAR
2019-07-23 15:47:25 +02:00
local char = ${ _p9k_ret :- }
2019-07-21 10:48:57 +02:00
_p9k_prompt_length $char
2019-07-23 15:47:25 +02:00
if ( ( _p9k_ret != 1 || $# char != 1 ) ) ; then
2019-08-05 10:37:04 +02:00
print -rP -- " %F{red}WARNING!%f %BMULTILINE_ ${ (U)1 } _PROMPT_GAP_CHAR%b is not one character long. Will use ' '. "
print -rP -- " Either change the value of %BPOWERLEVEL9K_MULTILINE_ ${ (U)1 } _PROMPT_GAP_CHAR%b or remove it. "
2019-07-21 10:48:57 +02:00
char = ' '
fi
local style
_p9k_color prompt_multiline_$1 _prompt_gap BACKGROUND ""
2019-07-23 15:47:25 +02:00
[ [ -n $_p9k_ret ] ] && _p9k_background $_p9k_ret
style += $_p9k_ret
2019-07-21 10:48:57 +02:00
_p9k_color prompt_multiline_$1 _prompt_gap FOREGROUND ""
2019-07-23 15:47:25 +02:00
[ [ -n $_p9k_ret ] ] && _p9k_foreground $_p9k_ret
style += $_p9k_ret
2019-07-21 18:54:08 +02:00
local exp = POWERLEVEL9K_MULTILINE_${ (U)1 } _PROMPT_GAP_EXPANSION
( ( $+parameters[ $exp ] ) ) && exp = ${ (P)exp } || exp = '${P9K_GAP}'
2019-07-21 10:48:57 +02:00
[ [ $char = = '.' ] ] && local s = ',' || local s = '.'
2019-07-24 14:34:26 +02:00
_p9k_ret = $style '${${${_p9k_m:#-*}:+'
2019-07-21 18:54:08 +02:00
if [ [ $exp = = '${P9K_GAP}' ] ] ; then
2019-07-24 14:34:26 +02:00
_p9k_ret += '${(pl' $s '$((_p9k_m+1))' $s $s $char $s $')}'
2019-07-21 18:54:08 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_ret += '${${P9K_GAP::=${(pl' $s '$((_p9k_m+1))' $s $s $char $s $')}}+}'
2019-07-23 15:47:25 +02:00
_p9k_ret += '${:-"' $exp '"}'
2019-07-21 18:54:08 +02:00
style = 1
fi
2019-07-30 06:13:45 +02:00
_p9k_ret += $'$_p9k_rprompt$_p9k_t[$((1+!_p9k_ind))]}:-\n}'
2019-07-23 15:47:25 +02:00
[ [ -n $style ] ] && _p9k_ret += '%b%k%f'
2019-07-21 10:48:57 +02:00
}
2019-07-16 16:19:16 +02:00
_p9k_init_lines( ) {
2019-08-20 14:56:43 +02:00
[ [ -z $_p9k_locale ] ] || local LC_ALL = $_p9k_locale
2019-07-23 15:47:25 +02:00
local -a left_segments = ( $_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS )
local -a right_segments = ( $_POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS )
2019-07-16 16:19:16 +02:00
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_PROMPT_ON_NEWLINE ) ) ; then
2019-07-16 16:19:16 +02:00
left_segments += ( newline _p9k_internal_nothing)
fi
local -i num_left_lines = $(( 1 + ${# ${ (@M)left_segments : #newline } } ))
local -i num_right_lines = $(( 1 + ${# ${ (@M)right_segments : #newline } } ))
if ( ( num_right_lines > num_left_lines ) ) ; then
2019-07-16 20:03:56 +02:00
repeat $(( num_right_lines - num_left_lines)) left_segments = ( newline $left_segments )
2019-07-16 16:19:16 +02:00
local -i num_lines = num_right_lines
else
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_RPROMPT_ON_NEWLINE ) ) ; then
2019-07-16 20:03:56 +02:00
repeat $(( num_left_lines - num_right_lines)) right_segments = ( newline $right_segments )
2019-07-16 16:19:16 +02:00
else
repeat $(( num_left_lines - num_right_lines)) right_segments += newline
fi
local -i num_lines = num_left_lines
fi
2019-07-16 23:47:59 +02:00
repeat $num_lines ; do
2019-07-16 16:19:16 +02:00
local -i left_end = ${ left_segments [(i)newline] }
local -i right_end = ${ right_segments [(i)newline] }
2019-07-24 14:34:26 +02:00
_p9k_line_segments_left += " ${ (pj : \0 : )left_segments[1,left_end-1] } "
_p9k_line_segments_right += " ${ (pj : \0 : )right_segments[1,right_end-1] } "
2019-07-16 16:19:16 +02:00
( ( left_end > $# left_segments ) ) && left_segments = ( ) || shift left_end left_segments
( ( right_end > $# right_segments ) ) && right_segments = ( ) || shift right_end right_segments
_p9k_get_icon '' LEFT_SEGMENT_SEPARATOR
2019-07-23 15:47:25 +02:00
_p9k_get_icon 'prompt_empty_line' LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL $_p9k_ret
_p9k_escape $_p9k_ret
2019-07-24 14:34:26 +02:00
_p9k_line_prefix_left += '${${:-${_p9k_bg::=NONE}${_p9k_i::=0}${_p9k_sss::=%f' $_p9k_ret '}}+}'
_p9k_line_suffix_left += '%b%k$_p9k_sss%b%k%f'
2019-07-16 16:19:16 +02:00
_p9k_escape ${ (g : : )POWERLEVEL9K_EMPTY_LINE_RIGHT_PROMPT_FIRST_SEGMENT_START_SYMBOL }
2019-07-24 14:34:26 +02:00
[ [ -n $_p9k_ret ] ] && _p9k_line_never_empty_right += 1 || _p9k_line_never_empty_right += 0
_p9k_line_prefix_right += '${${:-${_p9k_bg::=NONE}${_p9k_i::=0}${_p9k_sss::=' $_p9k_ret '}}+}'
_p9k_line_suffix_right += '$_p9k_sss%b%k%f' # gets overridden for _p9k_emulate_zero_rprompt_indent
2019-07-16 16:19:16 +02:00
done
_p9k_get_icon '' LEFT_SEGMENT_END_SEPARATOR
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
_p9k_ret += %b%k%f
2019-07-22 22:43:35 +02:00
# Not escaped for historical reasons.
2019-07-23 15:47:25 +02:00
_p9k_ret = '${:-"' $_p9k_ret '"}'
if ( ( _POWERLEVEL9K_PROMPT_ON_NEWLINE ) ) ; then
2019-07-24 14:34:26 +02:00
_p9k_line_suffix_left[ -2] += $_p9k_ret
2019-07-16 16:19:16 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_line_suffix_left[ -1] += $_p9k_ret
2019-07-16 16:19:16 +02:00
fi
fi
if ( ( num_lines > 1 ) ) ; then
2019-07-21 10:48:57 +02:00
_p9k_build_gap_post first
2019-07-24 14:34:26 +02:00
_p9k_line_gap_post[ 1] = $_p9k_ret
2019-07-21 10:48:57 +02:00
2019-07-23 15:47:25 +02:00
if [ [ $+POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX = = 1 || $_POWERLEVEL9K_PROMPT_ON_NEWLINE = = 1 ] ] ; then
2019-07-16 16:19:16 +02:00
_p9k_get_icon '' MULTILINE_FIRST_PROMPT_PREFIX
2019-07-23 15:47:25 +02:00
[ [ _p9k_ret = = *%* ] ] && _p9k_ret += %b%k%f
2019-07-22 22:43:35 +02:00
# Not escaped for historical reasons.
2019-07-23 15:47:25 +02:00
_p9k_ret = '${:-"' $_p9k_ret '"}'
2019-07-24 14:34:26 +02:00
_p9k_line_prefix_left[ 1] = $_p9k_ret $_p9k_line_prefix_left [ 1]
2019-07-16 16:19:16 +02:00
fi
2019-07-23 15:47:25 +02:00
if [ [ $+POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX = = 1 || $_POWERLEVEL9K_PROMPT_ON_NEWLINE = = 1 ] ] ; then
2019-07-16 16:19:16 +02:00
_p9k_get_icon '' MULTILINE_LAST_PROMPT_PREFIX
2019-07-23 15:47:25 +02:00
[ [ _p9k_ret = = *%* ] ] && _p9k_ret += %b%k%f
2019-07-22 22:43:35 +02:00
# Not escaped for historical reasons.
2019-07-23 15:47:25 +02:00
_p9k_ret = '${:-"' $_p9k_ret '"}'
2019-07-24 14:34:26 +02:00
_p9k_line_prefix_left[ -1] = $_p9k_ret $_p9k_line_prefix_left [ -1]
2019-07-16 16:19:16 +02:00
fi
2019-07-17 10:31:59 +02:00
_p9k_get_icon '' MULTILINE_FIRST_PROMPT_SUFFIX
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
[ [ _p9k_ret = = *%* ] ] && _p9k_ret += %b%k%f
_p9k_escape $_p9k_ret
2019-07-24 14:34:26 +02:00
_p9k_line_suffix_right[ 1] += $_p9k_ret
_p9k_line_never_empty_right[ 1] = 1
2019-07-17 10:31:59 +02:00
fi
_p9k_get_icon '' MULTILINE_LAST_PROMPT_SUFFIX
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
[ [ _p9k_ret = = *%* ] ] && _p9k_ret += %b%k%f
_p9k_escape $_p9k_ret
2019-07-24 14:34:26 +02:00
_p9k_line_suffix_right[ -1] += $_p9k_ret
_p9k_line_never_empty_right[ -1] = 1
2019-07-17 10:31:59 +02:00
fi
2019-07-16 16:19:16 +02:00
if ( ( num_lines > 2 ) ) ; then
2019-07-21 10:48:57 +02:00
_p9k_build_gap_post newline
2019-07-24 14:34:26 +02:00
_p9k_line_gap_post[ 2,-2] = ( ${ ${ :- {3..num_lines } } :/*/$_p9k_ret } )
2019-07-21 10:48:57 +02:00
2019-07-23 15:47:25 +02:00
if [ [ $+POWERLEVEL9K_MULTILINE_NEWLINE_PROMPT_PREFIX = = 1 || $_POWERLEVEL9K_PROMPT_ON_NEWLINE = = 1 ] ] ; then
2019-07-16 16:19:16 +02:00
_p9k_get_icon '' MULTILINE_NEWLINE_PROMPT_PREFIX
2019-07-23 15:47:25 +02:00
[ [ _p9k_ret = = *%* ] ] && _p9k_ret += %b%k%f
2019-07-22 22:43:35 +02:00
# Not escaped for historical reasons.
2019-07-23 15:47:25 +02:00
_p9k_ret = '${:-"' $_p9k_ret '"}'
2019-07-24 14:34:26 +02:00
_p9k_line_prefix_left[ 2,-2] = $_p9k_ret ${ ^_p9k_line_prefix_left[2,-2] }
2019-07-16 16:19:16 +02:00
fi
2019-07-17 10:31:59 +02:00
_p9k_get_icon '' MULTILINE_NEWLINE_PROMPT_SUFFIX
2019-07-23 15:47:25 +02:00
if [ [ -n $_p9k_ret ] ] ; then
[ [ _p9k_ret = = *%* ] ] && _p9k_ret += %b%k%f
_p9k_escape $_p9k_ret
2019-07-24 14:34:26 +02:00
_p9k_line_suffix_right[ 2,-2] = ${ ^_p9k_line_suffix_right[2,-2] } $_p9k_ret
_p9k_line_never_empty_right[ 2,-2] = ${ (@)_p9k_line_never_empty_right[2,-2]/0/1 }
2019-07-17 10:31:59 +02:00
fi
2019-07-16 16:19:16 +02:00
fi
fi
}
2019-08-19 12:18:11 +02:00
_p9k_all_params_eq( ) {
local key
for key in ${ parameters [(I) ${ ~1 } ] } ; do
[ [ ${ (P)key } = = $2 ] ] || return
done
}
2019-07-16 16:19:16 +02:00
_p9k_init_prompt( ) {
_p9k_init_lines
2019-07-24 14:34:26 +02:00
_p9k_gap_pre = '${${:-${_p9k_x::=0}${_p9k_y::=1024}${_p9k_p::=$_p9k_lprompt$_p9k_rprompt}'
2019-07-16 16:19:16 +02:00
repeat 10; do
2019-07-24 14:34:26 +02:00
_p9k_gap_pre += '${_p9k_m::=$(((_p9k_x+_p9k_y)/2))}'
_p9k_gap_pre += '${_p9k_xy::=${${(%):-$_p9k_p%$_p9k_m(l./$_p9k_m;$_p9k_y./$_p9k_x;$_p9k_m)}##*/}}'
_p9k_gap_pre += '${_p9k_x::=${_p9k_xy%;*}}'
_p9k_gap_pre += '${_p9k_y::=${_p9k_xy#*;}}'
2019-07-16 16:19:16 +02:00
done
2019-07-24 14:34:26 +02:00
_p9k_gap_pre += '${_p9k_m::=$((_p9k_clm-_p9k_x-_p9k_ind-1))}'
_p9k_gap_pre += '}+}'
2019-07-16 16:19:16 +02:00
2019-07-24 14:34:26 +02:00
_p9k_prompt_prefix_left = '${${_p9k_clm::=$COLUMNS}+}${${COLUMNS::=1024}+}'
_p9k_prompt_prefix_right = '${${_p9k_clm::=$COLUMNS}+}${${COLUMNS::=1024}+}'
_p9k_prompt_suffix_left = '${${COLUMNS::=$_p9k_clm}+}'
_p9k_prompt_suffix_right = '${${COLUMNS::=$_p9k_clm}+}'
2019-07-16 16:19:16 +02:00
2019-07-24 14:34:26 +02:00
_p9k_prompt_prefix_left += '%b%k%f'
2019-07-16 16:19:16 +02:00
# Bug fixed in: https://github.com/zsh-users/zsh/commit/3eea35d0853bddae13fa6f122669935a01618bf9.
# If affects most terminals when RPROMPT is non-empty and ZLE_RPROMPT_INDENT is zero.
# We can work around it as long as RPROMPT ends with a space.
2019-07-24 14:34:26 +02:00
if [ [ -n $_p9k_line_segments_right [ -1] && $_p9k_line_never_empty_right [ -1] = = 0 &&
2019-08-19 12:18:11 +02:00
$ZLE_RPROMPT_INDENT = = 0 ] ] &&
_p9k_all_params_eq 'POWERLEVEL9K_*WHITESPACE_BETWEEN_RIGHT_SEGMENTS' ' ' &&
_p9k_all_params_eq 'POWERLEVEL9K_*RIGHT_RIGHT_WHITESPACE' ' ' &&
_p9k_all_params_eq 'POWERLEVEL9K_*RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL' '' &&
! is-at-least 5.7.2; then
2019-07-24 14:34:26 +02:00
_p9k_emulate_zero_rprompt_indent = 1
_p9k_prompt_prefix_left += '${${:-${_p9k_real_zle_rprompt_indent:=$ZLE_RPROMPT_INDENT}${ZLE_RPROMPT_INDENT::=1}${_p9k_ind::=0}}+}'
_p9k_line_suffix_right[ -1] = '${_p9k_sss:+${_p9k_sss% }%E}'
2019-07-16 16:19:16 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_emulate_zero_rprompt_indent = 0
_p9k_prompt_prefix_left += '${${_p9k_ind::=${${ZLE_RPROMPT_INDENT:-1}/#-*/0}}+}'
2019-07-16 16:19:16 +02:00
fi
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_PROMPT_ADD_NEWLINE ) ) ; then
2019-07-24 14:34:26 +02:00
repeat $_POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT _p9k_prompt_prefix_left += $'\n'
2019-07-16 16:19:16 +02:00
fi
2019-07-24 14:34:26 +02:00
_p9k_t = ( $'\n' '' )
_p9k_prompt_overflow_bug && _p9k_t[ 2] = '%{%G%}'
2019-07-16 16:19:16 +02:00
2019-07-23 15:47:25 +02:00
if ( ( _POWERLEVEL9K_SHOW_RULER ) ) ; then
2019-07-16 16:19:16 +02:00
_p9k_get_icon '' RULER_CHAR
2019-07-23 15:47:25 +02:00
local ruler_char = $_p9k_ret
2019-07-16 16:19:16 +02:00
_p9k_prompt_length $ruler_char
2019-07-23 15:47:25 +02:00
if ( ( _p9k_ret = = 1 && $# ruler_char = = 1 ) ) ; then
2019-07-16 16:19:16 +02:00
_p9k_color prompt_ruler BACKGROUND ""
2019-07-23 15:47:25 +02:00
_p9k_background $_p9k_ret
2019-07-24 14:34:26 +02:00
_p9k_prompt_prefix_left += %b$_p9k_ret
2019-07-16 16:19:16 +02:00
_p9k_color prompt_ruler FOREGROUND ""
2019-07-23 15:47:25 +02:00
_p9k_foreground $_p9k_ret
2019-07-24 14:34:26 +02:00
_p9k_prompt_prefix_left += $_p9k_ret
2019-07-16 16:19:16 +02:00
[ [ $ruler_char = = '.' ] ] && local sep = ',' || local sep = '.'
2019-07-24 14:34:26 +02:00
local ruler_len = '${$((_p9k_clm-_p9k_ind))/#-*/0}'
_p9k_prompt_prefix_left += " \${(pl $sep $ruler_len $sep $sep ${ (q)ruler_char } $sep )}%k%f "
_p9k_prompt_prefix_left += '$_p9k_t[$((1+!_p9k_ind))]'
2019-07-16 16:19:16 +02:00
else
2019-08-05 10:37:04 +02:00
print -rP -- "%F{red}WARNING!%f %BPOWERLEVEL9K_RULER_CHAR%b is not one character long. Ruler won't be rendered."
print -rP -- "Either change the value of %BPOWERLEVEL9K_RULER_CHAR%b or set %BPOWERLEVEL9K_SHOW_RULER=false%b to"
print -rP -- "disable ruler."
2019-07-16 16:19:16 +02:00
fi
fi
if [ [ $ITERM_SHELL_INTEGRATION_INSTALLED = = Yes ] ] ; then
2019-07-24 14:34:26 +02:00
_p9k_prompt_prefix_left += " %{ $( iterm2_prompt_mark) %} "
2019-07-16 16:19:16 +02:00
fi
2019-07-27 12:09:09 +02:00
[ [ -o transient_rprompt && -n " $_p9k_line_segments_right [1,-2] " ] ] ||
( _p9k_segment_in_use time && ( ( _POWERLEVEL9K_TIME_UPDATE_ON_COMMAND ) ) )
_p9k_reset_on_line_finish = $(( !$? ))
2019-07-27 12:14:16 +02:00
if ( ( _p9k_reset_on_line_finish ) ) || _p9k_segment_in_use status; then
2019-07-16 16:19:16 +02:00
_p9k_wrap_zle_widget zle-line-finish _p9k_zle_line_finish
fi
}
2019-07-20 14:14:42 +02:00
_p9k_init_ssh( ) {
# The following code is based on Pure:
# https://github.com/sindresorhus/pure/blob/e8abf9d37185ec9b7b4398ca9c5eba555a1028eb/pure.zsh.
#
# License: https://github.com/sindresorhus/pure/blob/e8abf9d37185ec9b7b4398ca9c5eba555a1028eb/license.
2019-08-20 11:19:11 +02:00
[ [ -n $P9K_SSH ] ] && return
typeset -gix P9K_SSH = 0
2019-07-20 14:14:42 +02:00
if [ [ -n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION ] ] ; then
2019-08-20 11:19:11 +02:00
P9K_SSH = 1
2019-07-20 14:14:42 +02:00
return
fi
# When changing user on a remote system, the $SSH_CONNECTION environment variable can be lost.
# Attempt detection via `who`.
( ( $+commands[ who] ) ) || return
local ipv6 = '(([0-9a-fA-F]+:)|:){2,}[0-9a-fA-F]+' # Simplified, only checks partial pattern.
local ipv4 = '([0-9]{1,3}\.){3}[0-9]+' # Simplified, allows invalid ranges.
# Assume two non-consecutive periods represents a hostname. Matches `x.y.z`, but not `x.y`.
local hostname = '([.][^. ]+){2}'
2019-08-20 11:19:11 +02:00
local w
w = " $( who -m 2>/dev/null) " || w = ${ (@M) ${ (f) " $( who 2>/dev/null) " } : #*[[ : space : ]] ${ TTY #/dev/ } [[ : space : ]]* }
2019-07-20 14:14:42 +02:00
# Usually the remote address is surrounded by parenthesis but not on all systems (e.g., Busybox).
2019-08-20 11:19:11 +02:00
[ [ $w = ~ " \(?( $ipv4 | $ipv6 | $hostname )\)?\$ " ] ] && P9K_SSH = 1
2019-07-20 14:14:42 +02:00
}
2019-07-24 18:34:29 +02:00
_p9k_must_init( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-07-31 09:53:00 +02:00
local -a param_keys = (
${ (o)parameters[(I)(POWERLEVEL9K_*|GITSTATUS_LOG_LEVEL|GITSTATUS_ENABLE_LOGGING|GITSTATUS_DAEMON|GITSTATUS_NUM_THREADS|DEFAULT_USER|ZLE_RPROMPT_INDENT)] } )
2019-07-24 18:34:29 +02:00
local IFS param_sig
IFS = $'\1' param_sig = " ${ (@)param_keys : /(#b)(*)/ $match [1]= \$ $match [1] } "
IFS = $'\2' eval " param_sig=x\" $param_sig \" "
[ [ -o transient_rprompt ] ] && param_sig += t
[ [ $param_sig = = $_p9k_param_sig ] ] && return 1
[ [ -n $_p9k_param_sig ] ] && _p9k_deinit
_p9k_param_sig = $param_sig
}
function _p9k_set_os( ) {
_p9k_os = $1
_p9k_get_icon prompt_os_icon $2
_p9k_os_icon = $_p9k_ret
}
2019-06-01 17:54:53 +02:00
_p9k_init( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-07-24 18:34:29 +02:00
2019-06-01 17:54:53 +02:00
_p9k_init_icons
2019-07-24 14:34:26 +02:00
_p9k_init_vars
2019-07-23 16:20:59 +02:00
_p9k_init_params
2019-07-16 16:19:16 +02:00
_p9k_init_prompt
2019-06-01 17:54:53 +02:00
2019-07-29 14:18:57 +02:00
local uname = " $( uname) "
if [ [ $uname = = Linux && " $( uname -o 2>/dev/null) " = = Android ] ] ; then
2019-07-24 18:34:29 +02:00
_p9k_set_os Android ANDROID_ICON
2019-06-01 17:54:53 +02:00
else
2019-07-16 16:19:16 +02:00
case $uname in
2019-07-24 18:34:29 +02:00
SunOS) _p9k_set_os Solaris SUNOS_ICON; ;
Darwin) _p9k_set_os OSX APPLE_ICON; ;
CYGWIN_NT-* | MSYS_NT-*) _p9k_set_os Windows WINDOWS_ICON; ;
FreeBSD| OpenBSD| DragonFly) _p9k_set_os BSD FREEBSD_ICON; ;
2019-06-01 17:54:53 +02:00
Linux)
2019-07-24 14:34:26 +02:00
_p9k_os = 'Linux'
2019-06-01 17:54:53 +02:00
local os_release_id
2019-08-07 11:04:35 +02:00
if [ [ -r /etc/os-release ] ] ; then
local lines = ( ${ (f) " $( </etc/os-release) " } )
lines = ( ${ (@M)lines : #ID=* } )
( ( $# lines = = 1 ) ) && os_release_id = ${ lines [1]#ID= }
fi
case $os_release_id in
2019-07-24 18:34:29 +02:00
*arch*) _p9k_set_os Linux LINUX_ARCH_ICON; ;
*debian*) _p9k_set_os Linux LINUX_DEBIAN_ICON; ;
*raspbian*) _p9k_set_os Linux LINUX_RASPBIAN_ICON; ;
*ubuntu*) _p9k_set_os Linux LINUX_UBUNTU_ICON; ;
*elementary*) _p9k_set_os Linux LINUX_ELEMENTARY_ICON; ;
*fedora*) _p9k_set_os Linux LINUX_FEDORA_ICON; ;
*coreos*) _p9k_set_os Linux LINUX_COREOS_ICON; ;
*gentoo*) _p9k_set_os Linux LINUX_GENTOO_ICON; ;
*mageia*) _p9k_set_os Linux LINUX_MAGEIA_ICON; ;
*centos*) _p9k_set_os Linux LINUX_CENTOS_ICON; ;
*opensuse*| *tumbleweed*) _p9k_set_os Linux LINUX_OPENSUSE_ICON; ;
*sabayon*) _p9k_set_os Linux LINUX_SABAYON_ICON; ;
*slackware*) _p9k_set_os Linux LINUX_SLACKWARE_ICON; ;
*linuxmint*) _p9k_set_os Linux LINUX_MINT_ICON; ;
*alpine*) _p9k_set_os Linux LINUX_ALPINE_ICON; ;
*aosc*) _p9k_set_os Linux LINUX_AOSC_ICON; ;
*nixos*) _p9k_set_os Linux LINUX_NIXOS_ICON; ;
*devuan*) _p9k_set_os Linux LINUX_DEVUAN_ICON; ;
*manjaro*) _p9k_set_os Linux LINUX_MANJARO_ICON; ;
*) _p9k_set_os Linux LINUX_ICON; ;
2019-06-01 17:54:53 +02:00
esac
; ;
esac
fi
2019-07-23 15:47:25 +02:00
if [ [ $_POWERLEVEL9K_COLOR_SCHEME = = light ] ] ; then
2019-07-24 14:34:26 +02:00
_p9k_color1 = 7
_p9k_color2 = 0
2019-06-01 17:54:53 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_color1 = 0
_p9k_color2 = 7
2019-06-01 17:54:53 +02:00
fi
2019-07-24 14:34:26 +02:00
# Someone might be using these.
typeset -g OS = $_p9k_os
typeset -g DEFAULT_COLOR = $_p9k_color1
typeset -g DEFAULT_COLOR_INVERTED = $_p9k_color2
_p9k_battery_states = (
2019-07-20 15:40:15 +02:00
'LOW' 'red'
'CHARGING' 'yellow'
'CHARGED' 'green'
2019-07-24 14:34:26 +02:00
'DISCONNECTED' " $_p9k_color2 "
2019-06-15 16:10:51 +02:00
)
2019-07-16 16:19:16 +02:00
local -i i = 0
2019-07-24 14:34:26 +02:00
local -a left_segments = ( ${ (@0)_p9k_line_segments_left[@] } )
2019-07-24 18:34:29 +02:00
_p9k_left_join = ( 1)
2019-07-16 16:19:16 +02:00
for ( ( i = 2; i <= $# left_segments; ++i) ) ; do
local elem = $left_segments [ i]
2019-06-01 17:54:53 +02:00
if [ [ $elem = = *_joined ] ] ; then
2019-07-24 14:34:26 +02:00
_p9k_left_join += $_p9k_left_join [ ( ( i-1) ) ]
2019-06-01 17:54:53 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_left_join += $i
2019-06-01 17:54:53 +02:00
fi
done
2019-07-24 14:34:26 +02:00
local -a right_segments = ( ${ (@0)_p9k_line_segments_right[@] } )
2019-07-24 18:34:29 +02:00
_p9k_right_join = ( 1)
2019-07-16 16:19:16 +02:00
for ( ( i = 2; i <= $# right_segments; ++i) ) ; do
local elem = $right_segments [ i]
2019-06-01 17:54:53 +02:00
if [ [ $elem = = *_joined ] ] ; then
2019-07-24 14:34:26 +02:00
_p9k_right_join += $_p9k_right_join [ ( ( i-1) ) ]
2019-06-01 17:54:53 +02:00
else
2019-07-24 14:34:26 +02:00
_p9k_right_join += $i
2019-06-01 17:54:53 +02:00
fi
done
2019-07-24 21:07:28 +02:00
if _p9k_segment_in_use vcs; then
_p9k_vcs_info_init
2019-08-05 10:37:04 +02:00
local gitstatus_dir = ${ _POWERLEVEL9K_GITSTATUS_DIR :- ${ __p9k_root_dir } /gitstatus }
2019-07-23 15:47:25 +02:00
if [ [ $_POWERLEVEL9K_DISABLE_GITSTATUS = = 0 && -n $_POWERLEVEL9K_VCS_BACKENDS [ ( r) git] ] ] ; then
2019-08-05 10:37:04 +02:00
if [ [ -z $GITSTATUS_DAEMON && " $( uname -m) " = = i686 && -z $gitstatus_dir /bin/*-i686( -static| ) ( #qN) ]]; then
_POWERLEVEL9K_DISABLE_GITSTATUS = 1
>& 2 echo -E - " ${ (%) :- [%1FERROR%f] : %BPowerlevel10k%b is unable to use %Bgitstatus%b. Git prompt will be slow. } "
>& 2 echo -E - ""
>& 2 echo -E - " ${ (%) :- Reason : There is no %Bgitstatusd%b binary for i686 (32-bit Intel architecture). } "
>& 2 echo -E - ""
>& 2 echo -E - " ${ (%) :- You can : } "
>& 2 echo -E - ""
>& 2 echo -E - " ${ (%) :- - Do nothing. } "
>& 2 echo -E - ""
>& 2 echo -E - " ${ (%) :- * You %Bwill%b see this error message every time you start zsh. } "
>& 2 echo -E - " ${ (%) :- * Git prompt will be %Bslow%b. } "
>& 2 echo -E - ""
>& 2 echo -E - " ${ (%) :- - Set %BPOWERLEVEL9K_DISABLE_GITSTATUS=true%b at the bottom of %B $__p9k_zshrc_u %b. } "
>& 2 echo -E - " ${ (%) :- You can do this by running the following command : } "
>& 2 echo -E - ""
>& 2 echo -E - " ${ (%) :- %2Fecho%f %3F 'POWERLEVEL9K_DISABLE_GITSTATUS=true' %f >>! $__p9k_zshrc_u } "
>& 2 echo -E - ""
>& 2 echo -E - " ${ (%) :- * You %Bwill not%b see this error message again. } "
>& 2 echo -E - " ${ (%) :- * Git prompt will be %Bslow%b. } "
>& 2 echo -E - ""
2019-08-05 10:43:40 +02:00
>& 2 echo -E - " ${ (%) :- - Upgrade to a 64-bit OS. } "
>& 2 echo -E - ""
>& 2 echo -E - " ${ (%) :- * You %Bwill not%b see this error message again. } "
>& 2 echo -E - " ${ (%) :- * Git prompt will be %Bfast%b. } "
>& 2 echo -E - ""
2019-08-05 10:37:04 +02:00
>& 2 echo -E - " ${ (%) :- - Compile %Bgitstatusd%b and set %BGITSTATUS_DAEMON=/path/to/gitstatusd%b at } "
>& 2 echo -E - " ${ (%) :- the bottom of %B $__p9k_zshrc_u %b. See instructions at } "
>& 2 echo -E - " ${ (%) :- https : //github.com/romkatv/gitstatus/blob/master/README.md#compiling. } "
>& 2 echo -E - ""
>& 2 echo -E - " ${ (%) :- * You %Bwill not%b see this error message again. } "
>& 2 echo -E - " ${ (%) :- * Git prompt will be %Bfast%b. } "
else
source $gitstatus_dir /gitstatus.plugin.zsh
gitstatus_start \
-s $_POWERLEVEL9K_VCS_STAGED_MAX_NUM \
-u $_POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM \
-d $_POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM \
2019-08-05 22:26:23 +02:00
-c $_POWERLEVEL9K_VCS_CONFLICTED_MAX_NUM \
2019-08-05 10:37:04 +02:00
-m $_POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY \
POWERLEVEL9K || _POWERLEVEL9K_DISABLE_GITSTATUS = 1
fi
2019-06-01 17:54:53 +02:00
fi
fi
2019-07-24 21:07:28 +02:00
if _p9k_segment_in_use todo; then
2019-07-24 14:34:26 +02:00
local todo = $commands [ todo.sh]
if [ [ -n $todo ] ] ; then
local bash = ${ commands [bash] :- : }
2019-07-29 14:18:57 +02:00
_p9k_todo_file = " $( $bash 2>/dev/null -c "
2019-07-24 14:34:26 +02:00
[ -e \" \$ TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE = \$ HOME/.todo/config
[ -e \" \$ TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE = \$ HOME/todo.cfg
[ -e \" \$ TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE = \$ HOME/.todo.cfg
[ -e \" \$ TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE = \$ { XDG_CONFIG_HOME:-\$ HOME/.config} /todo/config
[ -e \" \$ TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE = ${ (qqq)todo : h } /todo.cfg
[ -e \" \$ TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE = \$ { TODOTXT_GLOBAL_CFG_FILE:-/etc/todo/config}
[ -r \" \$ TODOTXT_CFG_FILE\" ] || exit
source \" \$ TODOTXT_CFG_FILE\" & >/dev/null
2019-07-29 14:18:57 +02:00
echo \" \$ TODO_FILE\" ")"
2019-07-24 14:34:26 +02:00
fi
fi
2019-07-24 21:07:28 +02:00
if _p9k_segment_in_use load; then
2019-07-24 14:34:26 +02:00
case $_p9k_os in
2019-07-29 14:18:57 +02:00
OSX) ( ( $+commands[ sysctl] ) ) && _p9k_num_cpus = " $( sysctl -n hw.logicalcpu 2>/dev/null) " ; ;
BSD) ( ( $+commands[ sysctl] ) ) && _p9k_num_cpus = " $( sysctl -n hw.ncpu 2>/dev/null) " ; ;
*) ( ( $+commands[ nproc] ) ) && _p9k_num_cpus = " $( nproc 2>/dev/null) " ; ;
2019-07-24 14:34:26 +02:00
esac
fi
2019-07-24 21:07:28 +02:00
if _p9k_segment_in_use dir; then
2019-07-24 14:34:26 +02:00
if ( ( $+_POWERLEVEL9K_DIR_CLASSES ) ) ; then
2019-08-20 14:56:43 +02:00
[ [ -z $_p9k_locale ] ] || local LC_ALL = $_p9k_locale
2019-07-29 12:38:47 +02:00
local -i i = 3
for ( ( ; i <= $# _POWERLEVEL9K_DIR_CLASSES; i += 3) ) ; do
2019-07-24 14:34:26 +02:00
_POWERLEVEL9K_DIR_CLASSES[ i] = ${ (g : : )_POWERLEVEL9K_DIR_CLASSES[i] }
done
else
typeset -ga _POWERLEVEL9K_DIR_CLASSES = ( )
_p9k_get_icon prompt_dir_ETC ETC_ICON
_POWERLEVEL9K_DIR_CLASSES += ( '/etc|/etc/*' ETC " $_p9k_ret " )
_p9k_get_icon prompt_dir_HOME HOME_ICON
_POWERLEVEL9K_DIR_CLASSES += ( '~' HOME " $_p9k_ret " )
_p9k_get_icon prompt_dir_HOME_SUBFOLDER HOME_SUB_ICON
_POWERLEVEL9K_DIR_CLASSES += ( '~/*' HOME_SUBFOLDER " $_p9k_ret " )
_p9k_get_icon prompt_dir_DEFAULT FOLDER_ICON
_POWERLEVEL9K_DIR_CLASSES += ( '*' DEFAULT " $_p9k_ret " )
fi
fi
2019-06-21 19:49:36 +02:00
_p9k_init_async_pump
2019-07-24 21:07:28 +02:00
if _p9k_segment_in_use vi_mode && ( ( $+_POWERLEVEL9K_VI_VISUAL_MODE_STRING ) ) || _p9k_segment_in_use prompt_char; then
2019-07-12 11:55:32 +02:00
_p9k_wrap_zle_widget zle-line-pre-redraw _p9k_zle_line_pre_redraw
2019-06-01 17:54:53 +02:00
fi
2019-07-24 21:07:28 +02:00
if _p9k_segment_in_use dir &&
2019-07-23 15:47:25 +02:00
[ [ $_POWERLEVEL9K_SHORTEN_STRATEGY = = truncate_with_package_name && $+commands[ jq] = = 0 ] ] ; then
2019-08-05 10:37:04 +02:00
print -rP -- '%F{yellow}WARNING!%f %BPOWERLEVEL9K_SHORTEN_STRATEGY=truncate_with_package_name%b requires %F{green}jq%f.'
print -rP -- 'Either install %F{green}jq%f or change the value of %BPOWERLEVEL9K_SHORTEN_STRATEGY%b.'
2019-06-01 17:54:53 +02:00
fi
2019-07-26 15:35:46 +02:00
if _p9k_segment_in_use status; then
typeset -g _p9k_exitcode2str = ( { 0..255} )
local -i i = 2
if ( ( !_POWERLEVEL9K_STATUS_HIDE_SIGNAME ) ) ; then
for ( ( ; i <= $# signals; ++i) ) ; do
local sig = $signals [ i]
( ( _POWERLEVEL9K_STATUS_VERBOSE_SIGNAME ) ) && sig = " SIG ${ sig } ( $(( i-1)) ) "
_p9k_exitcode2str[ $(( 128 + i)) ] = $sig
done
fi
fi
2019-07-16 16:19:16 +02:00
_p9k_wrap_zle_widget zle-keymap-select _p9k_zle_keymap_select
2019-07-24 18:34:29 +02:00
}
2019-06-01 17:54:53 +02:00
2019-07-24 18:34:29 +02:00
_p9k_deinit( ) {
( ( $+functions[ gitstatus_stop] ) ) && gitstatus_stop POWERLEVEL9K
_p9k_deinit_async_pump
unset -m '(_POWERLEVEL9K_|P9K_|_p9k_)*'
2019-06-01 17:54:53 +02:00
}
2019-07-24 15:52:54 +02:00
typeset -gi __p9k_enabled = 0
2019-07-30 15:11:58 +02:00
typeset -gi __p9k_configured = 0
2019-07-24 15:52:54 +02:00
2019-06-01 17:54:53 +02:00
prompt_powerlevel9k_setup( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-06-01 17:54:53 +02:00
prompt_powerlevel9k_teardown
2019-07-24 15:52:54 +02:00
__p9k_enabled = 1
2019-07-24 21:07:28 +02:00
add-zsh-hook preexec _p9k_preexec
add-zsh-hook precmd _p9k_precmd
2019-06-01 17:54:53 +02:00
}
prompt_powerlevel9k_teardown( ) {
2019-08-05 10:37:04 +02:00
emulate -L zsh && setopt no_hist_expand extended_glob no_prompt_bang prompt_{ cr,percent,subst,sp}
2019-07-24 21:07:28 +02:00
add-zsh-hook -D precmd '(_p9k_|powerlevel9k_)*'
add-zsh-hook -D preexec '(_p9k_|powerlevel9k_)*'
2019-06-01 17:54:53 +02:00
PROMPT = '%m%# '
RPROMPT =
2019-07-24 15:52:54 +02:00
if ( ( __p9k_enabled ) ) ; then
2019-07-24 18:34:29 +02:00
_p9k_deinit
2019-07-24 15:52:54 +02:00
__p9k_enabled = 0
fi
2019-06-01 17:54:53 +02:00
}
2019-07-31 19:41:14 +02:00
typeset -gr __p9k_p10k_usage = " Usage: %2Fp10k%f %Bcommand%b [options]
Commands:
%Bconfigure%b run interactive configuration wizard
%Bsegment%b print a user-defined prompt segment
%Bhelp%b print this help message"
2019-07-31 19:54:49 +02:00
typeset -gr __p9k_p10k_segment_usage = " Usage: %2Fp10k%f %Bsegment%b [-h] [{+|-}re] [-s state] [-b bg] [-f fg] [-i icon] [-c cond] [-t text]
2019-07-31 19:41:14 +02:00
2019-07-31 19:54:49 +02:00
Print a user-defined prompt segment. Can be called only during prompt rendering.
2019-07-31 19:41:14 +02:00
Options:
-t text segment's main content; will undergo prompt expansion: ' %%F{ blue} %%*%%f' will
show as %F{ blue} %*%f; default is empty
-i icon segment' s icon; default is empty
-r icon is a symbolic reference that needs to be resolved; for example, 'LOCK_ICON'
+r icon is already resolved and should be printed literally; for example, '⭐' ;
this is the default; you can also use \$ '\u2B50' if you don' t want to have
non-ascii characters in source code
-b bg background color; for example, 'blue' , '4' , or '#0000ff' ; empty value means
transparent background, as in '%%k' ; default is black
-f fg foreground color; for example, 'blue' , '4' , or '#0000ff' ; empty value means
default foreground color, as in '%%f' ; default is empty
-s state segment' s state for the purpose of applying styling options; if you want to
to be able to use POWERLEVEL9K parameters to specify different colors or icons
depending on some property, use different states for different values of that
property
-c condition; if empty after parameter expansion and process substitution, the
segment is hidden; this is an advanced feature, use with caution; default is '1'
-e segment' s main content will undergo parameter expansion and process
substitution; the content will be surrounded with double quotes and thus
should quote its own double quotes; this is an advanced feature, use with
caution
+e segment' s main content should not undergo parameter expansion and process
substitution; this is the default
-h print this help message
Example: 'core' segment tells you if there is a file name 'core' in the current directory.
- Segment's icon is ' ⭐' .
- Segment's text is the file' s size in bytes.
- If you have permissions to delete the file, state is DELETABLE. If not, it' s PROTECTED.
zmodload -F zsh/stat b:zstat
function prompt_core( ) {
local size = ( )
if ! zstat -A size +size core 2>/dev/null; then
# No 'core' file in the current directory.
return
fi
if [ [ -w . ] ] ; then
local state = DELETABLE
else
local state = PROTECTED
fi
2019-08-05 10:37:04 +02:00
p10k segment -s \\ \$ state -i '⭐' -f blue -t \\ \$ { size[ 1] } b
2019-07-31 19:41:14 +02:00
}
To enable this segment, add 'core' to POWERLEVEL9K_LEFT_PROMPT_ELEMENTS or
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS.
Example customizations:
2019-07-31 19:54:49 +02:00
# Override default foreground.
2019-07-31 19:41:14 +02:00
POWERLEVEL9K_CORE_FOREGROUND = red
2019-07-31 19:54:49 +02:00
# Override foreground when DELETABLE.
2019-07-31 19:41:14 +02:00
POWERLEVEL9K_CORE_DELETABLE_BACKGROUND = green
# Override icon when PROTECTED.
POWERLEVEL9K_CORE_PROTECTED_VISUAL_IDENTIFIER_EXPANSION = '❎'
# Don't show file size when PROTECTED.
POWERLEVEL9K_CORE_PROTECTED_CONTENT_EXPANSION = '' "
typeset -gr __p9k_p10k_configure_usage = " Usage: %2Fp10k%f %Bconfigure%b
Run interactive configuration wizard."
2019-07-31 18:21:37 +02:00
function p10k( ) {
2019-07-31 19:41:14 +02:00
emulate -L zsh
setopt no_hist_expand extended_glob prompt_percent prompt_subst
if ( ( !ARGC ) ) ; then
2019-08-05 10:37:04 +02:00
print -rP -- $__p9k_p10k_usage >& 2
2019-07-31 18:21:37 +02:00
return 1
fi
2019-07-31 19:41:14 +02:00
case $1 in
segment)
shift
2019-07-31 19:54:49 +02:00
local -i num_opts = ARGC
2019-07-31 19:41:14 +02:00
local opt state bg = 0 fg icon cond text ref = 0 expand = 0
while getopts ':s:b:f:i:c:t:reh' opt; do
case $opt in
s) state = $OPTARG ; ;
b) bg = $OPTARG ; ;
f) fg = $OPTARG ; ;
i) icon = $OPTARG ; ;
c) cond = ${ OPTARG :- '${:-}' } ; ;
t) text = $OPTARG ; ;
r) ref = 1; ;
e) expand = 1; ;
+r) ref = 0; ;
+e) expand = 0; ;
2019-08-05 10:37:04 +02:00
h) print -rP -- $__p9k_p10k_segment_usage ; return 0; ;
?) print -rP -- $__p9k_p10k_segment_usage >& 2; return 1; ;
2019-07-31 19:41:14 +02:00
esac
done
if ( ( OPTIND <= ARGC ) ) ; then
2019-08-05 10:37:04 +02:00
print -rP -- $__p9k_p10k_segment_usage >& 2
2019-07-31 19:54:49 +02:00
return 1
fi
if [ [ -z $_p9k_prompt_side ] ] ; then
2019-08-05 10:37:04 +02:00
print -rP -- "%1F[ERROR]%f %Bp10k segment%b: can be called only during prompt rendering." >& 2
2019-07-31 19:54:49 +02:00
if ( ( !ARGC ) ) ; then
2019-08-05 10:37:04 +02:00
print -rP -- ""
print -rP -- "For help, type:" >& 2
print -rP -- ""
print -rP -- " %2Fp10k%f %Bhelp%b %Bsegment%b" >& 2
2019-07-31 19:54:49 +02:00
fi
2019-07-31 19:41:14 +02:00
return 1
fi
( ( ref ) ) || icon = $'\1' $icon
" _p9k_ ${ _p9k_prompt_side } _prompt_segment " " prompt_ ${ _p9k_segment_name } ${ state : +_ ${ (U)state } } " \
" $bg " " ${ fg :- $_p9k_color1 } " " $icon " " $expand " " $cond " " $text "
return 0
; ;
configure)
if ( ( ARGC > 1 ) ) ; then
2019-08-05 10:37:04 +02:00
print -rP -- $__p9k_p10k_configure_usage >& 2
2019-07-31 19:41:14 +02:00
return 1
fi
p9k_configure " $@ "
; ;
help )
local var = __p9k_p10k_$2 _usage
if ( ( $+parameters[ $var ] ) ) ; then
2019-08-05 10:37:04 +02:00
print -rP -- ${ (P)var }
2019-07-31 19:41:14 +02:00
return 0
elif ( ( ARGC = = 1 ) ) ; then
2019-08-05 10:37:04 +02:00
print -rP -- $__p9k_p10k_usage
2019-07-31 19:41:14 +02:00
return 0
else
2019-08-05 10:37:04 +02:00
print -rP -- $__p9k_p10k_usage >& 2
2019-07-31 19:41:14 +02:00
return 1
fi
; ;
*)
2019-08-05 10:37:04 +02:00
print -rP -- $__p9k_p10k_usage >& 2
2019-07-31 19:41:14 +02:00
return 1
; ;
esac
2019-07-31 18:21:37 +02:00
}
2019-07-31 13:03:17 +02:00
# Hook for zplugin.
powerlevel10k_plugin_unload( ) { prompt_powerlevel9k_teardown; }
2019-07-24 14:34:26 +02:00
autoload -Uz colors && colors
2019-06-01 17:54:53 +02:00
autoload -Uz add-zsh-hook
zmodload zsh/datetime
zmodload zsh/mathfunc
zmodload zsh/system
zmodload -F zsh/stat b:zstat
2019-07-25 14:11:04 +02:00
zmodload -F zsh/net/socket b:zsocket
2019-06-01 17:54:53 +02:00
2019-08-20 11:19:11 +02:00
_p9k_init_ssh
2019-07-02 08:38:35 +02:00
prompt_powerlevel9k_setup