2015-06-07 01:10:27 +00:00
|
|
|
# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
|
2015-04-02 17:45:53 +00:00
|
|
|
################################################################
|
2019-03-22 09:00:27 +00:00
|
|
|
# Powerlevel10k Theme
|
2019-03-01 20:18:05 +00:00
|
|
|
# https://github.com/romkatv/powerlevel10k
|
|
|
|
#
|
2019-03-22 09:01:16 +00:00
|
|
|
# Forked from Powerlevel9k Theme
|
2015-02-01 23:33:21 +00:00
|
|
|
# https://github.com/bhilburn/powerlevel9k
|
2014-12-05 18:15:35 +00:00
|
|
|
#
|
2019-03-22 09:01:16 +00:00
|
|
|
# Which in turn was forked from Agnoster Theme
|
2019-03-22 09:00:27 +00:00
|
|
|
# https://github.com/robbyrussell/oh-my-zsh/blob/74177c5320b2a1b2f8c4c695c05984b57fd7c6ea/themes/agnoster.zsh-theme
|
2015-04-02 17:45:53 +00:00
|
|
|
################################################################
|
2014-12-05 01:26:21 +00:00
|
|
|
|
2015-04-02 17:45:53 +00:00
|
|
|
################################################################
|
2019-03-01 20:18:05 +00:00
|
|
|
# For basic documentation, please refer to the README.md in the
|
|
|
|
# top-level directory.
|
2015-04-02 17:45:53 +00:00
|
|
|
################################################################
|
2014-12-05 01:26:21 +00:00
|
|
|
|
2015-09-03 19:33:18 +00:00
|
|
|
## Turn on for Debugging
|
2018-01-05 07:04:04 +00:00
|
|
|
#PS4='%s%f%b%k%F{blue}%{λ%}%L %F{240}%N:%i%(?.. %F{red}%?) %1(_.%F{yellow}%-1_ .)%s%f%b%k '
|
2015-06-06 17:38:20 +00:00
|
|
|
#zstyle ':vcs_info:*+*:*' debug true
|
|
|
|
#set -o xtrace
|
2014-12-05 18:15:35 +00:00
|
|
|
|
2019-04-29 09:27:41 +00:00
|
|
|
if test -z "${ZSH_VERSION}"; then
|
|
|
|
echo "powerlevel10k: unsupported shell; try zsh instead" >&2
|
|
|
|
return 1
|
|
|
|
exit 1
|
2019-03-19 14:40:30 +00:00
|
|
|
fi
|
|
|
|
|
2019-04-30 11:39:27 +00:00
|
|
|
if ! autoload -U is-at-least || ! is-at-least 5.1; then
|
2019-03-30 08:32:26 +00:00
|
|
|
() {
|
2019-04-30 11:39:27 +00:00
|
|
|
>&2 echo -E "You are using ZSH version $ZSH_VERSION. The minimum required version for Powerlevel10k is 5.1."
|
2019-03-30 08:32:26 +00:00
|
|
|
>&2 echo -E "Type 'echo \$ZSH_VERSION' to see your current zsh version."
|
|
|
|
local def=${SHELL:c:A}
|
|
|
|
local cur=${${ZSH_ARGZERO#-}:c:A}
|
|
|
|
local cur_v=$($cur -c 'echo -E $ZSH_VERSION' 2>/dev/null)
|
|
|
|
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-04-30 11:39:27 +00:00
|
|
|
if [[ -n $other ]] && $other -c 'autoload -U is-at-least && is-at-least 5.1' &>/dev/null; then
|
2019-03-30 08:32:26 +00:00
|
|
|
local other_v=$($other -c 'echo -E $ZSH_VERSION' 2>/dev/null)
|
|
|
|
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 ""
|
|
|
|
if [[ $(grep -F $other /etc/shells 2>/dev/null) != $other ]]; then
|
|
|
|
>&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-04-30 10:51:34 +00:00
|
|
|
if (( $+_P9K_SOURCED )); then
|
2019-04-29 09:27:41 +00:00
|
|
|
prompt_powerlevel9k_setup "$@"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-03-13 21:00:15 +00:00
|
|
|
readonly _P9K_SOURCED=1
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
typeset -g _P9K_INSTALLATION_DIR
|
|
|
|
|
2016-05-24 00:31:52 +00:00
|
|
|
# Try to set the installation path
|
2017-07-08 05:07:40 +00:00
|
|
|
if [[ -n "$POWERLEVEL9K_INSTALLATION_DIR" ]]; then
|
2019-03-13 16:04:27 +00:00
|
|
|
_P9K_INSTALLATION_DIR=${POWERLEVEL9K_INSTALLATION_DIR:A}
|
2015-11-07 15:32:48 +00:00
|
|
|
else
|
2017-07-08 05:07:40 +00:00
|
|
|
if [[ "${(%):-%N}" == '(eval)' ]]; then
|
|
|
|
if [[ "$0" == '-antigen-load' ]] && [[ -r "${PWD}/powerlevel9k.zsh-theme" ]]; then
|
|
|
|
# Antigen uses eval to load things so it can change the plugin (!!)
|
|
|
|
# https://github.com/zsh-users/antigen/issues/581
|
2019-03-13 16:04:27 +00:00
|
|
|
_P9K_INSTALLATION_DIR=$PWD
|
2017-07-08 05:07:40 +00:00
|
|
|
else
|
|
|
|
print -P "%F{red}You must set POWERLEVEL9K_INSTALLATION_DIR work from within an (eval).%f"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Get the path to file this code is executing in; then
|
|
|
|
# get the absolute path and strip the filename.
|
|
|
|
# See https://stackoverflow.com/a/28336473/108857
|
2019-03-13 16:04:27 +00:00
|
|
|
_P9K_INSTALLATION_DIR=${${(%):-%x}:A:h}
|
2017-07-08 05:07:40 +00:00
|
|
|
fi
|
2015-11-03 23:40:11 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
source "${_P9K_INSTALLATION_DIR}/functions/utilities.zsh"
|
|
|
|
source "${_P9K_INSTALLATION_DIR}/functions/icons.zsh"
|
|
|
|
source "${_P9K_INSTALLATION_DIR}/functions/colors.zsh"
|
|
|
|
source "${_P9K_INSTALLATION_DIR}/functions/vcs.zsh"
|
2015-10-23 23:05:37 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
typeset -g _P9K_RETVAL
|
|
|
|
typeset -g _P9K_CACHE_KEY
|
|
|
|
typeset -ga _P9K_CACHE_VAL
|
|
|
|
typeset -gA _P9K_CACHE
|
2019-03-18 15:08:37 +00:00
|
|
|
typeset -ga _P9K_T
|
|
|
|
typeset -g _P9K_N
|
|
|
|
typeset -gi _P9K_I
|
|
|
|
typeset -g _P9K_BG
|
|
|
|
typeset -g _P9K_F
|
2014-12-05 18:15:35 +00:00
|
|
|
|
2019-02-24 19:16:04 +00:00
|
|
|
# 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.
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default -i POWERLEVEL9K_MAX_CACHE_SIZE 10000
|
2019-02-28 16:21:01 +00:00
|
|
|
|
2019-03-01 20:45:36 +00:00
|
|
|
# Note: Several performance-critical functions return results to the caller via global
|
2019-03-08 11:24:50 +00:00
|
|
|
# variabls rather than stdout. This is faster.
|
2019-02-28 16:21:01 +00:00
|
|
|
|
2019-03-08 11:24:50 +00:00
|
|
|
# Caching allows storing array-to-array associations. It should be used like this:
|
2019-03-01 20:45:36 +00:00
|
|
|
#
|
2019-03-08 11:24:50 +00:00
|
|
|
# if ! _p9k_cache_get "$key1" "$key2"; then
|
|
|
|
# # Compute val1 and val2 and then store them in the cache.
|
|
|
|
# _p9k_cache_set "$val1" "$val2"
|
|
|
|
# fi
|
|
|
|
# # Here ${_P9K_CACHE_VAL[1]} and ${_P9K_CACHE_VAL[2]} are $val1 and $val2 respectively.
|
2019-04-02 01:14:52 +00:00
|
|
|
#
|
2019-03-08 11:24:50 +00:00
|
|
|
# Limitations:
|
2019-03-01 20:45:36 +00:00
|
|
|
#
|
2019-03-08 11:24:50 +00:00
|
|
|
# * 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.
|
2019-03-01 20:45:36 +00:00
|
|
|
_p9k_cache_set() {
|
|
|
|
# Uncomment to see cache misses.
|
2019-03-08 11:24:50 +00:00
|
|
|
# echo "caching: ${(@0q)_P9K_CACHE_KEY} => (${(q)@})" >&2
|
|
|
|
_P9K_CACHE[$_P9K_CACHE_KEY]="${(pj:\0:)*}"
|
|
|
|
_P9K_CACHE_VAL=("$@")
|
2019-03-12 13:00:52 +00:00
|
|
|
(( #_P9K_CACHE < POWERLEVEL9K_MAX_CACHE_SIZE )) || typeset -gAH _P9K_CACHE=()
|
2019-03-01 20:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_p9k_cache_get() {
|
2019-03-08 11:24:50 +00:00
|
|
|
_P9K_CACHE_KEY="${(pj:\0:)*}"
|
|
|
|
_P9K_CACHE_VAL=("${(@0)${_P9K_CACHE[$_P9K_CACHE_KEY]}}")
|
|
|
|
(( #_P9K_CACHE_VAL ))
|
2019-03-01 20:45:36 +00:00
|
|
|
}
|
|
|
|
|
2019-03-08 11:24:50 +00:00
|
|
|
# Sets _P9K_RETVAL to the icon whose name is supplied via $1.
|
2019-03-01 20:45:36 +00:00
|
|
|
_p9k_get_icon() {
|
|
|
|
local var_name=POWERLEVEL9K_$1
|
2019-03-06 22:04:06 +00:00
|
|
|
_P9K_RETVAL=${(g::)${${(P)var_name}-$icons[$1]}}
|
2019-03-01 20:45:36 +00:00
|
|
|
}
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
typeset -ga _P9K_LEFT_JOIN=(1)
|
|
|
|
typeset -ga _P9K_RIGHT_JOIN=(1)
|
2019-03-01 20:45:36 +00:00
|
|
|
|
2019-05-18 21:50:06 +00:00
|
|
|
_p9k_translate_color() {
|
|
|
|
if [[ $1 == <-> ]]; then # decimal color code: 255
|
|
|
|
_P9K_RETVAL=${(l:3::0:)1}
|
|
|
|
elif [[ $1 == '#'* ]]; then # hexademical color code: #ffffff
|
|
|
|
_P9K_RETVAL=$1
|
|
|
|
else # named color: red
|
|
|
|
# Strip prifixes if there are any.
|
|
|
|
_P9K_RETVAL=$__P9K_COLORS[${${${1#bg-}#fg-}#br}]
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-02-28 12:54:04 +00:00
|
|
|
# Resolves a color to its numerical value, or an empty string. Communicates the result back
|
|
|
|
# by setting _P9K_RETVAL.
|
|
|
|
_p9k_color() {
|
2019-02-28 16:21:01 +00:00
|
|
|
local user_var=POWERLEVEL9K_${(U)${2}#prompt_}_${3}
|
2019-05-18 21:50:06 +00:00
|
|
|
_p9k_translate_color ${${(P)user_var}:-${1}}
|
2019-02-24 19:16:04 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 12:54:04 +00:00
|
|
|
_p9k_background() {
|
|
|
|
[[ -n $1 ]] && _P9K_RETVAL="%K{$1}" || _P9K_RETVAL="%k"
|
|
|
|
}
|
|
|
|
|
|
|
|
_p9k_foreground() {
|
|
|
|
[[ -n $1 ]] && _P9K_RETVAL="%F{$1}" || _P9K_RETVAL="%f"
|
2019-02-24 19:16:04 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 20:04:41 +00:00
|
|
|
_p9k_escape_rcurly() {
|
|
|
|
_P9K_RETVAL=${${1//\\/\\\\}//\}/\\\}}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Begin a left prompt segment.
|
|
|
|
#
|
2019-03-19 16:56:56 +00:00
|
|
|
# * $1: Name of the function that was originally invoked.
|
|
|
|
# Necessary, to make the dynamic color-overwrite mechanism work.
|
|
|
|
# * $2: The array index of the current segment.
|
|
|
|
# * $3: Background color.
|
|
|
|
# * $4: Foreground color.
|
|
|
|
# * $5: An identifying icon (must be a key of the icons array).
|
|
|
|
# * $6: 1 to to perform parameter expansion and process substitution.
|
|
|
|
# * $7: If not empty but becomes empty after parameter expansion and process substitution,
|
|
|
|
# the segment isn't rendered.
|
|
|
|
# * $8+: The segment content
|
2015-10-16 18:42:21 +00:00
|
|
|
set_default POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS " "
|
2014-12-05 01:26:21 +00:00
|
|
|
left_prompt_segment() {
|
2019-03-19 16:56:56 +00:00
|
|
|
if ! _p9k_cache_get "$0" "$1" "$2" "$3" "$4" "$5"; then
|
2019-03-18 21:36:20 +00:00
|
|
|
_p9k_color $3 $1 BACKGROUND
|
2019-03-18 13:11:38 +00:00
|
|
|
local bg_color=$_P9K_RETVAL
|
|
|
|
_p9k_background $bg_color
|
|
|
|
local bg=$_P9K_RETVAL
|
2019-02-28 12:54:04 +00:00
|
|
|
|
2019-03-18 21:36:20 +00:00
|
|
|
_p9k_color $4 $1 FOREGROUND
|
2019-03-18 13:11:38 +00:00
|
|
|
local fg_color=$_P9K_RETVAL
|
|
|
|
_p9k_foreground $fg_color
|
2019-05-19 08:04:46 +00:00
|
|
|
local fg=%b$_P9K_RETVAL
|
2019-03-16 20:04:41 +00:00
|
|
|
|
|
|
|
_p9k_get_icon LEFT_SUBSEGMENT_SEPARATOR
|
|
|
|
local subsep=$_P9K_RETVAL
|
|
|
|
|
|
|
|
_p9k_escape_rcurly $POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS
|
|
|
|
local space=$_P9K_RETVAL
|
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
local icon
|
|
|
|
local -i has_icon
|
|
|
|
if [[ -n $5 ]]; then
|
|
|
|
_p9k_get_icon $5
|
2019-02-28 12:54:04 +00:00
|
|
|
if [[ -n $_P9K_RETVAL ]]; then
|
2019-03-18 13:11:38 +00:00
|
|
|
local glyph=$_P9K_RETVAL
|
2019-03-18 21:36:20 +00:00
|
|
|
_p9k_color $fg_color $1 VISUAL_IDENTIFIER_COLOR
|
2019-03-10 19:09:37 +00:00
|
|
|
_p9k_foreground $_P9K_RETVAL
|
2019-03-18 13:11:38 +00:00
|
|
|
icon=$_P9K_RETVAL$glyph
|
2019-03-19 16:56:56 +00:00
|
|
|
has_icon=1
|
2019-02-24 19:16:04 +00:00
|
|
|
fi
|
2015-12-15 01:43:42 +00:00
|
|
|
fi
|
2019-03-18 13:11:38 +00:00
|
|
|
|
2019-03-16 20:04:41 +00:00
|
|
|
# Segment separator logic:
|
|
|
|
#
|
|
|
|
# if [[ $_P9K_BG == NONE ]]; then
|
2019-03-18 13:11:38 +00:00
|
|
|
# 1
|
2019-03-16 20:04:41 +00:00
|
|
|
# elif (( joined )); then
|
2019-03-18 13:11:38 +00:00
|
|
|
# 2
|
|
|
|
# elif [[ $bg_color == $_P9K_BG ]]; then
|
|
|
|
# 3
|
2019-03-16 20:04:41 +00:00
|
|
|
# else
|
2019-03-18 13:11:38 +00:00
|
|
|
# 4
|
2019-03-16 20:04:41 +00:00
|
|
|
# fi
|
2019-03-18 15:08:37 +00:00
|
|
|
|
|
|
|
local t=$#_P9K_T
|
2019-05-19 08:04:46 +00:00
|
|
|
_P9K_T+=$bg$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS$icon # 1
|
|
|
|
_P9K_T+=$bg$icon # 2
|
2019-03-18 15:08:37 +00:00
|
|
|
if [[ -z $fg_color ]]; then
|
|
|
|
_p9k_foreground $DEFAULT_COLOR
|
2019-05-19 08:04:46 +00:00
|
|
|
_P9K_T+=$bg$_P9K_RETVAL$subsep$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS$icon # 3
|
2019-03-18 15:08:37 +00:00
|
|
|
else
|
2019-05-19 08:04:46 +00:00
|
|
|
_P9K_T+=$bg$fg$subsep$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS$icon # 3
|
2019-03-18 15:08:37 +00:00
|
|
|
fi
|
|
|
|
_p9k_get_icon LEFT_SEGMENT_SEPARATOR
|
2019-05-19 08:04:46 +00:00
|
|
|
_P9K_T+=$bg$_P9K_RETVAL$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS$icon # 4
|
2019-03-18 15:08:37 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
local pre
|
|
|
|
pre+="\${_P9K_N::=}\${_P9K_F::=}"
|
|
|
|
pre+="\${\${\${\${_P9K_BG:-0}:#NONE}:-\${_P9K_N::=$((t+1))}}+}" # 1
|
|
|
|
pre+="\${\${_P9K_N:=\${\${\$((_P9K_I>=$_P9K_LEFT_JOIN[$2])):#0}:+$((t+2))}}+}" # 2
|
|
|
|
pre+="\${\${_P9K_N:=\${\${\$((!\${#\${:-0\$_P9K_BG}:#0$bg_color})):#0}:+$((t+3))}}+}" # 3
|
|
|
|
pre+="\${\${_P9K_N:=\${\${_P9K_F::=%F{\$_P9K_BG\}}+$((t+4))}}+}" # 4
|
2019-05-19 08:04:46 +00:00
|
|
|
pre+="\${_P9K_F}%b\${_P9K_T[\$_P9K_N]}"
|
2019-04-02 01:14:52 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
local post="\${_P9K_C}$space\${\${_P9K_I::=$2}+}\${\${_P9K_BG::=$bg_color}+}}"
|
2019-03-18 15:08:37 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
_p9k_cache_set $has_icon $fg $pre $post
|
2019-03-16 20:04:41 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
local name=$1
|
|
|
|
local -i has_icon=${_P9K_CACHE_VAL[1]}
|
|
|
|
local fg=${_P9K_CACHE_VAL[2]}
|
|
|
|
local -i expand=$6
|
|
|
|
local cond=${7:-1}
|
|
|
|
shift 7
|
|
|
|
|
|
|
|
_p9k_escape_rcurly $fg
|
2019-04-30 09:54:00 +00:00
|
|
|
local content="${(j::):-$_P9K_RETVAL${^@}}"
|
2019-03-19 16:56:56 +00:00
|
|
|
(( expand )) || content="\${(Q)\${:-${(q)content}}}"
|
2015-12-14 23:41:02 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
_P9K_PROMPT+="\${\${:-$cond}:+\${\${_P9K_C::=${content}}+}${_P9K_CACHE_VAL[3]}"
|
|
|
|
(( has_icon )) && _P9K_PROMPT+="\${\${\${#_P9K_C}:#$(($# * $#fg))}:+ }"
|
|
|
|
_P9K_PROMPT+=${_P9K_CACHE_VAL[4]}
|
2014-12-05 01:26:21 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 20:04:41 +00:00
|
|
|
# The same as left_prompt_segment above but for the right prompt.
|
2015-10-16 18:42:21 +00:00
|
|
|
set_default POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS " "
|
2014-12-05 01:26:21 +00:00
|
|
|
right_prompt_segment() {
|
2019-03-19 16:56:56 +00:00
|
|
|
if ! _p9k_cache_get "$0" "$1" "$2" "$3" "$4" "$5"; then
|
2019-03-18 21:36:20 +00:00
|
|
|
_p9k_color $3 $1 BACKGROUND
|
2019-03-18 13:11:38 +00:00
|
|
|
local bg_color=$_P9K_RETVAL
|
|
|
|
_p9k_background $bg_color
|
2019-03-18 15:08:37 +00:00
|
|
|
local bg=$_P9K_RETVAL
|
2018-08-07 20:00:11 +00:00
|
|
|
|
2019-03-18 21:36:20 +00:00
|
|
|
_p9k_color $4 $1 FOREGROUND
|
2019-03-18 13:11:38 +00:00
|
|
|
local fg_color=$_P9K_RETVAL
|
|
|
|
_p9k_foreground $fg_color
|
2019-05-19 08:04:46 +00:00
|
|
|
local fg=%b$_P9K_RETVAL
|
2015-12-16 18:26:27 +00:00
|
|
|
|
2019-03-16 20:04:41 +00:00
|
|
|
_p9k_get_icon RIGHT_SUBSEGMENT_SEPARATOR
|
|
|
|
local subsep=$_P9K_RETVAL
|
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
local icon_fg icon
|
|
|
|
local -i has_icon
|
|
|
|
if [[ -n $5 ]]; then
|
|
|
|
_p9k_get_icon $5
|
2019-02-28 12:54:04 +00:00
|
|
|
if [[ -n $_P9K_RETVAL ]]; then
|
2019-03-18 22:41:48 +00:00
|
|
|
_p9k_escape_rcurly $_P9K_RETVAL
|
2019-03-19 16:56:56 +00:00
|
|
|
icon=$_P9K_RETVAL
|
2019-03-18 21:36:20 +00:00
|
|
|
_p9k_color $fg_color $1 VISUAL_IDENTIFIER_COLOR
|
2019-03-10 19:09:37 +00:00
|
|
|
_p9k_foreground $_P9K_RETVAL
|
2019-03-18 22:41:48 +00:00
|
|
|
_p9k_escape_rcurly $_P9K_RETVAL
|
2019-03-19 16:56:56 +00:00
|
|
|
icon_fg=$_P9K_RETVAL
|
|
|
|
has_icon=1
|
2019-02-24 19:16:04 +00:00
|
|
|
fi
|
2015-12-15 01:43:42 +00:00
|
|
|
fi
|
2019-04-02 01:14:52 +00:00
|
|
|
|
2019-03-18 15:08:37 +00:00
|
|
|
# Segment separator logic is the same as in left_prompt_segment except that here #4 and #1 are
|
|
|
|
# identical.
|
|
|
|
|
|
|
|
local t=$#_P9K_T
|
|
|
|
_p9k_get_icon RIGHT_SEGMENT_SEPARATOR
|
|
|
|
_P9K_T+="%F{$bg_color}$_P9K_RETVAL$bg$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS$fg" # 1
|
|
|
|
_P9K_T+=$bg$fg # 2
|
|
|
|
if [[ -z $fg_color ]]; then
|
|
|
|
_p9k_foreground $DEFAULT_COLOR
|
|
|
|
_P9K_T+=$_P9K_RETVAL$subsep$bg$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS$fg # 3
|
|
|
|
else
|
|
|
|
_P9K_T+=$fg$subsep$bg$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS # 3
|
|
|
|
fi
|
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
local pre
|
|
|
|
pre+="\${_P9K_N::=}"
|
|
|
|
pre+="\${\${\${\${_P9K_BG:-0}:#NONE}:-\${_P9K_N::=$((t+1))}}+}" # 1
|
|
|
|
pre+="\${\${_P9K_N:=\${\${\$((_P9K_I>=$_P9K_RIGHT_JOIN[$2])):#0}:+$((t+2))}}+}" # 2
|
|
|
|
pre+="\${\${_P9K_N:=\${\${\$((!\${#\${:-0\$_P9K_BG}:#0$bg_color})):#0}:+$((t+3))}}+}" # 3
|
|
|
|
pre+="\${\${_P9K_N:=$((t+1))}+}" # 4 == 1
|
2019-05-19 08:04:46 +00:00
|
|
|
pre+="%b\${_P9K_T[\$_P9K_N]}\${_P9K_C}$icon_fg"
|
2019-04-02 01:14:52 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
_p9k_escape_rcurly $POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS
|
|
|
|
local post="$icon$_P9K_RETVAL\${\${_P9K_I::=$2}+}\${\${_P9K_BG::=$bg_color}+}}"
|
2019-03-16 20:04:41 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
_p9k_cache_set $has_icon $fg $pre $post
|
2019-03-16 20:04:41 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
local -i has_icon=${_P9K_CACHE_VAL[1]}
|
|
|
|
local fg=${_P9K_CACHE_VAL[2]}
|
|
|
|
local -i expand=$6
|
|
|
|
local cond=${7:-1}
|
|
|
|
shift 7
|
|
|
|
|
|
|
|
_p9k_escape_rcurly $fg
|
2019-04-30 09:54:00 +00:00
|
|
|
local content="${(j::):-$_P9K_RETVAL${^@}}"
|
2019-03-19 16:56:56 +00:00
|
|
|
(( expand )) || content="\${(Q)\${:-${(q)content}}}"
|
2019-02-24 19:16:04 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
_P9K_PROMPT+="\${\${:-$cond}:+\${\${_P9K_C::=${content}}+}${_P9K_CACHE_VAL[3]}"
|
|
|
|
(( has_icon )) && _P9K_PROMPT+="\${\${\${#_P9K_C}:#$(($# * $#fg))}:+ }"
|
|
|
|
_P9K_PROMPT+=${_P9K_CACHE_VAL[4]}
|
2014-12-05 01:26:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 16:15:16 +00:00
|
|
|
################################################################
|
2015-09-03 19:33:18 +00:00
|
|
|
# Prompt Segment Definitions
|
2015-04-03 16:15:16 +00:00
|
|
|
################################################################
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2016-04-19 19:49:57 +00:00
|
|
|
# Anaconda Environment
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default POWERLEVEL9K_ANACONDA_LEFT_DELIMITER "("
|
|
|
|
set_default POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER ")"
|
2016-04-19 19:49:57 +00:00
|
|
|
prompt_anaconda() {
|
2016-07-26 09:39:00 +00:00
|
|
|
# Depending on the conda version, either might be set. This
|
|
|
|
# variant works even if both are set.
|
2019-03-15 13:11:53 +00:00
|
|
|
local path=$CONDA_ENV_PATH$CONDA_PREFIX
|
|
|
|
if [[ -n $path ]]; then
|
2019-03-19 18:40:18 +00:00
|
|
|
local msg="$POWERLEVEL9K_ANACONDA_LEFT_DELIMITER${${path:t}//\%/%%}$POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER"
|
|
|
|
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" 'PYTHON_ICON' 0 '' "$msg"
|
2016-04-19 19:49:57 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2015-04-03 16:15:16 +00:00
|
|
|
# AWS Profile
|
|
|
|
prompt_aws() {
|
2017-11-07 09:30:23 +00:00
|
|
|
local aws_profile="${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}"
|
2016-01-17 13:55:26 +00:00
|
|
|
if [[ -n "$aws_profile" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" red white 'AWS_ICON' 0 '' "${aws_profile//\%/%%}"
|
2015-04-03 16:15:16 +00:00
|
|
|
fi
|
2014-12-05 01:26:21 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2015-12-09 06:33:01 +00:00
|
|
|
# Current Elastic Beanstalk environment
|
|
|
|
prompt_aws_eb_env() {
|
2019-03-13 16:04:27 +00:00
|
|
|
# TODO(roman): This is clearly broken. Fix it.
|
2016-01-17 11:38:18 +00:00
|
|
|
local eb_env=$(grep environment .elasticbeanstalk/config.yml 2> /dev/null | awk '{print $2}')
|
|
|
|
if [[ -n "$eb_env" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" black green 'AWS_EB_ICON' 0 '' "${eb_env//\%/%%}"
|
2015-12-09 06:33:01 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2016-01-05 21:56:07 +00:00
|
|
|
# Segment to indicate background jobs with an icon.
|
2016-01-18 04:11:05 +00:00
|
|
|
set_default POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE true
|
2017-11-10 15:28:50 +00:00
|
|
|
set_default POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS false
|
2015-12-13 11:41:49 +00:00
|
|
|
prompt_background_jobs() {
|
2019-03-19 18:40:18 +00:00
|
|
|
local msg
|
2019-03-16 20:04:41 +00:00
|
|
|
if [[ $POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE == true ]]; then
|
|
|
|
if [[ $POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS == true ]]; then
|
2019-04-30 09:54:00 +00:00
|
|
|
msg='${(%):-%j}'
|
2019-03-16 20:04:41 +00:00
|
|
|
else
|
2019-04-30 09:54:00 +00:00
|
|
|
msg='${${(%):-%j}:#1}'
|
2019-03-16 20:04:41 +00:00
|
|
|
fi
|
2015-12-13 11:41:49 +00:00
|
|
|
fi
|
2019-04-30 09:54:00 +00:00
|
|
|
$1_prompt_segment $0 $2 "$DEFAULT_COLOR" cyan BACKGROUND_JOBS_ICON 1 '${${(%):-%j}:#0}' "$msg"
|
2015-11-18 22:45:22 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 08:45:52 +00:00
|
|
|
function _p9k_left_prompt_end_line() {
|
|
|
|
_p9k_get_icon LEFT_SEGMENT_SEPARATOR
|
|
|
|
_p9k_escape_rcurly $_P9K_RETVAL
|
2019-05-21 05:54:57 +00:00
|
|
|
_P9K_PROMPT+="%k%b"
|
2019-05-10 08:45:52 +00:00
|
|
|
_P9K_PROMPT+="\${_P9K_N::=}"
|
|
|
|
_P9K_PROMPT+="\${\${\${_P9K_BG:#NONE}:-\${_P9K_N:=1}}+}"
|
|
|
|
_P9K_PROMPT+="\${\${_P9K_N:=2}+}"
|
|
|
|
_P9K_PROMPT+="\${\${_P9K_T[2]::=%F{\$_P9K_BG\}$_P9K_RETVAL}+}"
|
|
|
|
_P9K_PROMPT+="\${_P9K_T[\$_P9K_N]}"
|
|
|
|
_P9K_PROMPT+='%f'
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2017-05-04 06:32:18 +00:00
|
|
|
# A newline in your prompt, so you can segments on multiple lines.
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default POWERLEVEL9K_PROMPT_ON_NEWLINE false
|
2017-05-04 06:32:18 +00:00
|
|
|
prompt_newline() {
|
2017-05-04 06:44:37 +00:00
|
|
|
[[ "$1" == "right" ]] && return
|
2019-05-10 08:45:52 +00:00
|
|
|
_p9k_left_prompt_end_line
|
|
|
|
_P9K_PROMPT+=$'\n'
|
|
|
|
_P9K_PROMPT+='${${_P9K_BG::=NONE}+}'
|
|
|
|
if [[ $POWERLEVEL9K_PROMPT_ON_NEWLINE == true ]]; then
|
2019-03-07 01:14:22 +00:00
|
|
|
_p9k_get_icon MULTILINE_NEWLINE_PROMPT_PREFIX
|
2019-05-10 08:45:52 +00:00
|
|
|
_P9K_PROMPT+=$_P9K_RETVAL
|
2017-05-13 01:07:50 +00:00
|
|
|
fi
|
2017-05-04 06:32:18 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2017-01-21 02:45:11 +00:00
|
|
|
# Segment that indicates usage level of current partition.
|
2017-01-22 02:34:55 +00:00
|
|
|
set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default -i POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90
|
|
|
|
set_default -i POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL 95
|
2017-01-22 02:34:55 +00:00
|
|
|
prompt_disk_usage() {
|
2016-11-21 11:15:24 +00:00
|
|
|
local current_state="unknown"
|
2016-11-21 11:24:31 +00:00
|
|
|
typeset -AH hdd_usage_forecolors
|
|
|
|
hdd_usage_forecolors=(
|
|
|
|
'normal' 'yellow'
|
|
|
|
'warning' "$DEFAULT_COLOR"
|
|
|
|
'critical' 'white'
|
|
|
|
)
|
|
|
|
typeset -AH hdd_usage_backcolors
|
|
|
|
hdd_usage_backcolors=(
|
|
|
|
'normal' $DEFAULT_COLOR
|
2016-11-21 11:15:24 +00:00
|
|
|
'warning' 'yellow'
|
|
|
|
'critical' 'red'
|
|
|
|
)
|
|
|
|
|
2017-01-22 02:34:55 +00:00
|
|
|
local disk_usage="${$(\df -P . | sed -n '2p' | awk '{ print $5 }')%%\%}"
|
2016-11-21 11:15:24 +00:00
|
|
|
|
2017-01-22 02:34:55 +00:00
|
|
|
if [ "$disk_usage" -ge "$POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL" ]; then
|
2016-11-21 11:39:40 +00:00
|
|
|
current_state='warning'
|
2017-01-22 02:34:55 +00:00
|
|
|
if [ "$disk_usage" -ge "$POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL" ]; then
|
2017-01-21 02:45:11 +00:00
|
|
|
current_state='critical'
|
|
|
|
fi
|
2016-11-21 11:39:40 +00:00
|
|
|
else
|
2017-01-22 02:34:55 +00:00
|
|
|
if [[ "$POWERLEVEL9K_DISK_USAGE_ONLY_WARNING" == true ]]; then
|
|
|
|
current_state=''
|
2017-01-21 02:45:11 +00:00
|
|
|
return
|
|
|
|
fi
|
2016-11-21 11:39:40 +00:00
|
|
|
current_state='normal'
|
2016-11-21 11:15:24 +00:00
|
|
|
fi
|
2017-01-21 02:45:11 +00:00
|
|
|
|
2017-01-22 02:34:55 +00:00
|
|
|
local message="${disk_usage}%%"
|
2016-11-21 11:15:24 +00:00
|
|
|
|
|
|
|
# Draw the prompt_segment
|
2017-01-22 02:34:55 +00:00
|
|
|
if [[ -n $disk_usage ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "${0}_${current_state}" "$2" "${hdd_usage_backcolors[$current_state]}" "${hdd_usage_forecolors[$current_state]}" 'DISK_ICON' 0 '' "$message"
|
2016-11-21 11:15:24 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment that displays the battery status in levels and colors
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default -i POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10
|
|
|
|
set_default -i POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD 999
|
|
|
|
set_default -a POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND
|
|
|
|
set_default POWERLEVEL9K_BATTERY_VERBOSE true
|
|
|
|
typeset -g POWERLEVEL9K_BATTERY_STAGES
|
|
|
|
|
2015-10-18 17:55:37 +00:00
|
|
|
prompt_battery() {
|
2016-01-05 21:56:07 +00:00
|
|
|
# The battery can have four different states - default to 'unknown'.
|
2017-01-18 22:50:00 +00:00
|
|
|
local current_state='unknown'
|
2015-11-24 17:36:56 +00:00
|
|
|
typeset -AH battery_states
|
|
|
|
battery_states=(
|
|
|
|
'low' 'red'
|
|
|
|
'charging' 'yellow'
|
|
|
|
'charged' 'green'
|
|
|
|
'disconnected' "$DEFAULT_COLOR_INVERTED"
|
|
|
|
)
|
2018-07-16 18:48:27 +00:00
|
|
|
local ROOT_PREFIX="${4}"
|
2015-10-18 23:30:16 +00:00
|
|
|
|
2018-07-16 18:48:27 +00:00
|
|
|
if [[ $OS =~ OSX && -f "${ROOT_PREFIX}"/usr/bin/pmset && -x "${ROOT_PREFIX}"/usr/bin/pmset ]]; then
|
2016-12-19 22:34:04 +00:00
|
|
|
# obtain battery information from system
|
2018-07-16 18:48:27 +00:00
|
|
|
local raw_data="$(${ROOT_PREFIX}/usr/bin/pmset -g batt | awk 'FNR==2{print}')"
|
2015-10-18 17:55:37 +00:00
|
|
|
# return if there is no battery on system
|
2016-12-19 22:34:04 +00:00
|
|
|
[[ -z $(echo $raw_data | grep "InternalBattery") ]] && return
|
2015-10-18 17:55:37 +00:00
|
|
|
|
2016-12-19 22:34:04 +00:00
|
|
|
# Time remaining on battery operation (charging/discharging)
|
2017-01-18 22:50:00 +00:00
|
|
|
local tstring=$(echo $raw_data | awk -F ';' '{print $3}' | awk '{print $1}')
|
2016-12-19 23:34:08 +00:00
|
|
|
# If time has not been calculated by system yet
|
2017-01-18 22:50:00 +00:00
|
|
|
[[ $tstring =~ '(\(no|not)' ]] && tstring="..."
|
2015-10-18 17:55:37 +00:00
|
|
|
|
2016-12-19 22:34:04 +00:00
|
|
|
# percent of battery charged
|
|
|
|
typeset -i 10 bat_percent
|
|
|
|
bat_percent=$(echo $raw_data | grep -o '[0-9]*%' | sed 's/%//')
|
2015-10-18 23:30:16 +00:00
|
|
|
|
2015-11-24 01:36:37 +00:00
|
|
|
local remain=""
|
2016-01-05 21:56:07 +00:00
|
|
|
# Logic for string output
|
2017-01-18 22:50:00 +00:00
|
|
|
case $(echo $raw_data | awk -F ';' '{print $2}' | awk '{$1=$1};1') in
|
|
|
|
# for a short time after attaching power, status will be 'AC attached;'
|
|
|
|
'charging'|'finishing charge'|'AC attached')
|
2015-11-24 17:36:56 +00:00
|
|
|
current_state="charging"
|
2015-11-24 01:36:37 +00:00
|
|
|
remain=" ($tstring)"
|
2016-12-19 22:34:04 +00:00
|
|
|
;;
|
2017-01-18 22:50:00 +00:00
|
|
|
'discharging')
|
2016-12-19 22:34:04 +00:00
|
|
|
[[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected"
|
|
|
|
remain=" ($tstring)"
|
|
|
|
;;
|
|
|
|
*)
|
2015-11-24 17:36:56 +00:00
|
|
|
current_state="charged"
|
2016-12-19 22:34:04 +00:00
|
|
|
;;
|
|
|
|
esac
|
2015-10-18 23:30:16 +00:00
|
|
|
fi
|
2015-10-18 17:55:37 +00:00
|
|
|
|
2017-04-12 19:38:43 +00:00
|
|
|
if [[ "$OS" == 'Linux' ]] || [[ "$OS" == 'Android' ]]; then
|
2018-07-16 18:48:27 +00:00
|
|
|
local sysp="${ROOT_PREFIX}/sys/class/power_supply"
|
2017-04-12 19:38:43 +00:00
|
|
|
|
2016-01-05 21:56:07 +00:00
|
|
|
# Reported BAT0 or BAT1 depending on kernel version
|
2015-10-18 23:30:16 +00:00
|
|
|
[[ -a $sysp/BAT0 ]] && local bat=$sysp/BAT0
|
|
|
|
[[ -a $sysp/BAT1 ]] && local bat=$sysp/BAT1
|
|
|
|
|
2017-04-12 19:38:43 +00:00
|
|
|
# Android-related
|
|
|
|
# Tested on: Moto G falcon (CM 13.0)
|
|
|
|
[[ -a $sysp/battery ]] && local bat=$sysp/battery
|
|
|
|
|
2016-01-05 21:56:07 +00:00
|
|
|
# Return if no battery found
|
2015-10-18 23:30:16 +00:00
|
|
|
[[ -z $bat ]] && return
|
2016-12-03 17:46:25 +00:00
|
|
|
local capacity=$(cat $bat/capacity)
|
|
|
|
local battery_status=$(cat $bat/status)
|
|
|
|
[[ $capacity -gt 100 ]] && local bat_percent=100 || local bat_percent=$capacity
|
|
|
|
[[ $battery_status =~ Charging || $battery_status =~ Full ]] && local connected=true
|
2015-11-18 20:34:07 +00:00
|
|
|
if [[ -z $connected ]]; then
|
2015-11-24 17:36:56 +00:00
|
|
|
[[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected"
|
2016-12-03 18:02:52 +00:00
|
|
|
else
|
|
|
|
[[ $bat_percent =~ 100 ]] && current_state="charged"
|
|
|
|
[[ $bat_percent -lt 100 ]] && current_state="charging"
|
2015-10-18 23:30:16 +00:00
|
|
|
fi
|
2018-07-16 18:48:27 +00:00
|
|
|
if [[ -f ${ROOT_PREFIX}/usr/bin/acpi ]]; then
|
|
|
|
local time_remaining=$(${ROOT_PREFIX}/usr/bin/acpi | awk '{ print $5 }')
|
2015-10-19 04:03:47 +00:00
|
|
|
if [[ $time_remaining =~ rate ]]; then
|
|
|
|
local tstring="..."
|
2016-11-21 16:51:27 +00:00
|
|
|
elif [[ $time_remaining =~ "[[:digit:]]+" ]]; then
|
2016-12-08 19:06:07 +00:00
|
|
|
local tstring=${(f)$(date -u -d "$(echo $time_remaining)" +%k:%M 2> /dev/null)}
|
2015-10-19 04:03:47 +00:00
|
|
|
fi
|
2015-10-19 02:48:45 +00:00
|
|
|
fi
|
2015-11-22 23:48:59 +00:00
|
|
|
[[ -n $tstring ]] && local remain=" ($tstring)"
|
2015-10-18 17:55:37 +00:00
|
|
|
fi
|
2015-10-18 23:30:16 +00:00
|
|
|
|
2015-12-14 23:55:55 +00:00
|
|
|
local message
|
2015-11-24 23:21:20 +00:00
|
|
|
if [[ "$POWERLEVEL9K_BATTERY_VERBOSE" == true ]]; then
|
2015-12-14 23:55:55 +00:00
|
|
|
message="$bat_percent%%$remain"
|
2016-06-17 05:33:09 +00:00
|
|
|
else
|
|
|
|
message="$bat_percent%%"
|
2015-10-18 17:55:37 +00:00
|
|
|
fi
|
2015-10-18 23:30:16 +00:00
|
|
|
|
2017-05-02 01:28:22 +00:00
|
|
|
# override default icon if we are using battery stages
|
|
|
|
if [[ -n "$POWERLEVEL9K_BATTERY_STAGES" ]]; then
|
|
|
|
local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_STAGES} - 1 ) ))
|
|
|
|
if [[ $segment > 1 ]]; then
|
|
|
|
local offset=$(( ($bat_percent / $segment) + 1 ))
|
|
|
|
# check if the stages are in an array or a string
|
|
|
|
[[ "${(t)POWERLEVEL9K_BATTERY_STAGES}" =~ "array" ]] && POWERLEVEL9K_BATTERY_ICON="$POWERLEVEL9K_BATTERY_STAGES[$offset]" || POWERLEVEL9K_BATTERY_ICON=${POWERLEVEL9K_BATTERY_STAGES:$offset:1}
|
|
|
|
fi
|
|
|
|
fi
|
2018-05-11 23:22:48 +00:00
|
|
|
# return if POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD is set and the battery percentage is greater or equal
|
2019-03-13 16:04:27 +00:00
|
|
|
if (( bat_percent >= POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD )); then
|
2018-05-09 08:18:06 +00:00
|
|
|
return
|
2016-01-17 13:55:26 +00:00
|
|
|
fi
|
2018-05-09 08:18:06 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
# override the default color if we are using a color level array
|
|
|
|
if (( #POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND )); then
|
|
|
|
local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) ))
|
|
|
|
local offset=$(( ($bat_percent / $segment) + 1 ))
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "BATTERY_ICON" 0 '' "${message}"
|
2019-03-13 16:04:27 +00:00
|
|
|
else
|
|
|
|
# Draw the prompt_segment
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "BATTERY_ICON" 0 '' "${message}"
|
2019-03-13 16:04:27 +00:00
|
|
|
fi
|
2015-10-18 17:55:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2017-01-21 13:30:19 +00:00
|
|
|
# Public IP segment
|
|
|
|
# Parameters:
|
|
|
|
# * $1 Alignment: string - left|right
|
|
|
|
# * $2 Index: integer
|
|
|
|
# * $3 Joined: bool - If the segment should be joined
|
2019-01-21 18:46:53 +00:00
|
|
|
# * $4 Root Prefix: string - Root prefix for testing purposes
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default -i POWERLEVEL9K_PUBLIC_IP_TIMEOUT 300
|
|
|
|
set_default -a POWERLEVEL9K_PUBLIC_IP_METHODS dig curl wget
|
|
|
|
set_default POWERLEVEL9K_PUBLIC_IP_NONE ""
|
|
|
|
set_default POWERLEVEL9K_PUBLIC_IP_FILE "/tmp/p9k_public_ip"
|
|
|
|
set_default POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me"
|
|
|
|
set_default POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ""
|
|
|
|
|
2016-12-30 21:04:18 +00:00
|
|
|
prompt_public_ip() {
|
2019-01-21 18:46:53 +00:00
|
|
|
local ROOT_PREFIX="${4}"
|
2016-12-30 21:04:18 +00:00
|
|
|
|
|
|
|
# Do we need a fresh IP?
|
2017-01-02 06:47:01 +00:00
|
|
|
local refresh_ip=false
|
2016-12-30 21:04:18 +00:00
|
|
|
if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
|
|
|
|
typeset -i timediff
|
2017-01-03 23:55:33 +00:00
|
|
|
# if saved IP is more than
|
2017-10-12 06:02:45 +00:00
|
|
|
if [[ "$OS" == "OSX" ]]; then
|
|
|
|
timediff=$(($(date +%s) - $(stat -f "%m" $POWERLEVEL9K_PUBLIC_IP_FILE)))
|
|
|
|
else
|
|
|
|
timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s)))
|
|
|
|
fi
|
2019-03-13 16:04:27 +00:00
|
|
|
(( timediff > POWERLEVEL9K_PUBLIC_IP_TIMEOUT )) && refresh_ip=true
|
2017-01-03 23:55:33 +00:00
|
|
|
# If tmp file is empty get a fresh IP
|
2017-01-09 22:25:02 +00:00
|
|
|
[[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=true
|
|
|
|
[[ -n $POWERLEVEL9K_PUBLIC_IP_NONE ]] && [[ $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) =~ "$POWERLEVEL9K_PUBLIC_IP_NONE" ]] && refresh_ip=true
|
2016-12-30 21:04:18 +00:00
|
|
|
else
|
2017-01-02 06:47:01 +00:00
|
|
|
touch $POWERLEVEL9K_PUBLIC_IP_FILE && refresh_ip=true
|
2016-12-30 21:04:18 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# grab a fresh IP if needed
|
2017-01-28 00:29:38 +00:00
|
|
|
local fresh_ip
|
2019-01-21 18:46:53 +00:00
|
|
|
if [[ $refresh_ip == true && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
|
2017-01-28 00:29:38 +00:00
|
|
|
for method in "${POWERLEVEL9K_PUBLIC_IP_METHODS[@]}"; do
|
2017-01-09 21:41:46 +00:00
|
|
|
case $method in
|
|
|
|
'dig')
|
2017-01-28 00:29:38 +00:00
|
|
|
fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)"
|
|
|
|
[[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip
|
2017-01-09 21:41:46 +00:00
|
|
|
;;
|
|
|
|
'curl')
|
2017-01-28 00:29:38 +00:00
|
|
|
fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
|
2017-01-09 21:41:46 +00:00
|
|
|
;;
|
|
|
|
'wget')
|
2017-01-28 00:29:38 +00:00
|
|
|
fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
|
2017-01-09 21:41:46 +00:00
|
|
|
;;
|
|
|
|
esac
|
2017-01-28 00:29:38 +00:00
|
|
|
# If we found a fresh IP, break loop.
|
|
|
|
if [[ -n "${fresh_ip}" ]]; then
|
|
|
|
break;
|
2017-01-09 21:41:46 +00:00
|
|
|
fi
|
2017-01-28 00:29:38 +00:00
|
|
|
done
|
2017-01-03 23:07:54 +00:00
|
|
|
|
2017-01-03 23:55:33 +00:00
|
|
|
# write IP to tmp file or clear tmp file if an IP was not retrieved
|
2017-01-21 13:30:19 +00:00
|
|
|
# Redirection with `>!`. From the manpage: Same as >, except that the file
|
|
|
|
# is truncated to zero length if it exists, even if CLOBBER is unset.
|
|
|
|
# If the file already exists, and a simple `>` redirection and CLOBBER
|
|
|
|
# unset, ZSH will produce an error.
|
|
|
|
[[ -n "${fresh_ip}" ]] && echo $fresh_ip >! $POWERLEVEL9K_PUBLIC_IP_FILE || echo $POWERLEVEL9K_PUBLIC_IP_NONE >! $POWERLEVEL9K_PUBLIC_IP_FILE
|
2016-12-30 21:04:18 +00:00
|
|
|
fi
|
|
|
|
|
2017-01-03 23:05:15 +00:00
|
|
|
# read public IP saved to tmp file
|
2017-01-28 00:29:38 +00:00
|
|
|
local public_ip="$(cat $POWERLEVEL9K_PUBLIC_IP_FILE)"
|
2016-12-30 21:04:18 +00:00
|
|
|
|
2017-01-21 13:30:19 +00:00
|
|
|
# Draw the prompt segment
|
2016-12-30 21:04:18 +00:00
|
|
|
if [[ -n $public_ip ]]; then
|
2017-11-14 21:23:19 +00:00
|
|
|
icon='PUBLIC_IP_ICON'
|
|
|
|
# Check VPN is on if VPN interface is set
|
|
|
|
if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then
|
2019-02-03 18:20:14 +00:00
|
|
|
local vpnIp="$(p9k::parseIp "${POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE}" "${ROOT_PREFIX}")"
|
|
|
|
if [[ -n "$vpnIp" ]]; then
|
2017-11-14 21:23:19 +00:00
|
|
|
icon='VPN_ICON'
|
2018-12-30 10:26:04 +00:00
|
|
|
fi
|
2017-11-14 21:23:19 +00:00
|
|
|
fi
|
2019-03-19 16:56:56 +00:00
|
|
|
$1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "$icon" 0 '' "${public_ip}"
|
2016-12-30 21:04:18 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2015-04-03 16:15:16 +00:00
|
|
|
# Context: user@hostname (who am I and where am I)
|
|
|
|
# Note that if $DEFAULT_USER is not set, this prompt segment will always print
|
2017-02-14 02:50:37 +00:00
|
|
|
set_default POWERLEVEL9K_ALWAYS_SHOW_CONTEXT false
|
2017-02-14 03:29:58 +00:00
|
|
|
set_default POWERLEVEL9K_ALWAYS_SHOW_USER false
|
2017-01-26 12:01:17 +00:00
|
|
|
set_default POWERLEVEL9K_CONTEXT_TEMPLATE "%n@%m"
|
2015-04-03 16:15:16 +00:00
|
|
|
prompt_context() {
|
2019-03-15 13:11:53 +00:00
|
|
|
local content
|
2019-03-18 21:39:15 +00:00
|
|
|
if [[ $POWERLEVEL9K_ALWAYS_SHOW_CONTEXT == true || -z $DEFAULT_USER || -n $SSH_CLIENT || -n $SSH_TTY ]]; then
|
2019-03-15 13:11:53 +00:00
|
|
|
content=$POWERLEVEL9K_CONTEXT_TEMPLATE
|
2017-02-14 03:29:58 +00:00
|
|
|
else
|
2019-03-15 13:11:53 +00:00
|
|
|
local user=$(whoami)
|
2019-03-18 21:39:15 +00:00
|
|
|
if [[ $user != $DEFAULT_USER ]]; then
|
2019-03-15 13:11:53 +00:00
|
|
|
content="${POWERLEVEL9K_CONTEXT_TEMPLATE}"
|
|
|
|
elif [[ $POWERLEVEL9K_ALWAYS_SHOW_USER == true ]]; then
|
|
|
|
content="${user//\%/%%}"
|
|
|
|
else
|
2017-02-14 03:29:58 +00:00
|
|
|
return
|
2019-03-15 13:11:53 +00:00
|
|
|
fi
|
2014-12-05 01:26:21 +00:00
|
|
|
fi
|
2017-02-14 03:29:58 +00:00
|
|
|
|
2019-03-15 13:11:53 +00:00
|
|
|
local current_state="DEFAULT"
|
2019-03-13 16:04:27 +00:00
|
|
|
if [[ "${(%):-%#}" == '#' ]]; then
|
2017-12-23 13:54:25 +00:00
|
|
|
current_state="ROOT"
|
|
|
|
elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
|
2018-07-31 20:22:26 +00:00
|
|
|
if [[ -n "$SUDO_COMMAND" ]]; then
|
2018-02-12 09:28:00 +00:00
|
|
|
current_state="REMOTE_SUDO"
|
|
|
|
else
|
|
|
|
current_state="REMOTE"
|
|
|
|
fi
|
2018-07-31 20:22:26 +00:00
|
|
|
elif [[ -n "$SUDO_COMMAND" ]]; then
|
2018-02-10 19:01:09 +00:00
|
|
|
current_state="SUDO"
|
2017-12-23 13:54:25 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" yellow '' 0 '' "${content}"
|
2014-12-05 01:26:21 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 20:06:28 +00:00
|
|
|
################################################################
|
|
|
|
# User: user (who am I)
|
|
|
|
# Note that if $DEFAULT_USER is not set, this prompt segment will always print
|
|
|
|
set_default POWERLEVEL9K_USER_TEMPLATE "%n"
|
|
|
|
prompt_user() {
|
2019-03-15 13:11:53 +00:00
|
|
|
local user=$(whoami)
|
|
|
|
[[ $POWERLEVEL9K_ALWAYS_SHOW_USER != true && $user == $DEFAULT_USER ]] && return
|
2019-03-13 16:04:27 +00:00
|
|
|
if [[ "${(%):-%#}" == '#' ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "${0}_ROOT" "$2" "${DEFAULT_COLOR}" yellow ROOT_ICON 0 '' "${POWERLEVEL9K_USER_TEMPLATE}"
|
2019-03-13 16:04:27 +00:00
|
|
|
elif [[ -n "$SUDO_COMMAND" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "${0}_SUDO" "$2" "${DEFAULT_COLOR}" yellow SUDO_ICON 0 '' "${POWERLEVEL9K_USER_TEMPLATE}"
|
2019-03-13 16:04:27 +00:00
|
|
|
else
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "${0}_DEFAULT" "$2" "${DEFAULT_COLOR}" yellow USER_ICON 0 '' "${user//\%/%%}"
|
2017-04-20 20:06:28 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################
|
|
|
|
# Host: machine (where am I)
|
|
|
|
set_default POWERLEVEL9K_HOST_TEMPLATE "%m"
|
|
|
|
prompt_host() {
|
2019-03-13 16:04:27 +00:00
|
|
|
if [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0_REMOTE" "$2" "${DEFAULT_COLOR}" yellow SSH_ICON 0 '' "${POWERLEVEL9K_HOST_TEMPLATE}"
|
2017-04-20 20:06:28 +00:00
|
|
|
else
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0_LOCAL" "$2" "${DEFAULT_COLOR}" yellow HOST_ICON 0 '' "${POWERLEVEL9K_HOST_TEMPLATE}"
|
2017-04-20 20:06:28 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2016-01-08 19:34:45 +00:00
|
|
|
# The 'custom` prompt provides a way for users to invoke commands and display
|
|
|
|
# the output in a segment.
|
|
|
|
prompt_custom() {
|
2018-07-18 20:13:25 +00:00
|
|
|
local segment_name="${3:u}"
|
|
|
|
# Get content of custom segment
|
|
|
|
local command="POWERLEVEL9K_CUSTOM_${segment_name}"
|
2016-05-24 13:53:48 +00:00
|
|
|
local segment_content="$(eval ${(P)command})"
|
2019-03-12 07:29:33 +00:00
|
|
|
# Note: this would be a better implementation. I'm keeping the old one in case anyone
|
|
|
|
# relies on its quirks.
|
|
|
|
# local segment_content=$("${(@Q)${(z)${(P)command}}}")
|
2016-01-08 19:34:45 +00:00
|
|
|
|
2016-05-24 13:53:48 +00:00
|
|
|
if [[ -n $segment_content ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "CUSTOM_${segment_name}_ICON" 0 '' "$segment_content"
|
2016-05-24 13:53:48 +00:00
|
|
|
fi
|
2016-01-08 19:34:45 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2017-02-12 23:56:32 +00:00
|
|
|
# Display the duration the command needed to run.
|
2019-03-13 16:04:27 +00:00
|
|
|
typeset -gF _P9K_COMMAND_DURATION
|
|
|
|
set_default -i POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD 3
|
|
|
|
set_default -i POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION 2
|
2017-02-12 23:56:32 +00:00
|
|
|
prompt_command_execution_time() {
|
2019-03-13 16:04:27 +00:00
|
|
|
(( _P9K_COMMAND_DURATION < POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )) && return
|
2017-02-14 20:32:41 +00:00
|
|
|
# Print time in human readable format
|
|
|
|
# For that use `strftime` and convert
|
|
|
|
# the duration (float) to an seconds
|
|
|
|
# (integer).
|
|
|
|
# See http://unix.stackexchange.com/a/89748
|
|
|
|
local humanReadableDuration
|
|
|
|
if (( _P9K_COMMAND_DURATION > 3600 )); then
|
2017-02-14 20:38:39 +00:00
|
|
|
humanReadableDuration=$(TZ=GMT; strftime '%H:%M:%S' $(( int(rint(_P9K_COMMAND_DURATION)) )))
|
2017-02-14 20:32:41 +00:00
|
|
|
elif (( _P9K_COMMAND_DURATION > 60 )); then
|
2017-02-14 20:38:39 +00:00
|
|
|
humanReadableDuration=$(TZ=GMT; strftime '%M:%S' $(( int(rint(_P9K_COMMAND_DURATION)) )))
|
2017-02-14 20:32:41 +00:00
|
|
|
else
|
|
|
|
# If the command executed in seconds, print as float.
|
|
|
|
# Convert to float
|
|
|
|
if [[ "${POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION}" == "0" ]]; then
|
|
|
|
# If user does not want microseconds, then we need to convert
|
|
|
|
# the duration to an integer.
|
|
|
|
typeset -i humanReadableDuration
|
|
|
|
else
|
|
|
|
typeset -F ${POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION} humanReadableDuration
|
|
|
|
fi
|
|
|
|
humanReadableDuration=$_P9K_COMMAND_DURATION
|
|
|
|
fi
|
2017-02-12 23:56:32 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "red" "yellow1" 'EXECUTION_TIME_ICON' 0 '' "${humanReadableDuration}"
|
2017-02-12 23:56:32 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 21:58:19 +00:00
|
|
|
set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/"
|
2017-03-31 06:13:11 +00:00
|
|
|
set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~"
|
2018-02-19 18:00:15 +00:00
|
|
|
set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default POWERLEVEL9K_DIR_PATH_ABSOLUTE false
|
|
|
|
set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false
|
|
|
|
set_default POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER false
|
|
|
|
set_default POWERLEVEL9K_SHORTEN_STRATEGY ""
|
|
|
|
set_default POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND ""
|
|
|
|
set_default -i POWERLEVEL9K_SHORTEN_DIR_LENGTH -1
|
2019-05-19 07:11:39 +00:00
|
|
|
# Individual elements are patterns. They are expanded with the options set by `emulate zsh`.
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default -a POWERLEVEL9K_DIR_PACKAGE_FILES package.json composer.json
|
2019-05-19 07:11:39 +00:00
|
|
|
|
|
|
|
################################################################
|
|
|
|
# Dir: current working directory
|
2015-04-03 16:15:16 +00:00
|
|
|
prompt_dir() {
|
2019-05-18 21:50:06 +00:00
|
|
|
[[ $POWERLEVEL9K_DIR_PATH_ABSOLUTE == true ]] && local p=$PWD || local p=${(%):-%~}
|
|
|
|
|
|
|
|
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,
|
|
|
|
# for "~[a/b]" it'll give the nonsensical "~a[". To solve this problem we have to
|
|
|
|
# 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
|
|
|
|
if (( $+functions[$func] )) && $func d $PWD && [[ $p == '~['$reply[1]']'* ]]; then
|
|
|
|
parts+='~['$reply[1]']'
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if (( $#parts )); then
|
|
|
|
parts+=(${(s:/:)${p#$parts[1]}})
|
|
|
|
else
|
|
|
|
p=$PWD
|
|
|
|
parts=("${(s:/:)p}")
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
local -a parts=("${(s:/:)p}")
|
|
|
|
fi
|
|
|
|
|
|
|
|
local -i fake_first=0
|
2019-05-19 10:46:28 +00:00
|
|
|
local delim=${POWERLEVEL9K_SHORTEN_DELIMITER-$'\u2026'}
|
2019-05-18 21:50:06 +00:00
|
|
|
|
|
|
|
case $POWERLEVEL9K_SHORTEN_STRATEGY in
|
|
|
|
truncate_absolute|truncate_absolute_chars)
|
2019-05-19 05:50:43 +00:00
|
|
|
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 && $#p > POWERLEVEL9K_SHORTEN_DIR_LENGTH + 1 )); then
|
2019-05-18 21:50:06 +00:00
|
|
|
local -i n=POWERLEVEL9K_SHORTEN_DIR_LENGTH
|
|
|
|
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
|
|
|
|
parts[i]=$'\0'$dir[-n,-1]
|
|
|
|
parts[1,i-1]=()
|
|
|
|
break
|
2019-02-24 19:16:04 +00:00
|
|
|
fi
|
2019-05-18 21:50:06 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
truncate_with_package_name|truncate_middle|truncate_from_right)
|
|
|
|
() {
|
2019-05-19 07:11:39 +00: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-05-18 21:50:06 +00:00
|
|
|
local -i i=$#parts
|
2019-05-19 07:11:39 +00:00
|
|
|
local dir=$PWD
|
2019-05-18 21:50:06 +00:00
|
|
|
for (( ; i > 0; --i )); do
|
2019-05-19 07:11:39 +00:00
|
|
|
local pkg_file=''
|
|
|
|
for pkg_file in $dir/${~pat}(N); do
|
|
|
|
local pkg_name=''
|
|
|
|
pkg_name=$(command jq -j '.name' <$pkg_file) && [[ -n $pkg_name ]] || return
|
|
|
|
parts[1,i]=($pkg_name)
|
|
|
|
fake_first=1
|
|
|
|
return
|
2019-02-24 19:16:04 +00:00
|
|
|
done
|
2019-05-19 07:11:39 +00:00
|
|
|
dir=${dir:h}
|
2019-05-18 21:50:06 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )); then
|
|
|
|
local -i pref=$POWERLEVEL9K_SHORTEN_DIR_LENGTH suf=0 i=2
|
|
|
|
[[ $POWERLEVEL9K_SHORTEN_STRATEGY == truncate_middle ]] && suf=pref
|
|
|
|
for (( ; i < $#parts; ++i )); do
|
|
|
|
local dir=$parts[i]
|
2019-05-19 05:50:43 +00:00
|
|
|
if (( $#dir > pref + suf + 1 )); then
|
2019-05-18 21:50:06 +00:00
|
|
|
dir[pref+1,-suf-1]=$'\0'
|
|
|
|
parts[i]=$dir
|
2019-02-24 19:16:04 +00:00
|
|
|
fi
|
2019-05-18 21:50:06 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
truncate_to_last)
|
|
|
|
fake_first=$(($#parts > 1))
|
|
|
|
parts[1,-2]=()
|
|
|
|
;;
|
|
|
|
truncate_to_first_and_last)
|
|
|
|
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )); then
|
|
|
|
local -i i=$(( POWERLEVEL9K_SHORTEN_DIR_LENGTH + 1 ))
|
|
|
|
[[ $p == /* ]] && (( ++i ))
|
|
|
|
for (( ; i <= $#parts - POWERLEVEL9K_SHORTEN_DIR_LENGTH; ++i )); do
|
|
|
|
parts[i]=$'\0'
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
truncate_to_unique)
|
2019-05-19 13:53:09 +00:00
|
|
|
local -i i=2 n=1
|
|
|
|
[[ $p == /* ]] && (( ++i ))
|
|
|
|
(( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )) && n=POWERLEVEL9K_SHORTEN_DIR_LENGTH
|
|
|
|
local pat=${POWERLEVEL9K_SHORTEN_FOLDER_MARKER-'(.bzr|CVS|.git|.hg|.svn|.citc)'}
|
|
|
|
local parent="${PWD%/${(pj./.)parts[i,-1]}}"
|
|
|
|
for (( ; i <= $#parts - n; ++i )); do
|
2019-05-18 21:50:06 +00:00
|
|
|
local dir=$parts[i]
|
2019-05-19 13:53:09 +00:00
|
|
|
if [[ -n $pat ]]; then
|
|
|
|
local -a matches=($parent/$dir/${~pat}(N))
|
|
|
|
if (( $#matches )); then
|
|
|
|
parent+=/$dir
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
2019-05-18 21:50:06 +00:00
|
|
|
local -i j=1
|
2019-05-19 10:46:28 +00:00
|
|
|
for (( ; j < $#dir; ++j )); do
|
2019-05-19 07:11:39 +00:00
|
|
|
local -a matching=($parent/$dir[1,j]*/(N))
|
2019-05-18 21:50:06 +00:00
|
|
|
(( $#matching == 1 )) && break
|
|
|
|
done
|
2019-05-19 10:46:28 +00:00
|
|
|
(( j == $#dir )) || parts[i]=$dir[1,j]$'\0'
|
2019-05-19 13:53:09 +00:00
|
|
|
parent+=/$dir
|
2019-05-18 21:50:06 +00:00
|
|
|
done
|
2019-05-19 10:46:28 +00:00
|
|
|
delim=${POWERLEVEL9K_SHORTEN_DELIMITER-'*'}
|
2019-05-18 21:50:06 +00:00
|
|
|
;;
|
|
|
|
truncate_with_folder_marker)
|
2019-05-19 13:53:09 +00:00
|
|
|
local pat=${POWERLEVEL9K_SHORTEN_FOLDER_MARKER-.shorten_folder_marker}
|
|
|
|
if [[ -n $pat ]]; then
|
|
|
|
local dir=$PWD
|
|
|
|
local -a m=()
|
|
|
|
local -i i=$(($#parts - 1))
|
|
|
|
for (( ; i > 1; --i )); do
|
|
|
|
dir=${dir:h}
|
|
|
|
local -a matches=($dir/${~pat}(N))
|
|
|
|
(( $#matches )) && m+=$i
|
|
|
|
done
|
|
|
|
m+=1
|
|
|
|
for (( i=1; i < $#m; ++i )); do
|
|
|
|
(( m[i] - m[i+1] > 2 )) && parts[m[i+1]+1,m[i]-1]=($'\0')
|
|
|
|
done
|
|
|
|
fi
|
2019-05-18 21:50:06 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if (( POWERLEVEL9K_SHORTEN_DIR_LENGTH > 0 )); then
|
|
|
|
local -i len=$#parts
|
|
|
|
[[ -z $parts[1] ]] && (( --len ))
|
|
|
|
if (( len > POWERLEVEL9K_SHORTEN_DIR_LENGTH )); then
|
|
|
|
parts[1,-POWERLEVEL9K_SHORTEN_DIR_LENGTH-1]=($'\0')
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2015-06-06 23:06:26 +00:00
|
|
|
|
2019-05-18 21:50:06 +00:00
|
|
|
local state='' icon=''
|
|
|
|
if [[ $POWERLEVEL9K_DIR_SHOW_WRITABLE == true && ! -w $PWD ]]; then
|
|
|
|
state=NOT_WRITABLE
|
|
|
|
icon=LOCK_ICON
|
|
|
|
else
|
|
|
|
case $PWD in
|
|
|
|
/etc|/etc/*) state=ETC; icon=ETC_ICON;;
|
|
|
|
~) state=HOME; icon=HOME_ICON;;
|
|
|
|
~/*) state=HOME_SUBFOLDER; icon=HOME_SUB_ICON;;
|
|
|
|
*) state=DEFAULT; icon=FOLDER_ICON;;
|
|
|
|
esac
|
|
|
|
fi
|
2019-03-15 13:11:53 +00:00
|
|
|
|
2019-05-18 21:50:06 +00:00
|
|
|
_p9k_color "$DEFAULT_COLOR" "$0_$state" FOREGROUND
|
|
|
|
_p9k_foreground $_P9K_RETVAL
|
2019-05-19 08:04:46 +00:00
|
|
|
local fg=%b$_P9K_RETVAL
|
2019-03-15 13:11:53 +00:00
|
|
|
|
2019-05-19 08:04:46 +00:00
|
|
|
parts=("${(@)parts//\%/%%}")
|
|
|
|
[[ $fake_first == 0 && $parts[1] == '~' ]] && parts[1]=$POWERLEVEL9K_HOME_FOLDER_ABBREVIATION$fg
|
2019-05-18 21:50:06 +00:00
|
|
|
[[ $POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER == true && $#parts > 1 && -n $parts[2] ]] && parts[1]=()
|
2019-02-24 19:16:04 +00:00
|
|
|
|
2019-05-19 08:04:46 +00:00
|
|
|
local last_fg=
|
|
|
|
[[ $POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD == true ]] && last_fg+=%B
|
2019-05-18 21:50:06 +00:00
|
|
|
if [[ -n $POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND ]]; then
|
|
|
|
_p9k_translate_color $POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
|
|
|
|
_p9k_foreground $_P9K_RETVAL
|
2019-05-19 08:04:46 +00:00
|
|
|
last_fg+=$_P9K_RETVAL
|
2019-05-18 21:50:06 +00:00
|
|
|
fi
|
2019-05-19 08:04:46 +00:00
|
|
|
parts[-1]=$last_fg${parts[-1]//$'\0'/$'\0'$last_fg}
|
2019-05-19 10:46:28 +00:00
|
|
|
parts=("${(@)parts//$'\0'/$delim$fg}")
|
2018-02-10 10:46:56 +00:00
|
|
|
|
2019-05-19 08:04:46 +00:00
|
|
|
local sep=$POWERLEVEL9K_DIR_PATH_SEPARATOR$fg
|
2019-05-18 21:50:06 +00:00
|
|
|
if [[ -n $POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND ]]; then
|
|
|
|
_p9k_translate_color $POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
|
|
|
|
_p9k_foreground $_P9K_RETVAL
|
|
|
|
sep=$_P9K_RETVAL$sep
|
2018-02-10 10:46:56 +00:00
|
|
|
fi
|
|
|
|
|
2019-05-18 21:50:06 +00:00
|
|
|
"$1_prompt_segment" "$0_$state" "$2" blue "$DEFAULT_COLOR" "$icon" 0 "" "${(pj.$sep.)parts}"
|
2015-04-03 16:15:16 +00:00
|
|
|
}
|
2014-12-05 01:26:21 +00:00
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2016-03-06 17:25:17 +00:00
|
|
|
# Docker machine
|
|
|
|
prompt_docker_machine() {
|
2019-03-13 16:04:27 +00:00
|
|
|
if [[ -n "$DOCKER_MACHINE_NAME" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "magenta" "$DEFAULT_COLOR" 'SERVER_ICON' 0 '' "${DOCKER_MACHINE_NAME//\%/%%}"
|
2016-03-06 17:25:17 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2016-01-05 21:56:07 +00:00
|
|
|
# GO prompt
|
2015-09-21 16:27:03 +00:00
|
|
|
prompt_go_version() {
|
2019-05-21 11:21:22 +00:00
|
|
|
_p9k_cached_cmd_stdout go version || return
|
|
|
|
emulate -L zsh && setopt extendedglob
|
|
|
|
local -a match
|
|
|
|
[[ $_P9K_RETVAL == (#b)*(go[0-9.]##)* ]] || return
|
|
|
|
local v=$match[1]
|
|
|
|
local p=${GOPATH:-$(go env GOPATH 2>/dev/null)}
|
|
|
|
[[ -n $p && $PWD/ == $p/* ]] || return
|
|
|
|
"$1_prompt_segment" "$0" "$2" "green" "grey93" "GO_ICON" 0 '' "${v//\%/%%}"
|
2015-09-21 16:27:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2015-04-03 16:15:16 +00:00
|
|
|
# Command number (in local history)
|
|
|
|
prompt_history() {
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" '' 0 '' '%h'
|
2014-12-05 01:26:21 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2016-12-11 04:16:02 +00:00
|
|
|
# Detection for virtualization (systemd based systems only)
|
|
|
|
prompt_detect_virt() {
|
2018-07-18 20:15:35 +00:00
|
|
|
local virt=$(systemd-detect-virt 2> /dev/null)
|
2016-12-11 04:16:02 +00:00
|
|
|
if [[ "$virt" == "none" ]]; then
|
|
|
|
if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then
|
|
|
|
virt="chroot"
|
|
|
|
fi
|
2018-07-18 20:15:35 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "${virt}" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" '' 0 '' "${virt//\%/%%}"
|
2016-12-11 04:16:02 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Test icons
|
2015-08-04 16:21:22 +00:00
|
|
|
prompt_icons_test() {
|
2015-09-12 19:59:56 +00:00
|
|
|
for key in ${(@k)icons}; do
|
2015-08-04 16:21:22 +00:00
|
|
|
# The lower color spectrum in ZSH makes big steps. Choosing
|
|
|
|
# the next color has enough contrast to read.
|
|
|
|
local random_color=$((RANDOM % 8))
|
|
|
|
local next_color=$((random_color+1))
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "$random_color" "$next_color" "$key" 0 '' "$key"
|
2015-08-04 16:21:22 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display the current IP address
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default POWERLEVEL9K_IP_INTERFACE "^[^ ]+"
|
2015-08-26 15:36:04 +00:00
|
|
|
prompt_ip() {
|
2019-02-03 18:20:14 +00:00
|
|
|
local ROOT_PREFIX="${4}"
|
|
|
|
local ip=$(p9k::parseIp "${POWERLEVEL9K_IP_INTERFACE}" "${ROOT_PREFIX}")
|
2015-08-26 17:56:49 +00:00
|
|
|
|
2018-07-18 20:17:54 +00:00
|
|
|
if [[ -n "$ip" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" 'NETWORK_ICON' 0 '' "${ip//\%/%%}"
|
2018-07-18 20:17:54 +00:00
|
|
|
fi
|
2015-08-26 15:36:04 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display if VPN is active
|
2017-05-31 15:32:42 +00:00
|
|
|
set_default POWERLEVEL9K_VPN_IP_INTERFACE "tun"
|
|
|
|
# prompt if vpn active
|
|
|
|
prompt_vpn_ip() {
|
2019-01-21 18:46:53 +00:00
|
|
|
local ROOT_PREFIX="${4}"
|
2019-02-03 18:20:14 +00:00
|
|
|
local ip=$(p9k::parseIp "${POWERLEVEL9K_VPN_IP_INTERFACE}" "${ROOT_PREFIX}")
|
|
|
|
|
|
|
|
if [[ -n "${ip}" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" 'VPN_ICON' 0 '' "${ip//\%/%%}"
|
2018-12-30 10:26:04 +00:00
|
|
|
fi
|
2017-05-31 15:32:42 +00:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:10:26 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display laravel version
|
|
|
|
prompt_laravel_version() {
|
2018-07-23 01:55:44 +00:00
|
|
|
local laravel_version="$(php artisan --version 2> /dev/null)"
|
2018-07-18 15:45:05 +00:00
|
|
|
if [[ -n "${laravel_version}" && "${laravel_version}" =~ "Laravel Framework" ]]; then
|
2018-07-14 22:24:10 +00:00
|
|
|
# Strip out everything but the version
|
|
|
|
laravel_version="${laravel_version//Laravel Framework /}"
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "maroon" "white" 'LARAVEL_ICON' 0 '' "${laravel_version//\%/%%}"
|
2018-05-01 00:10:26 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display load
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default -i POWERLEVEL9K_LOAD_WHICH 5
|
2015-08-26 15:34:09 +00:00
|
|
|
prompt_load() {
|
2018-07-18 20:20:16 +00:00
|
|
|
local ROOT_PREFIX="${4}"
|
2016-01-08 19:42:06 +00:00
|
|
|
# The load segment can have three different states
|
|
|
|
local current_state="unknown"
|
2017-08-27 20:42:52 +00:00
|
|
|
local load_select=2
|
|
|
|
local load_avg
|
2016-04-22 11:24:30 +00:00
|
|
|
local cores
|
|
|
|
|
2016-01-08 19:42:06 +00:00
|
|
|
typeset -AH load_states
|
|
|
|
load_states=(
|
|
|
|
'critical' 'red'
|
|
|
|
'warning' 'yellow'
|
|
|
|
'normal' 'green'
|
|
|
|
)
|
2016-04-22 11:24:30 +00:00
|
|
|
|
2017-08-27 20:42:52 +00:00
|
|
|
case "$POWERLEVEL9K_LOAD_WHICH" in
|
|
|
|
1)
|
|
|
|
load_select=1
|
|
|
|
;;
|
|
|
|
5)
|
|
|
|
load_select=2
|
|
|
|
;;
|
|
|
|
15)
|
|
|
|
load_select=3
|
|
|
|
;;
|
|
|
|
esac
|
2017-08-17 19:54:26 +00:00
|
|
|
|
2017-08-27 20:42:52 +00:00
|
|
|
case "$OS" in
|
|
|
|
OSX|BSD)
|
|
|
|
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | sed -n ${load_select}p)
|
|
|
|
if [[ "$OS" == "OSX" ]]; then
|
|
|
|
cores=$(sysctl -n hw.logicalcpu)
|
|
|
|
else
|
|
|
|
cores=$(sysctl -n hw.ncpu)
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
2018-07-18 20:20:16 +00:00
|
|
|
load_avg=$(cut -d" " -f${load_select} ${ROOT_PREFIX}/proc/loadavg)
|
2017-08-27 20:42:52 +00:00
|
|
|
cores=$(nproc)
|
|
|
|
esac
|
2015-08-26 15:34:09 +00:00
|
|
|
|
2015-08-31 16:13:28 +00:00
|
|
|
# Replace comma
|
2017-08-17 19:54:26 +00:00
|
|
|
load_avg=${load_avg//,/.}
|
2015-08-31 16:13:28 +00:00
|
|
|
|
2018-01-15 07:58:05 +00:00
|
|
|
if [[ "$load_avg" -gt $((${cores} * 0.7)) ]]; then
|
2016-01-08 19:42:06 +00:00
|
|
|
current_state="critical"
|
2018-01-15 07:58:05 +00:00
|
|
|
elif [[ "$load_avg" -gt $((${cores} * 0.5)) ]]; then
|
2016-01-08 19:42:06 +00:00
|
|
|
current_state="warning"
|
2015-08-26 15:34:09 +00:00
|
|
|
else
|
2016-01-08 19:42:06 +00:00
|
|
|
current_state="normal"
|
2015-08-26 15:34:09 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" 'LOAD_ICON' 0 '' "$load_avg"
|
2015-08-26 15:34:09 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 10:26:34 +00: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]" "$cmd" "$@"; then
|
|
|
|
local out
|
|
|
|
out=$($cmd "$@" 2>/dev/null)
|
|
|
|
_p9k_cache_set $(( ! $? )) "$out"
|
|
|
|
fi
|
|
|
|
(( $_P9K_CACHE_VAL[1] )) || return
|
|
|
|
_P9K_RETVAL=$_P9K_CACHE_VAL[2]
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to diplay Node version
|
2019-03-22 12:45:52 +00:00
|
|
|
set_default P9K_NODE_VERSION_PROJECT_ONLY false
|
2015-05-26 19:51:01 +00:00
|
|
|
prompt_node_version() {
|
2019-05-21 10:26:34 +00:00
|
|
|
(( $+commands[node] )) || return
|
2019-04-02 01:14:52 +00:00
|
|
|
|
2019-05-21 10:26:34 +00:00
|
|
|
if [[ $P9K_NODE_VERSION_PROJECT_ONLY == true ]] ; then
|
|
|
|
local dir=$PWD
|
|
|
|
while true; do
|
|
|
|
[[ $dir == / ]] && return
|
|
|
|
[[ -e $dir/package.json ]] && break
|
|
|
|
dir=${dir:h}
|
2019-03-22 12:45:52 +00:00
|
|
|
done
|
|
|
|
fi
|
2014-12-05 01:26:21 +00:00
|
|
|
|
2019-05-21 10:26:34 +00:00
|
|
|
_p9k_cached_cmd_stdout node --version && [[ $_P9K_RETVAL == v?* ]] || return
|
|
|
|
"$1_prompt_segment" "$0" "$2" "green" "white" 'NODE_ICON' 0 '' "${_P9K_RETVAL#v}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
local target
|
|
|
|
while [[ -r $NVM_DIR/alias/$v ]] && read target <$NVM_DIR/alias/$v; do
|
|
|
|
[[ -n $target && ${seen[(I)$target]} == 0 ]] || return
|
|
|
|
seen+=$target
|
|
|
|
v=$target
|
|
|
|
done
|
|
|
|
|
|
|
|
case $v in
|
|
|
|
default|N/A)
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
system|v)
|
|
|
|
_P9K_RETVAL=system
|
|
|
|
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
|
|
|
|
_P9K_RETVAL=$v
|
|
|
|
return
|
|
|
|
elif [[ -x $NVM_DIR/versions/io.js/$v/bin/node ]]; then
|
|
|
|
_P9K_RETVAL=iojs-$v
|
|
|
|
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
|
|
|
|
|
|
|
|
emulate -L zsh && setopt extendedglob
|
|
|
|
|
|
|
|
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
|
|
|
|
_P9K_RETVAL=${path:t}
|
|
|
|
[[ ${path:h:t} != io.js ]] || _P9K_RETVAL=iojs-$_P9K_RETVAL
|
|
|
|
done
|
|
|
|
|
|
|
|
[[ -n $max ]]
|
|
|
|
}
|
2019-03-22 12:45:52 +00:00
|
|
|
|
2019-05-21 10:26:34 +00:00
|
|
|
# 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
|
|
|
|
_P9K_RETVAL=iojs-v${_P9K_RETVAL#v}
|
|
|
|
elif [[ -n $nvm_dir && $node_path == $nvm_dir/* ]]; then
|
|
|
|
_p9k_cached_cmd_stdout node --version || return
|
|
|
|
_P9K_RETVAL=v${_P9K_RETVAL#v}
|
|
|
|
else
|
|
|
|
_P9K_RETVAL=system
|
2019-03-22 12:45:52 +00:00
|
|
|
fi
|
2014-12-05 01:26:21 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display Node version from NVM
|
2016-01-05 21:56:07 +00:00
|
|
|
# Only prints the segment if different than the default value
|
|
|
|
prompt_nvm() {
|
2019-05-21 10:26:34 +00:00
|
|
|
[[ -n $NVM_DIR ]] && _p9k_nvm_ls_current || return
|
|
|
|
local current=$_P9K_RETVAL
|
|
|
|
! _p9k_nvm_ls_default || [[ $_P9K_RETVAL != $current ]] || return
|
|
|
|
$1_prompt_segment "$0" "$2" "magenta" "black" 'NODE_ICON' 0 '' "${${current#v}//\%/%%}"
|
2016-01-05 21:56:07 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display NodeEnv
|
2016-02-26 11:03:19 +00:00
|
|
|
prompt_nodeenv() {
|
2019-02-01 10:09:42 +00:00
|
|
|
if [[ -n "$NODE_VIRTUAL_ENV" ]]; then
|
2019-05-21 12:14:04 +00:00
|
|
|
_p9k_cached_cmd_stdout node --version || return
|
|
|
|
local info="${_P9K_RETVAL}[${NODE_VIRTUAL_ENV:t}]"
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "black" "green" 'NODE_ICON' 0 '' "${info//\%/%%}"
|
2016-02-26 11:03:19 +00:00
|
|
|
fi
|
2016-02-26 10:02:22 +00:00
|
|
|
}
|
2016-01-05 21:56:07 +00:00
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to print a little OS icon
|
2015-06-07 01:08:24 +00:00
|
|
|
prompt_os_icon() {
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "black" "white" '' 0 '' "$OS_ICON"
|
2015-06-07 01:08:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display PHP version number
|
2015-09-05 16:03:06 +00:00
|
|
|
prompt_php_version() {
|
2019-05-21 12:23:50 +00:00
|
|
|
_p9k_cached_cmd_stdout php --version || return
|
|
|
|
emulate -L zsh && setopt extendedglob
|
|
|
|
local -a match
|
|
|
|
[[ $_P9K_RETVAL == (#b)(*$'\n')#(PHP [0-9.]##)* ]] || return
|
|
|
|
local v=$match[2]
|
|
|
|
"$1_prompt_segment" "$0" "$2" "fuchsia" "grey93" '' 0 '' "${v//\%/%%}"
|
2015-09-05 16:03:06 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display free RAM and used Swap
|
2015-09-20 18:34:43 +00:00
|
|
|
prompt_ram() {
|
2018-07-18 20:24:25 +00:00
|
|
|
local ROOT_PREFIX="${4}"
|
2016-01-08 20:34:30 +00:00
|
|
|
local base=''
|
|
|
|
local ramfree=0
|
|
|
|
if [[ "$OS" == "OSX" ]]; then
|
2017-03-04 18:42:51 +00:00
|
|
|
# Available = Free + Inactive
|
|
|
|
# See https://support.apple.com/en-us/HT201538
|
2016-01-08 20:34:30 +00:00
|
|
|
ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+')
|
2017-03-04 18:42:51 +00:00
|
|
|
ramfree=$((ramfree + $(vm_stat | grep "Pages inactive" | grep -o -E '[0-9]+')))
|
2016-01-08 20:34:30 +00:00
|
|
|
# Convert pages into Bytes
|
|
|
|
ramfree=$(( ramfree * 4096 ))
|
|
|
|
else
|
2016-10-05 01:08:32 +00:00
|
|
|
if [[ "$OS" == "BSD" ]]; then
|
2018-07-18 20:24:25 +00:00
|
|
|
ramfree=$(grep 'avail memory' ${ROOT_PREFIX}/var/run/dmesg.boot | awk '{print $4}')
|
2016-10-05 01:08:32 +00:00
|
|
|
else
|
2018-07-18 20:24:25 +00:00
|
|
|
ramfree=$(grep -o -E "MemAvailable:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+")
|
2016-10-05 01:08:32 +00:00
|
|
|
base='K'
|
|
|
|
fi
|
2016-01-08 20:34:30 +00:00
|
|
|
fi
|
2015-09-20 18:34:43 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" 'RAM_ICON' 0 '' "$(printSizeHumanReadable "$ramfree" $base)"
|
2015-08-26 15:34:09 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 12:55:27 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display rbenv information
|
2018-07-14 09:09:56 +00:00
|
|
|
# https://github.com/rbenv/rbenv#choosing-the-ruby-version
|
2018-04-03 12:52:13 +00:00
|
|
|
set_default POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW false
|
2015-03-26 22:39:27 +00:00
|
|
|
prompt_rbenv() {
|
2018-07-14 09:09:56 +00:00
|
|
|
if [[ -n "$RBENV_VERSION" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" 'RUBY_ICON' 0 '' "$RBENV_VERSION"
|
2018-07-14 09:09:56 +00:00
|
|
|
elif [ $commands[rbenv] ]; then
|
2016-02-12 22:09:04 +00:00
|
|
|
local rbenv_version_name="$(rbenv version-name)"
|
|
|
|
local rbenv_global="$(rbenv global)"
|
2018-07-14 12:41:15 +00:00
|
|
|
if [[ "${rbenv_version_name}" != "${rbenv_global}" || "${POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" 'RUBY_ICON' 0 '' "${rbenv_version_name//\%/%%}"
|
2016-02-12 22:09:04 +00:00
|
|
|
fi
|
2015-03-26 22:39:27 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display chruby information
|
2016-03-04 20:44:58 +00:00
|
|
|
# see https://github.com/postmodern/chruby/issues/245 for chruby_auto issue with ZSH
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default POWERLEVEL9K_CHRUBY_SHOW_VERSION true
|
|
|
|
set_default POWERLEVEL9K_CHRUBY_SHOW_ENGINE true
|
2016-03-04 20:44:58 +00:00
|
|
|
prompt_chruby() {
|
2018-04-30 17:52:15 +00:00
|
|
|
# Uses $RUBY_VERSION and $RUBY_ENGINE set by chruby
|
|
|
|
local chruby_label=""
|
|
|
|
|
|
|
|
if [[ "$POWERLEVEL9K_CHRUBY_SHOW_ENGINE" == true ]]; then
|
|
|
|
chruby_label+="$RUBY_ENGINE "
|
|
|
|
fi
|
|
|
|
if [[ "$POWERLEVEL9K_CHRUBY_SHOW_VERSION" == true ]]; then
|
|
|
|
chruby_label+="$RUBY_VERSION"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Truncate trailing spaces
|
|
|
|
chruby_label="${chruby_label%"${chruby_label##*[![:space:]]}"}"
|
|
|
|
|
2016-03-04 20:44:58 +00:00
|
|
|
# Don't show anything if the chruby did not change the default ruby
|
2018-04-30 17:52:15 +00:00
|
|
|
if [[ "$RUBY_ENGINE" != "" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" 'RUBY_ICON' 0 '' "${chruby_label//\%/%%}"
|
2016-03-04 20:44:58 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to print an icon if user is root.
|
2015-12-13 11:41:49 +00:00
|
|
|
prompt_root_indicator() {
|
2019-04-30 09:54:00 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" 'ROOT_ICON' 0 '${${(%):-%#}:#%}' ''
|
2019-03-16 20:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# This segment is a demo. It can disappear any time. Use prompt_dir instead.
|
|
|
|
prompt_simple_dir() {
|
2019-03-18 18:52:53 +00:00
|
|
|
if ! _p9k_cache_get "$0" "$1" "$2" ; then
|
|
|
|
local p=$_P9K_PROMPT
|
|
|
|
local key=$_P9K_CACHE_KEY
|
|
|
|
_P9K_PROMPT=''
|
2019-04-30 09:54:00 +00:00
|
|
|
$1_prompt_segment $0_HOME $2 blue "$DEFAULT_COLOR" HOME_ICON 0 '${$((!${#${(%):-%~}:#\~})):#0}' "%~"
|
|
|
|
$1_prompt_segment $0_HOME_SUBFOLDER $2 blue "$DEFAULT_COLOR" HOME_SUB_ICON 0 '${$((!${#${(%):-%~}:#\~?*})):#0}' "%~"
|
|
|
|
$1_prompt_segment $0_ETC $2 blue "$DEFAULT_COLOR" ETC_ICON 0 '${$((!${#${(%):-%~}:#/etc*})):#0}' "%~"
|
|
|
|
$1_prompt_segment $0_DEFAULT $2 blue "$DEFAULT_COLOR" FOLDER_ICON 0 '${${${(%):-%~}:#\~*}:#/etc*}' "%~"
|
2019-03-18 18:52:53 +00:00
|
|
|
_P9K_CACHE_KEY=$key
|
|
|
|
_p9k_cache_set "$_P9K_PROMPT"
|
|
|
|
_P9K_PROMPT=$p
|
|
|
|
fi
|
|
|
|
_P9K_PROMPT+=${_P9K_CACHE_VAL[1]}
|
2015-03-26 22:39:27 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display Rust version number
|
2015-09-30 18:12:47 +00:00
|
|
|
prompt_rust_version() {
|
2018-06-07 00:01:36 +00:00
|
|
|
local rust_version
|
|
|
|
rust_version=$(command rustc --version 2>/dev/null)
|
2018-05-05 17:25:29 +00:00
|
|
|
# Remove "rustc " (including the whitespace) from the beginning
|
|
|
|
# of the version string and remove everything after the next
|
|
|
|
# whitespace. This way we'll end up with only the version.
|
|
|
|
rust_version=${${rust_version/rustc /}%% *}
|
2015-09-30 18:12:47 +00:00
|
|
|
|
|
|
|
if [[ -n "$rust_version" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "darkorange" "$DEFAULT_COLOR" 'RUST_ICON' 0 '' "${rust_version//\%/%%}"
|
2015-09-30 18:12:47 +00:00
|
|
|
fi
|
|
|
|
}
|
2018-01-05 07:04:04 +00:00
|
|
|
|
2015-04-01 01:51:19 +00:00
|
|
|
# RSpec test ratio
|
|
|
|
prompt_rspec_stats() {
|
2019-03-15 13:11:53 +00:00
|
|
|
if [[ -d app && -d spec ]]; then
|
2015-09-12 19:59:56 +00:00
|
|
|
local code_amount tests_amount
|
|
|
|
code_amount=$(ls -1 app/**/*.rb | wc -l)
|
|
|
|
tests_amount=$(ls -1 spec/**/*.rb | wc -l)
|
2015-04-01 01:51:19 +00:00
|
|
|
|
2015-12-18 00:07:22 +00:00
|
|
|
build_test_stats "$1" "$0" "$2" "$code_amount" "$tests_amount" "RSpec" 'TEST_ICON'
|
2015-04-01 01:51:19 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display Ruby Version Manager information
|
2015-04-03 16:15:16 +00:00
|
|
|
prompt_rvm() {
|
2019-01-04 20:59:05 +00:00
|
|
|
if [ $commands[rvm-prompt] ]; then
|
|
|
|
local version_and_gemset=${$(rvm-prompt v p)/ruby-}
|
2015-11-15 22:35:15 +00:00
|
|
|
|
2019-01-04 20:59:05 +00:00
|
|
|
if [[ -n "$version_and_gemset" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" 'RUBY_ICON' 0 '' "${version_and_gemset//\%/%%}"
|
2019-01-04 20:59:05 +00:00
|
|
|
fi
|
2015-04-03 16:15:16 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display SSH icon when connected
|
2017-02-14 03:07:23 +00:00
|
|
|
prompt_ssh() {
|
2019-03-13 16:04:27 +00:00
|
|
|
if [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" 'SSH_ICON' 0 '' ''
|
2017-02-14 03:07:23 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2017-07-15 19:28:27 +00: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
|
2017-07-27 02:21:18 +00:00
|
|
|
#
|
2017-07-15 19:28:27 +00:00
|
|
|
set_default POWERLEVEL9K_STATUS_CROSS false
|
|
|
|
set_default POWERLEVEL9K_STATUS_OK true
|
2017-05-13 02:13:37 +00:00
|
|
|
set_default POWERLEVEL9K_STATUS_SHOW_PIPESTATUS true
|
2017-07-27 02:21:18 +00:00
|
|
|
set_default POWERLEVEL9K_STATUS_HIDE_SIGNAME false
|
|
|
|
# old options, retro compatibility
|
|
|
|
set_default POWERLEVEL9K_STATUS_VERBOSE true
|
|
|
|
set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false
|
|
|
|
|
|
|
|
exit_code_or_status() {
|
|
|
|
local ec=$1
|
2019-03-06 22:04:06 +00:00
|
|
|
if [[ "$POWERLEVEL9K_STATUS_HIDE_SIGNAME" = true ]] || (( ec <= 128 )); then
|
|
|
|
_P9K_RETVAL=$ec
|
2017-07-27 02:21:18 +00:00
|
|
|
else
|
2019-03-06 22:04:06 +00:00
|
|
|
_P9K_RETVAL="SIG${signals[$((sig + 1))]}($((ec - 128)))"
|
2017-07-27 02:21:18 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
typeset -gi _P9K_EXIT_CODE
|
|
|
|
typeset -ga _P9K_PIPE_EXIT_CODES
|
|
|
|
|
2015-04-03 16:15:16 +00:00
|
|
|
prompt_status() {
|
2019-03-13 16:04:27 +00:00
|
|
|
if ! _p9k_cache_get "$0" "$2" "$_P9K_EXIT_CODE" "${(@)_P9K_PIPE_EXIT_CODES}"; then
|
2019-02-24 19:16:04 +00:00
|
|
|
local ec_text
|
|
|
|
local ec_sum
|
|
|
|
local ec
|
|
|
|
|
|
|
|
if [[ $POWERLEVEL9K_STATUS_SHOW_PIPESTATUS == true ]]; then
|
2019-03-13 16:04:27 +00:00
|
|
|
if (( $#_P9K_PIPE_EXIT_CODES > 1 )); then
|
|
|
|
ec_sum=${_P9K_PIPE_EXIT_CODES[1]}
|
|
|
|
exit_code_or_status "${_P9K_PIPE_EXIT_CODES[1]}"
|
2019-04-02 01:14:52 +00:00
|
|
|
|
2019-02-24 19:16:04 +00:00
|
|
|
else
|
2019-03-13 16:04:27 +00:00
|
|
|
ec_sum=${_P9K_EXIT_CODE}
|
|
|
|
exit_code_or_status "${_P9K_EXIT_CODE}"
|
2019-02-24 19:16:04 +00:00
|
|
|
fi
|
2019-03-06 22:04:06 +00:00
|
|
|
ec_text=$_P9K_RETVAL
|
2019-03-13 16:04:27 +00:00
|
|
|
for ec in "${(@)_P9K_PIPE_EXIT_CODES[2,-1]}"; do
|
2019-03-06 22:04:06 +00:00
|
|
|
(( ec_sum += ec ))
|
|
|
|
exit_code_or_status "$ec"
|
|
|
|
ec_text+="|$_P9K_RETVAL"
|
2019-02-24 19:16:04 +00:00
|
|
|
done
|
2018-03-26 18:55:06 +00:00
|
|
|
else
|
2019-03-13 16:04:27 +00:00
|
|
|
ec_sum=${_P9K_EXIT_CODE}
|
|
|
|
# We use _P9K_EXIT_CODE instead of the right-most _P9K_PIPE_EXIT_CODES item because
|
2019-02-24 19:16:04 +00:00
|
|
|
# PIPE_FAIL may be set.
|
2019-03-13 16:04:27 +00:00
|
|
|
exit_code_or_status "${_P9K_EXIT_CODE}"
|
2019-03-06 22:04:06 +00:00
|
|
|
ec_text=$_P9K_RETVAL
|
2018-03-26 18:55:06 +00:00
|
|
|
fi
|
2017-05-04 03:53:59 +00:00
|
|
|
|
2019-02-24 19:16:04 +00:00
|
|
|
if (( ec_sum > 0 )); then
|
|
|
|
if [[ "$POWERLEVEL9K_STATUS_CROSS" == false && "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
_P9K_CACHE_VAL=("$0_ERROR" "$2" red yellow1 CARRIAGE_RETURN_ICON 0 '' "$ec_text")
|
2019-02-24 19:16:04 +00:00
|
|
|
else
|
2019-03-19 16:56:56 +00:00
|
|
|
_P9K_CACHE_VAL=("$0_ERROR" "$2" "$DEFAULT_COLOR" red FAIL_ICON 0 '' '')
|
2019-02-24 19:16:04 +00:00
|
|
|
fi
|
|
|
|
elif [[ "$POWERLEVEL9K_STATUS_OK" == true ]] && [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true || "$POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE" == true ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
_P9K_CACHE_VAL=("$0_OK" "$2" "$DEFAULT_COLOR" green OK_ICON 0 '' '')
|
2019-03-04 02:22:14 +00:00
|
|
|
else
|
|
|
|
return
|
2019-02-24 19:16:04 +00:00
|
|
|
fi
|
2019-03-13 16:04:27 +00:00
|
|
|
if (( $#_P9K_PIPE_EXIT_CODES < 3 )); then
|
2019-03-08 11:24:50 +00:00
|
|
|
_p9k_cache_set "${(@)_P9K_CACHE_VAL}"
|
2015-12-13 11:41:49 +00:00
|
|
|
fi
|
2015-09-20 19:24:37 +00:00
|
|
|
fi
|
2019-03-08 11:24:50 +00:00
|
|
|
"$1_prompt_segment" "${(@)_P9K_CACHE_VAL}"
|
2015-04-03 16:15:16 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display Swap information
|
2016-01-08 20:34:30 +00:00
|
|
|
prompt_swap() {
|
2018-07-18 20:26:08 +00:00
|
|
|
local ROOT_PREFIX="${4}"
|
2016-01-08 20:34:30 +00:00
|
|
|
local swap_used=0
|
|
|
|
local base=''
|
|
|
|
|
|
|
|
if [[ "$OS" == "OSX" ]]; then
|
|
|
|
local raw_swap_used
|
|
|
|
raw_swap_used=$(sysctl vm.swapusage | grep -o "used\s*=\s*[0-9,.A-Z]*" | grep -o "[0-9,.A-Z]*$")
|
|
|
|
|
|
|
|
typeset -F 2 swap_used
|
|
|
|
swap_used=${$(echo $raw_swap_used | grep -o "[0-9,.]*")//,/.}
|
|
|
|
# Replace comma
|
|
|
|
swap_used=${swap_used//,/.}
|
|
|
|
|
|
|
|
base=$(echo "$raw_swap_used" | grep -o "[A-Z]*$")
|
|
|
|
else
|
2018-07-18 20:26:08 +00:00
|
|
|
swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+")
|
|
|
|
swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+")
|
2016-01-08 20:34:30 +00:00
|
|
|
swap_used=$(( swap_total - swap_free ))
|
|
|
|
base='K'
|
|
|
|
fi
|
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" 'SWAP_ICON' 0 '' "$(printSizeHumanReadable "$swap_used" $base)"
|
2016-01-08 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2015-04-01 01:51:19 +00:00
|
|
|
# Symfony2-PHPUnit test ratio
|
|
|
|
prompt_symfony2_tests() {
|
2019-03-13 16:04:27 +00:00
|
|
|
if [[ -d src && -d app && -f app/AppKernel.php ]]; then
|
2015-09-12 19:59:56 +00:00
|
|
|
local code_amount tests_amount
|
|
|
|
code_amount=$(ls -1 src/**/*.php | grep -vc Tests)
|
|
|
|
tests_amount=$(ls -1 src/**/*.php | grep -c Tests)
|
2015-04-01 01:51:19 +00:00
|
|
|
|
2015-12-18 00:07:22 +00:00
|
|
|
build_test_stats "$1" "$0" "$2" "$code_amount" "$tests_amount" "SF2" 'TEST_ICON'
|
2015-04-01 01:51:19 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display Symfony2-Version
|
2015-05-24 18:34:46 +00:00
|
|
|
prompt_symfony2_version() {
|
|
|
|
if [[ -f app/bootstrap.php.cache ]]; then
|
2015-09-12 19:59:56 +00:00
|
|
|
local symfony2_version
|
|
|
|
symfony2_version=$(grep " VERSION " app/bootstrap.php.cache | sed -e 's/[^.0-9]*//g')
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "grey35" "$DEFAULT_COLOR" 'SYMFONY_ICON' 0 '' "${symfony2_version//\%/%%}"
|
2015-04-01 01:51:19 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2015-04-01 01:51:19 +00:00
|
|
|
# Show a ratio of tests vs code
|
|
|
|
build_test_stats() {
|
2015-12-16 18:26:27 +00:00
|
|
|
local code_amount="$4"
|
|
|
|
local tests_amount="$5"+0.00001
|
|
|
|
local headline="$6"
|
2015-04-01 01:51:19 +00:00
|
|
|
|
2015-04-02 00:17:25 +00:00
|
|
|
# Set float precision to 2 digits:
|
2019-03-13 16:04:27 +00:00
|
|
|
local -F 2 ratio=$(( (tests_amount/code_amount) * 100 ))
|
2015-04-01 01:51:19 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
(( ratio >= 75 )) && "$1_prompt_segment" "${2}_GOOD" "$3" "cyan" "$DEFAULT_COLOR" "$6" 0 '' "$headline: $ratio%%"
|
|
|
|
(( ratio >= 50 && ratio < 75 )) && "$1_prompt_segment" "$2_AVG" "$3" "yellow" "$DEFAULT_COLOR" "$6" 0 '' "$headline: $ratio%%"
|
|
|
|
(( ratio < 50 )) && "$1_prompt_segment" "$2_BAD" "$3" "red" "$DEFAULT_COLOR" "$6" 0 '' "$headline: $ratio%%"
|
2015-04-01 01:51:19 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2015-04-03 16:15:16 +00:00
|
|
|
# System time
|
2019-03-11 18:12:53 +00:00
|
|
|
|
|
|
|
# If set to true, `time` prompt will update every second.
|
|
|
|
set_default POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME false
|
2019-03-12 07:29:33 +00:00
|
|
|
set_default POWERLEVEL9K_TIME_FORMAT "%D{%H:%M:%S}"
|
2015-04-03 16:15:16 +00:00
|
|
|
prompt_time() {
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "TIME_ICON" 0 '' "$POWERLEVEL9K_TIME_FORMAT"
|
2018-01-05 07:04:04 +00:00
|
|
|
}
|
2015-04-03 16:15:16 +00:00
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# System date
|
2019-03-12 07:29:33 +00:00
|
|
|
set_default POWERLEVEL9K_DATE_FORMAT "%D{%d.%m.%y}"
|
2018-01-05 07:04:04 +00:00
|
|
|
prompt_date() {
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "DATE_ICON" 0 '' "$POWERLEVEL9K_DATE_FORMAT"
|
2015-04-03 16:15:16 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2015-10-17 18:30:55 +00:00
|
|
|
# todo.sh: shows the number of tasks in your todo.sh file
|
|
|
|
prompt_todo() {
|
|
|
|
if $(hash todo.sh 2>&-); then
|
|
|
|
count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }')
|
|
|
|
if [[ "$count" = <-> ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" 'TODO_ICON' 0 '' "${count//\%/%%}"
|
2015-10-17 18:30:55 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2016-01-05 21:56:07 +00:00
|
|
|
# VCS segment: shows the state of your repository, if you are in a folder under
|
|
|
|
# version control
|
2019-03-13 16:04:27 +00:00
|
|
|
|
|
|
|
# The vcs segment can have 4 different states - defaults to 'clean'.
|
|
|
|
typeset -gA vcs_states=(
|
|
|
|
'clean' 'green'
|
|
|
|
'modified' 'yellow'
|
|
|
|
'untracked' 'green'
|
|
|
|
'loading' 'grey'
|
|
|
|
)
|
|
|
|
|
|
|
|
set_default POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND red
|
|
|
|
set_default POWERLEVEL9K_SHOW_CHANGESET false
|
2019-03-20 13:47:29 +00:00
|
|
|
set_default POWERLEVEL9K_VCS_LOADING_TEXT loading
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default -i POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH 8
|
|
|
|
set_default -a POWERLEVEL9K_VCS_GIT_HOOKS vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname
|
|
|
|
set_default -a POWERLEVEL9K_VCS_HG_HOOKS vcs-detect-changes
|
|
|
|
set_default -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.
|
|
|
|
set_default -F POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS 0.05
|
|
|
|
set_default -a POWERLEVEL9K_VCS_BACKENDS git
|
2019-03-06 22:04:06 +00:00
|
|
|
|
2016-08-11 19:40:05 +00:00
|
|
|
powerlevel9k_vcs_init() {
|
2016-04-17 15:51:31 +00:00
|
|
|
if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then
|
|
|
|
POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH"
|
|
|
|
fi
|
|
|
|
|
2019-03-20 13:47:29 +00:00
|
|
|
local component state
|
|
|
|
for component in REMOTE_URL COMMIT BRANCH TAG REMOTE_BRANCH STAGED UNSTAGED UNTRACKED \
|
|
|
|
OUTGOING_CHANGES INCOMING_CHANGES STASH ACTION; do
|
2019-04-30 10:20:23 +00:00
|
|
|
local color=${(P)${:-POWERLEVEL9K_VCS_${component}FORMAT_FOREGROUND}}
|
2019-03-20 13:47:29 +00:00
|
|
|
if [[ -n $color ]]; then
|
|
|
|
for state in "${(@k)vcs_states}"; do
|
|
|
|
local var=POWERLEVEL9K_VCS_${(U)state}_${component}FORMAT_FOREGROUND
|
|
|
|
if [[ -z ${(P)var} ]]; then
|
|
|
|
typeset -g $var=$color
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
2019-03-19 18:40:18 +00:00
|
|
|
|
2015-10-23 22:05:15 +00:00
|
|
|
autoload -Uz vcs_info
|
|
|
|
|
|
|
|
VCS_CHANGESET_PREFIX=''
|
|
|
|
if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then
|
2016-04-17 15:51:31 +00:00
|
|
|
VCS_CHANGESET_PREFIX="$(print_icon 'VCS_COMMIT_ICON')%0.$POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH""i "
|
2015-10-23 22:05:15 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
zstyle ':vcs_info:*' check-for-changes true
|
|
|
|
|
2016-02-10 20:57:06 +00:00
|
|
|
VCS_DEFAULT_FORMAT="$VCS_CHANGESET_PREFIX%b%c%u%m"
|
2015-12-17 23:47:37 +00:00
|
|
|
zstyle ':vcs_info:*' formats "$VCS_DEFAULT_FORMAT"
|
2016-04-03 17:13:58 +00:00
|
|
|
zstyle ':vcs_info:*' actionformats "%b %F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| %a%f"
|
2016-02-10 20:57:06 +00:00
|
|
|
zstyle ':vcs_info:*' stagedstr " $(print_icon 'VCS_STAGED_ICON')"
|
|
|
|
zstyle ':vcs_info:*' unstagedstr " $(print_icon 'VCS_UNSTAGED_ICON')"
|
2016-01-17 15:00:45 +00:00
|
|
|
zstyle ':vcs_info:git*+set-message:*' hooks $POWERLEVEL9K_VCS_GIT_HOOKS
|
|
|
|
zstyle ':vcs_info:hg*+set-message:*' hooks $POWERLEVEL9K_VCS_HG_HOOKS
|
2016-08-25 21:15:55 +00:00
|
|
|
zstyle ':vcs_info:svn*+set-message:*' hooks $POWERLEVEL9K_VCS_SVN_HOOKS
|
2015-10-23 22:05:15 +00:00
|
|
|
|
|
|
|
# For Hg, only show the branch name
|
|
|
|
zstyle ':vcs_info:hg*:*' branchformat "$(print_icon 'VCS_BRANCH_ICON')%b"
|
|
|
|
# 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
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
# TODO: fix the %b (branch) format for svn. Using %b breaks color-encoding of the foreground
|
|
|
|
# for the rest of the powerline.
|
2017-04-16 14:53:48 +00:00
|
|
|
zstyle ':vcs_info:svn*:*' formats "$VCS_CHANGESET_PREFIX%c%u"
|
|
|
|
zstyle ':vcs_info:svn*:*' actionformats "$VCS_CHANGESET_PREFIX%c%u %F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| %a%f"
|
|
|
|
|
2015-10-23 22:05:15 +00:00
|
|
|
if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then
|
|
|
|
zstyle ':vcs_info:*' get-revision true
|
|
|
|
fi
|
2016-08-11 19:40:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-06 22:04:06 +00:00
|
|
|
# git workdir => the last prompt we've shown for it
|
|
|
|
typeset -gAH _P9K_LAST_GIT_PROMPT
|
|
|
|
|
|
|
|
# git workdir => 1 if gitstatus is slow on it, 0 if it's fast.
|
|
|
|
typeset -gAH _P9K_GIT_SLOW
|
|
|
|
|
2019-03-19 18:40:18 +00:00
|
|
|
function _p9k_vcs_style() {
|
2019-04-30 10:20:23 +00:00
|
|
|
local color=${(P)${:-POWERLEVEL9K_VCS_${1}_${2}FORMAT_FOREGROUND}}
|
2019-03-19 18:40:18 +00:00
|
|
|
if [[ -z $color ]]; then
|
|
|
|
_P9K_RETVAL=""
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if [[ $color == <-> ]]; then
|
|
|
|
color=${(l:3::0:)color}
|
|
|
|
else
|
|
|
|
color=$__P9K_COLORS[${${${color#bg-}#fg-}#br}]
|
|
|
|
if [[ -z $color ]]; then
|
|
|
|
_P9K_RETVAL=""
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
_P9K_RETVAL="%F{$color}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function _p9k_vcs_render() {
|
2019-04-30 10:51:34 +00:00
|
|
|
if (( $+_P9K_NEXT_VCS_DIR )); then
|
2019-03-19 18:40:18 +00:00
|
|
|
local -a msg
|
2019-03-27 09:09:42 +00:00
|
|
|
local dir=${${GIT_DIR:a}:-$PWD}
|
2019-03-06 22:04:06 +00:00
|
|
|
while true; do
|
2019-03-19 18:40:18 +00:00
|
|
|
msg=("${(@0)${_P9K_LAST_GIT_PROMPT[$dir]}}")
|
2019-05-01 10:17:27 +00:00
|
|
|
[[ $#msg -gt 1 || -n ${msg[1]} ]] && break
|
|
|
|
[[ $dir == / ]] && msg=() && break
|
2019-03-06 22:04:06 +00:00
|
|
|
dir=${dir:h}
|
|
|
|
done
|
2019-05-01 10:17:27 +00:00
|
|
|
if (( $#msg )); then
|
|
|
|
$2_prompt_segment $1_LOADING $3 "${vcs_states[loading]}" "$DEFAULT_COLOR" '' 0 '' "${msg[@]}"
|
|
|
|
else
|
2019-03-20 13:47:29 +00:00
|
|
|
_p9k_get_icon VCS_LOADING_ICON
|
|
|
|
if [[ -n $_P9K_RETVAL || -n $POWERLEVEL9K_VCS_LOADING_TEXT ]]; then
|
2019-04-02 01:14:52 +00:00
|
|
|
$2_prompt_segment $1_LOADING $3 "${vcs_states[loading]}" "$DEFAULT_COLOR" VCS_LOADING_ICON 0 '' "$POWERLEVEL9K_VCS_LOADING_TEXT"
|
2019-03-20 13:47:29 +00:00
|
|
|
fi
|
|
|
|
fi
|
2019-03-06 22:04:06 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
[[ $VCS_STATUS_RESULT == ok-* ]] || return 1
|
2019-03-14 19:43:33 +00:00
|
|
|
|
|
|
|
(( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-untracked]} )) || VCS_STATUS_HAS_UNTRACKED=0
|
2019-03-21 16:38:49 +00:00
|
|
|
(( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-aheadbehind]} )) || { VCS_STATUS_COMMITS_AHEAD=0 && VCS_STATUS_COMMITS_BEHIND=0 }
|
2019-03-14 19:43:33 +00:00
|
|
|
(( ${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-03-08 11:24:50 +00:00
|
|
|
local -a cache_key=(
|
|
|
|
"$VCS_STATUS_LOCAL_BRANCH"
|
|
|
|
"$VCS_STATUS_REMOTE_BRANCH"
|
|
|
|
"$VCS_STATUS_REMOTE_URL"
|
|
|
|
"$VCS_STATUS_ACTION"
|
|
|
|
"$VCS_STATUS_HAS_STAGED"
|
|
|
|
"$VCS_STATUS_HAS_UNSTAGED"
|
|
|
|
"$VCS_STATUS_HAS_UNTRACKED"
|
|
|
|
"$VCS_STATUS_COMMITS_AHEAD"
|
|
|
|
"$VCS_STATUS_COMMITS_BEHIND"
|
|
|
|
"$VCS_STATUS_STASHES"
|
2019-03-14 19:43:33 +00:00
|
|
|
"$VCS_STATUS_TAG"
|
2019-03-08 11:24:50 +00:00
|
|
|
)
|
2019-03-14 19:43:33 +00:00
|
|
|
if [[ $POWERLEVEL9K_SHOW_CHANGESET == true || -z $VCS_STATUS_LOCAL_BRANCH ]]; then
|
|
|
|
cache_key+=$VCS_STATUS_COMMIT
|
|
|
|
fi
|
|
|
|
|
2019-03-08 11:24:50 +00:00
|
|
|
if ! _p9k_cache_get "${(@)cache_key}"; then
|
2019-03-19 18:40:18 +00:00
|
|
|
local state=CLEAN
|
|
|
|
local -a cur_prompt
|
|
|
|
local -a stale_prompt
|
|
|
|
|
2019-03-21 14:02:41 +00:00
|
|
|
function _$0_fmt() {
|
2019-03-19 18:40:18 +00:00
|
|
|
_p9k_vcs_style $state $1
|
|
|
|
cur_prompt+=$_P9K_RETVAL$2
|
|
|
|
_p9k_vcs_style LOADING $1
|
|
|
|
stale_prompt+=$_P9K_RETVAL$2
|
|
|
|
}
|
2019-03-14 19:43:33 +00:00
|
|
|
|
2019-03-21 14:02:41 +00:00
|
|
|
trap "unfunction _$0_fmt" EXIT
|
|
|
|
|
2019-03-14 19:43:33 +00:00
|
|
|
if (( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)vcs-detect-changes]} )); then
|
|
|
|
if [[ $VCS_STATUS_HAS_STAGED != 0 || $VCS_STATUS_HAS_UNSTAGED != 0 ]]; then
|
2019-03-19 18:40:18 +00:00
|
|
|
state=MODIFIED
|
2019-03-14 19:43:33 +00:00
|
|
|
elif [[ $VCS_STATUS_HAS_UNTRACKED != 0 ]]; then
|
2019-03-19 18:40:18 +00:00
|
|
|
state=UNTRACKED
|
2019-03-14 19:43:33 +00: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.
|
|
|
|
if [[ "$VCS_STATUS_REMOTE_URL" == *github* ]] then
|
|
|
|
_p9k_get_icon VCS_GIT_GITHUB_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt REMOTE_URL $_P9K_RETVAL
|
2019-03-14 19:43:33 +00:00
|
|
|
elif [[ "$VCS_STATUS_REMOTE_URL" == *bitbucket* ]] then
|
|
|
|
_p9k_get_icon VCS_GIT_BITBUCKET_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt REMOTE_URL $_P9K_RETVAL
|
2019-03-14 19:43:33 +00:00
|
|
|
elif [[ "$VCS_STATUS_REMOTE_URL" == *stash* ]] then
|
|
|
|
_p9k_get_icon VCS_GIT_GITHUB_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt REMOTE_URL $_P9K_RETVAL
|
2019-03-14 19:43:33 +00:00
|
|
|
elif [[ "$VCS_STATUS_REMOTE_URL" == *gitlab* ]] then
|
|
|
|
_p9k_get_icon VCS_GIT_GITLAB_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt REMOTE_URL $_P9K_RETVAL
|
2019-03-14 19:43:33 +00:00
|
|
|
else
|
|
|
|
_p9k_get_icon VCS_GIT_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt REMOTE_URL $_P9K_RETVAL
|
2019-03-14 19:43:33 +00:00
|
|
|
fi
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-19 18:40:18 +00:00
|
|
|
local ws
|
2019-03-14 19:43:33 +00:00
|
|
|
if [[ $POWERLEVEL9K_SHOW_CHANGESET == true || -z $VCS_STATUS_LOCAL_BRANCH ]]; then
|
|
|
|
_p9k_get_icon VCS_COMMIT_ICON
|
2019-03-24 17:05:48 +00:00
|
|
|
_$0_fmt COMMIT "$_P9K_RETVAL${${VCS_STATUS_COMMIT:0:$POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH}:-HEAD}"
|
2019-03-19 18:40:18 +00:00
|
|
|
ws=' '
|
2019-03-14 19:43:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
|
|
|
|
_p9k_get_icon VCS_BRANCH_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt BRANCH "$ws$_P9K_RETVAL${VCS_STATUS_LOCAL_BRANCH//\%/%%}"
|
2019-03-14 19:43:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $POWERLEVEL9K_VCS_HIDE_TAGS == false && -n $VCS_STATUS_TAG ]]; then
|
|
|
|
_p9k_get_icon VCS_TAG_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt TAG " $_P9K_RETVAL${VCS_STATUS_TAG//\%/%%}"
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n $VCS_STATUS_ACTION ]]; then
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt ACTION " | ${VCS_STATUS_ACTION//\%/%%}"
|
2019-03-06 22:04:06 +00:00
|
|
|
else
|
|
|
|
if [[ -n $VCS_STATUS_REMOTE_BRANCH &&
|
|
|
|
$VCS_STATUS_LOCAL_BRANCH != $VCS_STATUS_REMOTE_BRANCH ]]; then
|
|
|
|
_p9k_get_icon VCS_REMOTE_BRANCH_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt REMOTE_BRANCH " $_P9K_RETVAL${VCS_STATUS_REMOTE_BRANCH//\%/%%}"
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
if [[ $VCS_STATUS_HAS_STAGED == 1 ]]; then
|
|
|
|
_p9k_get_icon VCS_STAGED_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt STAGED " $_P9K_RETVAL"
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
if [[ $VCS_STATUS_HAS_UNSTAGED == 1 ]]; then
|
|
|
|
_p9k_get_icon VCS_UNSTAGED_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt UNSTAGED " $_P9K_RETVAL"
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
if [[ $VCS_STATUS_HAS_UNTRACKED == 1 ]]; then
|
|
|
|
_p9k_get_icon VCS_UNTRACKED_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt UNTRACKED " $_P9K_RETVAL"
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
if [[ $VCS_STATUS_COMMITS_AHEAD -gt 0 ]]; then
|
|
|
|
_p9k_get_icon VCS_OUTGOING_CHANGES_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt OUTGOING_CHANGES " $_P9K_RETVAL$VCS_STATUS_COMMITS_AHEAD"
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
if [[ $VCS_STATUS_COMMITS_BEHIND -gt 0 ]]; then
|
|
|
|
_p9k_get_icon VCS_INCOMING_CHANGES_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt INCOMING_CHANGES " $_P9K_RETVAL$VCS_STATUS_COMMITS_BEHIND"
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
if [[ $VCS_STATUS_STASHES -gt 0 ]]; then
|
|
|
|
_p9k_get_icon VCS_STASH_ICON
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_fmt STASH " $_P9K_RETVAL$VCS_STATUS_STASHES"
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-03-19 18:40:18 +00:00
|
|
|
_p9k_cache_set "${1}_$state" "${vcs_states[${(L)state}]}" "${stale_prompt[@]}" "${cur_prompt[@]}"
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-19 18:40:18 +00:00
|
|
|
local id=${_P9K_CACHE_VAL[1]}
|
|
|
|
local bg=${_P9K_CACHE_VAL[2]}
|
|
|
|
shift 2 _P9K_CACHE_VAL
|
|
|
|
local -i n=$(($#_P9K_CACHE_VAL / 2))
|
|
|
|
_P9K_LAST_GIT_PROMPT[$VCS_STATUS_WORKDIR]="${(pj:\0:)_P9K_CACHE_VAL[1,$n]}"
|
|
|
|
shift $n _P9K_CACHE_VAL
|
|
|
|
$2_prompt_segment "$id" "$3" "$bg" "$DEFAULT_COLOR" '' 0 '' "${(@)_P9K_CACHE_VAL}"
|
2019-03-06 22:04:06 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-03-21 14:02:41 +00:00
|
|
|
function _p9k_vcs_resume() {
|
2019-03-13 16:04:27 +00:00
|
|
|
emulate -L zsh
|
|
|
|
|
2019-03-06 22:04:06 +00:00
|
|
|
if [[ $VCS_STATUS_RESULT == ok-async ]]; then
|
2019-03-11 17:20:39 +00:00
|
|
|
local latency=$((EPOCHREALTIME - _P9K_GITSTATUS_START_TIME))
|
|
|
|
if (( latency > POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS )); then
|
|
|
|
_P9K_GIT_SLOW[$VCS_STATUS_WORKDIR]=1
|
|
|
|
elif (( latency < 0.8 * POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS )); then # 0.8 to avoid flip-flopping
|
|
|
|
_P9K_GIT_SLOW[$VCS_STATUS_WORKDIR]=0
|
|
|
|
fi
|
2019-03-06 22:04:06 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $_P9K_NEXT_VCS_DIR ]]; then
|
|
|
|
unset _P9K_NEXT_VCS_DIR
|
2019-03-13 17:28:41 +00:00
|
|
|
_p9k_update_prompt gitstatus
|
2019-03-06 22:04:06 +00:00
|
|
|
else
|
|
|
|
typeset -gFH _P9K_GITSTATUS_START_TIME=$EPOCHREALTIME
|
|
|
|
if ! gitstatus_query -d $_P9K_NEXT_VCS_DIR -t 0 -c _p9k_vcs_resume POWERLEVEL9K; then
|
|
|
|
unset _P9K_NEXT_VCS_DIR
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
case $VCS_STATUS_RESULT in
|
|
|
|
*-sync)
|
|
|
|
unset _P9K_NEXT_VCS_DIR
|
2019-03-13 17:28:41 +00:00
|
|
|
_p9k_update_prompt gitstatus
|
2019-03-06 22:04:06 +00:00
|
|
|
;;
|
|
|
|
tout)
|
|
|
|
typeset -gH _P9K_NEXT_VCS_DIR=""
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-03-21 14:02:41 +00:00
|
|
|
function _p9k_vcs_gitstatus() {
|
2019-03-06 22:04:06 +00:00
|
|
|
[[ $POWERLEVEL9K_DISABLE_GITSTATUS == true ]] && return 1
|
2019-03-13 17:28:41 +00:00
|
|
|
if [[ $_P9K_REFRESH_REASON == precmd ]]; then
|
2019-04-30 10:51:34 +00:00
|
|
|
if (( $+_P9K_NEXT_VCS_DIR )); then
|
2019-03-27 09:09:42 +00:00
|
|
|
typeset -gH _P9K_NEXT_VCS_DIR=${${GIT_DIR:a}:-$PWD}
|
2019-03-06 22:04:06 +00:00
|
|
|
else
|
2019-03-27 09:09:42 +00:00
|
|
|
local dir=${${GIT_DIR:a}:-$PWD}
|
2019-03-06 22:04:06 +00:00
|
|
|
local -F timeout=$POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS
|
|
|
|
while true; do
|
|
|
|
case "$_P9K_GIT_SLOW[$dir]" in
|
|
|
|
"") [[ $dir == / ]] && break; dir=${dir:h};;
|
|
|
|
0) break;;
|
|
|
|
1) timeout=0; break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
typeset -gFH _P9K_GITSTATUS_START_TIME=$EPOCHREALTIME
|
2019-03-27 09:09:42 +00:00
|
|
|
gitstatus_query -d ${${GIT_DIR:a}:-$PWD} -t $timeout -c _p9k_vcs_resume POWERLEVEL9K || return 1
|
2019-03-06 22:04:06 +00:00
|
|
|
[[ $VCS_STATUS_RESULT == tout ]] && typeset -gH _P9K_NEXT_VCS_DIR=""
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to show VCS information
|
2019-03-06 22:04:06 +00:00
|
|
|
|
2016-08-11 19:40:05 +00:00
|
|
|
prompt_vcs() {
|
2019-03-13 16:04:27 +00:00
|
|
|
local -a backends=($POWERLEVEL9K_VCS_BACKENDS)
|
2019-03-06 22:04:06 +00:00
|
|
|
if (( ${backends[(I)git]} )) && _p9k_vcs_gitstatus; then
|
|
|
|
_p9k_vcs_render $0 $1 $2 && return
|
|
|
|
backends=(${backends:#git})
|
|
|
|
fi
|
|
|
|
if (( #backends )); then
|
2019-02-27 17:43:21 +00:00
|
|
|
VCS_WORKDIR_DIRTY=false
|
|
|
|
VCS_WORKDIR_HALF_DIRTY=false
|
|
|
|
local current_state=""
|
|
|
|
# Actually invoke vcs_info manually to gather all information.
|
2019-03-06 22:04:06 +00:00
|
|
|
zstyle ':vcs_info:*' enable ${backends}
|
2019-02-27 17:43:21 +00:00
|
|
|
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.
|
|
|
|
current_state='modified'
|
|
|
|
else
|
|
|
|
if [[ "$VCS_WORKDIR_HALF_DIRTY" == true ]]; then
|
|
|
|
current_state='untracked'
|
|
|
|
else
|
|
|
|
current_state='clean'
|
|
|
|
fi
|
|
|
|
fi
|
2019-03-19 16:56:56 +00:00
|
|
|
$1_prompt_segment "${0}_${(U)current_state}" "$2" "${vcs_states[$current_state]}" "$DEFAULT_COLOR" "$vcs_visual_identifier" 0 '' "$vcs_prompt"
|
2019-02-27 17:43:21 +00:00
|
|
|
fi
|
2015-10-23 22:05:15 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2019-05-05 16:33:24 +00:00
|
|
|
# Vi Mode: show editing mode (NORMAL|INSERT|VISUAL)
|
|
|
|
#
|
|
|
|
# VISUAL mode is shown as NORMAL unless POWERLEVEL9K_VI_VISUAL_MODE_STRING is explicitly set.
|
|
|
|
# Your ZSH version must be >= 5.3 if you set this parameter.
|
2015-10-16 18:16:31 +00:00
|
|
|
set_default POWERLEVEL9K_VI_INSERT_MODE_STRING "INSERT"
|
|
|
|
set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL"
|
2015-09-21 16:34:43 +00:00
|
|
|
prompt_vi_mode() {
|
2019-05-05 16:33:24 +00:00
|
|
|
$1_prompt_segment $0_NORMAL $2 "$DEFAULT_COLOR" white '' 0 '${$((!${#${:-$KEYMAP$_P9K_REGION_ACTIVE}:#vicmd0})):#0}' "$POWERLEVEL9K_VI_COMMAND_MODE_STRING"
|
|
|
|
$1_prompt_segment $0_VISUAL $2 "$DEFAULT_COLOR" white '' 0 '${$((!${#${:-$KEYMAP$_P9K_REGION_ACTIVE}:#vicmd1})):#0}' "$POWERLEVEL9K_VI_VISUAL_MODE_STRING"
|
2019-03-16 20:04:41 +00:00
|
|
|
if [[ -n $POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
$1_prompt_segment $0_INSERT $2 "$DEFAULT_COLOR" blue '' 0 '${${KEYMAP:-0}:#vicmd}' "$POWERLEVEL9K_VI_INSERT_MODE_STRING"
|
2019-03-13 17:28:41 +00:00
|
|
|
fi
|
2015-09-21 16:34:43 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2015-04-03 16:15:16 +00:00
|
|
|
# Virtualenv: current working virtualenv
|
|
|
|
# More information on virtualenv (Python):
|
|
|
|
# https://virtualenv.pypa.io/en/latest/
|
|
|
|
prompt_virtualenv() {
|
2019-03-13 16:04:27 +00:00
|
|
|
if [[ -n "$VIRTUAL_ENV" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" 'PYTHON_ICON' 0 '' "${${VIRTUAL_ENV:t}//\%/%%}"
|
2019-03-13 16:04:27 +00:00
|
|
|
fi
|
2015-04-03 16:15:16 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2018-07-11 12:55:27 +00:00
|
|
|
# Segment to display pyenv information
|
2017-11-22 04:30:24 +00:00
|
|
|
# https://github.com/pyenv/pyenv#choosing-the-python-version
|
2018-07-11 12:55:27 +00:00
|
|
|
set_default POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW false
|
2016-05-14 18:00:40 +00:00
|
|
|
prompt_pyenv() {
|
2017-11-22 04:30:24 +00:00
|
|
|
if [[ -n "$PYENV_VERSION" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" 'PYTHON_ICON' 0 '' "${PYENV_VERSION//\%/%%}"
|
2018-07-14 09:09:56 +00:00
|
|
|
elif [ $commands[pyenv] ]; then
|
|
|
|
local pyenv_version_name="$(pyenv version-name)"
|
2018-07-17 20:14:34 +00:00
|
|
|
local pyenv_global="system"
|
|
|
|
local pyenv_root="$(pyenv root)"
|
|
|
|
if [[ -f "${pyenv_root}/version" ]]; then
|
|
|
|
pyenv_global="$(pyenv version-file-read ${pyenv_root}/version)"
|
|
|
|
fi
|
2018-07-14 12:41:15 +00:00
|
|
|
if [[ "${pyenv_version_name}" != "${pyenv_global}" || "${POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" 'PYTHON_ICON' 0 '' "${pyenv_version_name//\%/%%}"
|
2018-07-11 12:55:27 +00:00
|
|
|
fi
|
2015-04-03 16:15:16 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Display openfoam information
|
2017-12-11 21:40:06 +00:00
|
|
|
prompt_openfoam() {
|
|
|
|
local wm_project_version="$WM_PROJECT_VERSION"
|
|
|
|
local wm_fork="$WM_FORK"
|
2019-03-15 13:11:53 +00:00
|
|
|
if [[ -n "$wm_project_version" && -z "$wm_fork" ]] ; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" '' 0 '' "OF: ${${wm_project_version:t}//\%/%%}"
|
2019-03-15 13:11:53 +00:00
|
|
|
elif [[ -n "$wm_project_version" && -n "$wm_fork" ]] ; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" '' 0 '' "F-X: ${${wm_project_version:t}//\%/%%}"
|
2018-01-05 07:04:04 +00:00
|
|
|
fi
|
2017-12-11 21:40:06 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
|
|
|
# Segment to display Swift version
|
2016-12-01 20:21:05 +00:00
|
|
|
prompt_swift_version() {
|
2017-01-22 00:47:58 +00:00
|
|
|
# Get the first number as this is probably the "main" version number..
|
|
|
|
local swift_version=$(swift --version 2>/dev/null | grep -o -E "[0-9.]+" | head -n 1)
|
2016-12-01 20:21:05 +00:00
|
|
|
[[ -z "${swift_version}" ]] && return
|
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "magenta" "white" 'SWIFT_ICON' 0 '' "${swift_version//\%/%%}"
|
2016-12-01 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2017-01-31 22:57:59 +00:00
|
|
|
# dir_writable: Display information about the user's permission to write in the current directory
|
|
|
|
prompt_dir_writable() {
|
2016-08-09 09:22:02 +00:00
|
|
|
if [[ ! -w "$PWD" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0_FORBIDDEN" "$2" "red" "yellow1" 'LOCK_ICON' 0 '' ''
|
2016-08-09 09:22:02 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2017-10-19 01:57:31 +00:00
|
|
|
# Kubernetes Current Context/Namespace
|
2017-05-26 13:02:14 +00:00
|
|
|
prompt_kubecontext() {
|
2017-08-31 18:15:11 +00:00
|
|
|
local kubectl_version="$(kubectl version --client 2>/dev/null)"
|
2017-05-26 13:02:14 +00:00
|
|
|
|
2017-05-26 18:29:06 +00:00
|
|
|
if [[ -n "$kubectl_version" ]]; then
|
2017-10-27 17:55:21 +00:00
|
|
|
# Get the current Kuberenetes context
|
2017-10-19 01:57:31 +00:00
|
|
|
local cur_ctx=$(kubectl config view -o=jsonpath='{.current-context}')
|
|
|
|
cur_namespace="$(kubectl config view -o=jsonpath="{.contexts[?(@.name==\"${cur_ctx}\")].context.namespace}")"
|
|
|
|
# If the namespace comes back empty set it default.
|
|
|
|
if [[ -z "${cur_namespace}" ]]; then
|
|
|
|
cur_namespace="default"
|
|
|
|
fi
|
|
|
|
|
2017-11-14 17:58:16 +00:00
|
|
|
local k8s_final_text=""
|
|
|
|
|
2018-07-09 19:30:28 +00:00
|
|
|
if [[ "$cur_ctx" == "$cur_namespace" ]]; then
|
2017-11-14 17:58:16 +00:00
|
|
|
# No reason to print out the same identificator twice
|
2017-12-05 09:21:31 +00:00
|
|
|
k8s_final_text="$cur_ctx"
|
2017-11-14 17:58:16 +00:00
|
|
|
else
|
2017-12-05 09:21:31 +00:00
|
|
|
k8s_final_text="$cur_ctx/$cur_namespace"
|
2017-11-14 17:58:16 +00:00
|
|
|
fi
|
2017-12-05 00:15:33 +00:00
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "magenta" "white" "KUBERNETES_ICON" 0 '' "${k8s_final_text//\%/%%}"
|
2017-05-26 13:02:14 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:04 +00:00
|
|
|
################################################################
|
2017-10-01 15:53:07 +00:00
|
|
|
# Dropbox status
|
|
|
|
prompt_dropbox() {
|
|
|
|
# The first column is just the directory, so cut it
|
|
|
|
local dropbox_status="$(dropbox-cli filestatus . | cut -d\ -f2-)"
|
|
|
|
|
2017-10-02 12:24:06 +00:00
|
|
|
# Only show if the folder is tracked and dropbox is running
|
|
|
|
if [[ "$dropbox_status" != 'unwatched' && "$dropbox_status" != "isn't running!" ]]; then
|
2017-10-01 15:53:07 +00:00
|
|
|
# If "up to date", only show the icon
|
|
|
|
if [[ "$dropbox_status" =~ 'up to date' ]]; then
|
|
|
|
dropbox_status=""
|
|
|
|
fi
|
|
|
|
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "white" "blue" "DROPBOX_ICON" 0 '' "${dropbox_status//\%/%%}"
|
2017-10-01 15:53:07 +00:00
|
|
|
fi
|
2018-06-06 22:11:15 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 10:04:16 +00:00
|
|
|
# print Java version number
|
|
|
|
prompt_java_version() {
|
|
|
|
local java_version
|
2018-06-20 20:55:14 +00:00
|
|
|
# Stupid: Java prints its version on STDERR.
|
|
|
|
# The first version ouput will print nothing, we just
|
|
|
|
# use it to transport whether the command was successful.
|
|
|
|
# If yes, we parse the version string (and need to
|
|
|
|
# redirect the stderr to stdout to make the pipe work).
|
|
|
|
java_version=$(java -version 2>/dev/null && java -fullversion 2>&1 | cut -d '"' -f 2)
|
2017-10-01 15:53:07 +00:00
|
|
|
|
2018-03-24 10:04:16 +00:00
|
|
|
if [[ -n "$java_version" ]]; then
|
2019-03-19 16:56:56 +00:00
|
|
|
"$1_prompt_segment" "$0" "$2" "red" "white" "JAVA_ICON" 0 '' "${java_version//\%/%%}"
|
2018-03-24 10:04:16 +00:00
|
|
|
fi
|
2017-10-01 15:53:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 16:15:16 +00:00
|
|
|
################################################################
|
|
|
|
# Prompt processing and drawing
|
|
|
|
################################################################
|
2014-12-05 03:26:00 +00:00
|
|
|
# Main prompt
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS context dir vcs
|
2014-12-05 01:26:21 +00:00
|
|
|
build_left_prompt() {
|
2019-03-13 16:04:27 +00:00
|
|
|
local -i index=1
|
2017-10-31 15:47:21 +00:00
|
|
|
local element
|
2015-09-12 19:59:56 +00:00
|
|
|
for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do
|
2016-01-22 18:13:07 +00:00
|
|
|
# Remove joined information in direct calls
|
|
|
|
element=${element%_joined}
|
|
|
|
|
2015-11-18 22:45:22 +00:00
|
|
|
# Check if it is a custom command, otherwise interpet it as
|
|
|
|
# a prompt.
|
2019-03-12 07:29:33 +00:00
|
|
|
if [[ $element == custom_* ]]; then
|
2016-01-22 18:13:07 +00:00
|
|
|
"prompt_custom" "left" "$index" $element[8,-1]
|
2015-11-18 22:45:22 +00:00
|
|
|
else
|
2019-05-05 16:33:24 +00:00
|
|
|
(( $+functions[prompt_$element] )) && "prompt_$element" "left" "$index"
|
2015-11-18 22:45:22 +00:00
|
|
|
fi
|
2016-01-22 18:13:07 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
((++index))
|
2015-03-22 19:10:09 +00:00
|
|
|
done
|
2014-12-05 01:26:21 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 03:26:00 +00:00
|
|
|
# Right prompt
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS status root_indicator background_jobs history time
|
2014-12-05 01:26:21 +00:00
|
|
|
build_right_prompt() {
|
2019-03-13 16:04:27 +00:00
|
|
|
local -i index=1
|
2018-03-26 23:09:41 +00:00
|
|
|
local element
|
2019-03-06 22:04:06 +00:00
|
|
|
|
2015-09-12 19:59:56 +00:00
|
|
|
for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do
|
2016-01-22 18:13:07 +00:00
|
|
|
# Remove joined information in direct calls
|
|
|
|
element=${element%_joined}
|
|
|
|
|
2015-11-18 22:45:22 +00:00
|
|
|
# Check if it is a custom command, otherwise interpet it as
|
|
|
|
# a prompt.
|
2019-03-12 07:29:33 +00:00
|
|
|
if [[ $element == custom_* ]]; then
|
2016-01-22 18:13:07 +00:00
|
|
|
"prompt_custom" "right" "$index" $element[8,-1]
|
2015-11-18 22:45:22 +00:00
|
|
|
else
|
2019-05-05 16:33:24 +00:00
|
|
|
(( $+functions[prompt_$element] )) && "prompt_$element" "right" "$index"
|
2015-11-18 22:45:22 +00:00
|
|
|
fi
|
2016-01-22 18:13:07 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
((++index))
|
2015-03-22 19:10:09 +00:00
|
|
|
done
|
2014-12-05 01:26:21 +00:00
|
|
|
}
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
typeset -gF _P9K_TIMER_START
|
|
|
|
|
|
|
|
powerlevel9k_preexec() { _P9K_TIMER_START=$EPOCHREALTIME }
|
2017-02-12 23:56:32 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
typeset -g _P9K_PROMPT
|
2019-03-13 17:52:22 +00:00
|
|
|
typeset -g _P9K_LEFT_PREFIX
|
|
|
|
typeset -g _P9K_LEFT_SUFFIX
|
|
|
|
typeset -g _P9K_RIGHT_PREFIX
|
|
|
|
typeset -g _P9K_RIGHT_SUFFIX
|
|
|
|
|
|
|
|
set_default POWERLEVEL9K_DISABLE_RPROMPT false
|
2019-03-21 14:02:41 +00:00
|
|
|
function _p9k_set_prompt() {
|
2019-03-16 13:10:19 +00:00
|
|
|
emulate -L zsh
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
_P9K_PROMPT=''
|
2019-03-06 22:04:06 +00:00
|
|
|
build_left_prompt
|
2019-03-13 17:52:22 +00:00
|
|
|
PROMPT=$_P9K_LEFT_PREFIX$_P9K_PROMPT$_P9K_LEFT_SUFFIX
|
2019-02-24 19:16:04 +00:00
|
|
|
|
2019-03-13 17:52:22 +00:00
|
|
|
if [[ $POWERLEVEL9K_DISABLE_RPROMPT == true ]]; then
|
|
|
|
RPROMPT=''
|
2015-09-12 21:46:46 +00:00
|
|
|
else
|
2019-03-13 17:52:22 +00:00
|
|
|
_P9K_PROMPT=''
|
|
|
|
build_right_prompt
|
|
|
|
RPROMPT=$_P9K_RIGHT_PREFIX$_P9K_PROMPT$_P9K_RIGHT_SUFFIX
|
2015-09-12 21:46:46 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-03-13 17:28:41 +00:00
|
|
|
typeset -g _P9K_REFRESH_REASON
|
|
|
|
|
|
|
|
function _p9k_update_prompt() {
|
2019-03-13 16:04:27 +00:00
|
|
|
(( _P9K_ENABLED )) || return
|
2019-03-13 17:28:41 +00:00
|
|
|
_P9K_REFRESH_REASON=$1
|
|
|
|
_p9k_set_prompt
|
|
|
|
_P9K_REFRESH_REASON=''
|
2019-04-25 08:24:53 +00:00
|
|
|
zle && zle .reset-prompt && zle -R
|
2019-03-06 22:04:06 +00:00
|
|
|
}
|
|
|
|
|
2019-05-05 16:33:24 +00:00
|
|
|
typeset -gi _P9K_REGION_ACTIVE
|
|
|
|
|
2019-03-06 22:04:06 +00:00
|
|
|
set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false
|
|
|
|
powerlevel9k_prepare_prompts() {
|
2019-03-13 16:04:27 +00:00
|
|
|
# Do not move these lines down, otherwise the last command is not what you expected it to be.
|
|
|
|
_P9K_EXIT_CODE=$?
|
|
|
|
_P9K_PIPE_EXIT_CODES=( "$pipestatus[@]" )
|
2019-03-06 22:04:06 +00:00
|
|
|
_P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START))
|
2019-03-13 16:04:27 +00:00
|
|
|
|
2019-03-16 13:10:19 +00:00
|
|
|
unsetopt local_options
|
|
|
|
prompt_opts=(cr percent sp subst)
|
|
|
|
setopt nopromptbang prompt{cr,percent,sp,subst}
|
2019-03-13 16:04:27 +00:00
|
|
|
|
|
|
|
_p9k_init
|
|
|
|
_P9K_TIMER_START=1e10
|
2019-05-05 16:33:24 +00:00
|
|
|
_P9K_REGION_ACTIVE=0
|
2019-03-13 17:28:41 +00:00
|
|
|
|
|
|
|
_P9K_REFRESH_REASON=precmd
|
|
|
|
_p9k_set_prompt
|
|
|
|
_P9K_REFRESH_REASON=''
|
2019-03-06 22:04:06 +00:00
|
|
|
}
|
|
|
|
|
2019-03-13 17:28:41 +00:00
|
|
|
function _p9k_zle_keymap_select() {
|
2019-04-25 08:24:53 +00:00
|
|
|
zle && zle .reset-prompt && zle -R
|
2015-09-12 21:46:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 23:41:33 +00:00
|
|
|
set_default POWERLEVEL9K_IGNORE_TERM_COLORS false
|
2017-12-08 00:00:55 +00:00
|
|
|
set_default POWERLEVEL9K_IGNORE_TERM_LANG false
|
2019-03-13 16:04:27 +00:00
|
|
|
set_default POWERLEVEL9K_DISABLE_GITSTATUS false
|
|
|
|
set_default -i POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY -1
|
2018-03-07 01:58:12 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
typeset -g DEFAULT_COLOR
|
|
|
|
typeset -g DEFAULT_COLOR_INVERTED
|
|
|
|
typeset -gi _P9K_INITIALIZED=0
|
2017-04-12 19:38:43 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
typeset -g OS
|
|
|
|
typeset -g OS_ICON
|
|
|
|
typeset -g SED_EXTENDED_REGEX_PARAMETER
|
2017-02-12 23:56:32 +00:00
|
|
|
|
2019-03-17 13:01:30 +00:00
|
|
|
typeset -g _P9K_TIMER_FIFO
|
2019-03-17 07:46:33 +00:00
|
|
|
typeset -gi _P9K_TIMER_FD=0
|
2019-03-17 13:01:30 +00:00
|
|
|
typeset -gi _P9K_TIMER_PID=0
|
2019-03-22 11:39:59 +00:00
|
|
|
typeset -gi _P9K_TIMER_SUBSHELL=0
|
2019-03-14 12:17:50 +00:00
|
|
|
|
|
|
|
_p9k_init_timer() {
|
|
|
|
_p9k_start_timer() {
|
|
|
|
emulate -L zsh
|
|
|
|
setopt err_return no_bg_nice
|
|
|
|
|
2019-03-17 13:01:30 +00:00
|
|
|
_P9K_TIMER_FIFO=$(mktemp -u "${TMPDIR:-/tmp}"/p9k.$$.timer.pipe.XXXXXXXXXX)
|
|
|
|
mkfifo $_P9K_TIMER_FIFO
|
|
|
|
sysopen -rw -o cloexec,sync -u _P9K_TIMER_FD $_P9K_TIMER_FIFO
|
|
|
|
zsystem flock $_P9K_TIMER_FIFO
|
2019-03-14 12:17:50 +00:00
|
|
|
|
|
|
|
function _p9k_on_timer() {
|
|
|
|
emulate -L zsh
|
2019-03-17 13:01:30 +00:00
|
|
|
local dummy
|
|
|
|
while IFS='' read -t -u $_P9K_TIMER_FD dummy; do true; done
|
2019-04-25 08:24:53 +00:00
|
|
|
zle && zle .reset-prompt && zle -R
|
2019-03-14 12:17:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-17 07:46:33 +00:00
|
|
|
zle -F $_P9K_TIMER_FD _p9k_on_timer
|
|
|
|
|
|
|
|
# `kill -WINCH $$` 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).
|
2019-03-17 13:01:30 +00:00
|
|
|
zsh -c "
|
|
|
|
zmodload zsh/system
|
|
|
|
while sleep 1 && ! zsystem flock -t 0 ${(q)_P9K_TIMER_FIFO} && kill -WINCH $$ && echo; do
|
|
|
|
true
|
|
|
|
done
|
|
|
|
command rm -f ${(q)_P9K_TIMER_FIFO}
|
|
|
|
" </dev/null >&$_P9K_TIMER_FD 2>/dev/null &!
|
|
|
|
|
|
|
|
_P9K_TIMER_PID=$!
|
2019-03-22 11:39:59 +00:00
|
|
|
_P9K_TIMER_SUBSHELL=$ZSH_SUBSHELL
|
2019-03-17 13:01:30 +00:00
|
|
|
|
|
|
|
function _p9k_kill_timer() {
|
2019-03-15 18:14:10 +00:00
|
|
|
emulate -L zsh
|
2019-03-22 11:39:59 +00:00
|
|
|
if (( ZSH_SUBSHELL == _P9K_TIMER_SUBSHELL )); then
|
|
|
|
(( _P9K_TIMER_PID )) && kill -- -$_P9K_TIMER_PID &>/dev/null
|
|
|
|
command rm -f $_P9K_TIMER_FIFO
|
|
|
|
fi
|
2019-03-15 18:14:10 +00:00
|
|
|
}
|
2019-03-17 13:01:30 +00:00
|
|
|
add-zsh-hook zshexit _p9k_kill_timer
|
2019-03-14 12:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ! _p9k_start_timer ; then
|
|
|
|
echo "powerlevel10k: failed to initialize background timer" >&2
|
2019-03-17 07:46:33 +00:00
|
|
|
if (( _P9K_TIMER_FD )); then
|
|
|
|
zle -F $_P9K_TIMER_FD
|
|
|
|
exec {_P9K_TIMER_FD}>&-
|
|
|
|
_P9K_TIMER_FD=0
|
2019-03-14 12:17:50 +00:00
|
|
|
fi
|
2019-03-17 13:01:30 +00:00
|
|
|
if (( _P9K_TIMER_PID )); then
|
|
|
|
kill -- -$_P9K_TIMER_PID &>/dev/null
|
|
|
|
_P9K_TIMER_PID=0
|
|
|
|
fi
|
|
|
|
command rm -f $_P9K_TIMER_FIFO
|
|
|
|
_P9K_TIMER_FIFO=''
|
2019-03-14 12:17:50 +00:00
|
|
|
unset -f _p9k_on_timer
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-03-18 16:24:56 +00:00
|
|
|
# Some people write POWERLEVEL9K_DIR_PATH_SEPARATOR='\uNNNN' instead of
|
|
|
|
# POWERLEVEL9K_DIR_PATH_SEPARATOR=$'\uNNNN'. There is no good reason for it and if we were
|
|
|
|
# starting from scratch we wouldn't perform automatic conversion from the former to the latter.
|
|
|
|
# But we aren't starting from scratch, so convert we do.
|
|
|
|
_p9k_init_strings() {
|
|
|
|
# To find candidates:
|
|
|
|
#
|
|
|
|
# egrep 'set_default [^-]' powerlevel9k.zsh-theme | egrep -v '(true|false)$'
|
|
|
|
_p9k_g_expand POWERLEVEL9K_ANACONDA_LEFT_DELIMITER
|
|
|
|
_p9k_g_expand POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER
|
|
|
|
_p9k_g_expand POWERLEVEL9K_CONTEXT_TEMPLATE
|
|
|
|
_p9k_g_expand POWERLEVEL9K_DATE_FORMAT
|
|
|
|
_p9k_g_expand POWERLEVEL9K_DIR_PATH_SEPARATOR
|
|
|
|
_p9k_g_expand POWERLEVEL9K_HOME_FOLDER_ABBREVIATION
|
|
|
|
_p9k_g_expand POWERLEVEL9K_HOST_TEMPLATE
|
|
|
|
_p9k_g_expand POWERLEVEL9K_SHORTEN_DELIMITER
|
|
|
|
_p9k_g_expand POWERLEVEL9K_TIME_FORMAT
|
|
|
|
_p9k_g_expand POWERLEVEL9K_USER_TEMPLATE
|
2019-03-20 13:47:29 +00:00
|
|
|
_p9k_g_expand POWERLEVEL9K_VCS_LOADING_TEXT
|
2019-03-18 16:24:56 +00:00
|
|
|
_p9k_g_expand POWERLEVEL9K_VI_COMMAND_MODE_STRING
|
|
|
|
_p9k_g_expand POWERLEVEL9K_VI_INSERT_MODE_STRING
|
|
|
|
_p9k_g_expand POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS
|
|
|
|
_p9k_g_expand POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS
|
|
|
|
}
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
_p9k_init() {
|
|
|
|
(( _P9K_INITIALIZED )) && return
|
2017-04-20 00:40:41 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
_p9k_init_icons
|
2019-03-18 16:24:56 +00:00
|
|
|
_p9k_init_strings
|
2017-04-20 00:40:41 +00:00
|
|
|
|
2019-03-21 14:02:41 +00:00
|
|
|
function _$0_set_os() {
|
2019-03-13 16:04:27 +00:00
|
|
|
OS=$1
|
|
|
|
_p9k_get_icon $2
|
|
|
|
OS_ICON=$_P9K_RETVAL
|
|
|
|
}
|
2015-09-04 15:20:00 +00:00
|
|
|
|
2019-03-21 14:02:41 +00:00
|
|
|
trap "unfunction _$0_set_os" EXIT
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
if [[ $(uname -o 2>/dev/null) == Android ]]; then
|
2019-03-21 14:02:41 +00:00
|
|
|
_$0_set_os Android ANDROID_ICON
|
2019-03-13 16:04:27 +00:00
|
|
|
else
|
|
|
|
case $(uname) in
|
2019-03-21 14:02:41 +00:00
|
|
|
SunOS) _$0_set_os Solaris SUNOS_ICON;;
|
|
|
|
Darwin) _$0_set_os OSX APPLE_ICON;;
|
|
|
|
CYGWIN_NT-* | MSYS_NT-*) _$0_set_os Windows WINDOWS_ICON;;
|
|
|
|
FreeBSD|OpenBSD|DragonFly) _$0_set_os BSD FREEBSD_ICON;;
|
2019-03-13 16:04:27 +00:00
|
|
|
Linux)
|
|
|
|
OS='Linux'
|
|
|
|
local os_release_id
|
|
|
|
[[ -f /etc/os-release &&
|
2019-03-14 17:00:10 +00:00
|
|
|
"${(f)$((</etc/os-release) 2>/dev/null)}" =~ "ID=([A-Za-z]+)" ]] && os_release_id="${match[1]}"
|
2019-03-13 16:04:27 +00:00
|
|
|
case "$os_release_id" in
|
2019-03-21 14:02:41 +00:00
|
|
|
*arch*) _$0_set_os Linux LINUX_ARCH_ICON;;
|
|
|
|
*debian*) _$0_set_os Linux LINUX_DEBIAN_ICON;;
|
2019-04-05 15:35:01 +00:00
|
|
|
*raspbian*) _$0_set_os Linux LINUX_RASPBIAN_ICON;;
|
2019-03-21 14:02:41 +00:00
|
|
|
*ubuntu*) _$0_set_os Linux LINUX_UBUNTU_ICON;;
|
|
|
|
*elementary*) _$0_set_os Linux LINUX_ELEMENTARY_ICON;;
|
|
|
|
*fedora*) _$0_set_os Linux LINUX_FEDORA_ICON;;
|
|
|
|
*coreos*) _$0_set_os Linux LINUX_COREOS_ICON;;
|
|
|
|
*gentoo*) _$0_set_os Linux LINUX_GENTOO_ICON;;
|
|
|
|
*mageia*) _$0_set_os Linux LINUX_MAGEIA_ICON;;
|
|
|
|
*centos*) _$0_set_os Linux LINUX_CENTOS_ICON;;
|
|
|
|
*opensuse*|*tumbleweed*) _$0_set_os Linux LINUX_OPENSUSE_ICON;;
|
|
|
|
*sabayon*) _$0_set_os Linux LINUX_SABAYON_ICON;;
|
|
|
|
*slackware*) _$0_set_os Linux LINUX_SLACKWARE_ICON;;
|
|
|
|
*linuxmint*) _$0_set_os Linux LINUX_MINT_ICON;;
|
|
|
|
*alpine*) _$0_set_os Linux LINUX_ALPINE_ICON;;
|
|
|
|
*aosc*) _$0_set_os Linux LINUX_AOSC_ICON;;
|
|
|
|
*nixos*) _$0_set_os Linux LINUX_NIXOS_ICON;;
|
|
|
|
*devuan*) _$0_set_os Linux LINUX_DEVUAN_ICON;;
|
|
|
|
*manjaro*) _$0_set_os Linux LINUX_MANJARO_ICON;;
|
|
|
|
*) _$0_set_os Linux LINUX_ICON;;
|
2019-03-13 16:04:27 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
2016-07-07 17:51:26 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
if [[ $POWERLEVEL9K_COLOR_SCHEME == light ]]; then
|
|
|
|
DEFAULT_COLOR=white
|
|
|
|
DEFAULT_COLOR_INVERTED=black
|
|
|
|
else
|
|
|
|
DEFAULT_COLOR=black
|
|
|
|
DEFAULT_COLOR_INVERTED=white
|
2016-08-11 19:40:05 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
local i
|
|
|
|
for ((i = 2; i <= $#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS; ++i)); do
|
|
|
|
local elem=$POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[$i]
|
|
|
|
if [[ $elem == *_joined ]]; then
|
|
|
|
_P9K_LEFT_JOIN+=$_P9K_LEFT_JOIN[((i-1))]
|
|
|
|
else
|
|
|
|
_P9K_LEFT_JOIN+=$i
|
|
|
|
fi
|
|
|
|
done
|
2017-02-14 20:32:41 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
for ((i = 2; i <= $#POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS; ++i)); do
|
|
|
|
local elem=$POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[$i]
|
|
|
|
if [[ $elem == *_joined ]]; then
|
|
|
|
_P9K_RIGHT_JOIN+=$_P9K_RIGHT_JOIN[((i-1))]
|
|
|
|
else
|
|
|
|
_P9K_RIGHT_JOIN+=$i
|
|
|
|
fi
|
|
|
|
done
|
2015-05-27 19:03:02 +00:00
|
|
|
|
2019-03-16 20:04:41 +00:00
|
|
|
if [[ $POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME == true ]]; then
|
2019-03-14 12:17:50 +00:00
|
|
|
_p9k_init_timer
|
|
|
|
fi
|
|
|
|
|
2019-03-16 20:04:41 +00:00
|
|
|
_P9K_LEFT_PREFIX+='${${_P9K_BG::=NONE}+}${${_P9K_I::=0}+}'
|
|
|
|
_P9K_RIGHT_PREFIX+='${${_P9K_BG::=NONE}+}${${_P9K_I::=0}+}'
|
|
|
|
|
|
|
|
_p9k_get_icon LEFT_SEGMENT_SEPARATOR
|
2019-05-10 08:45:52 +00:00
|
|
|
_P9K_T=("%f$_P9K_RETVAL" "")
|
|
|
|
_P9K_PROMPT=''
|
|
|
|
_p9k_left_prompt_end_line
|
|
|
|
_P9K_LEFT_SUFFIX=$_P9K_PROMPT
|
|
|
|
_P9K_PROMPT=''
|
2019-03-16 20:04:41 +00:00
|
|
|
_p9k_get_icon LEFT_SEGMENT_END_SEPARATOR
|
|
|
|
_P9K_LEFT_SUFFIX+=$_P9K_RETVAL
|
|
|
|
|
2019-05-14 10:40:55 +00:00
|
|
|
_P9K_RIGHT_SUFFIX+='%f%b%k'
|
|
|
|
_P9K_RIGHT_PREFIX+='%f%b%k'
|
2019-03-16 20:04:41 +00:00
|
|
|
|
2019-03-13 17:52:22 +00:00
|
|
|
if [[ $POWERLEVEL9K_PROMPT_ON_NEWLINE == true ]]; then
|
|
|
|
_p9k_get_icon MULTILINE_FIRST_PROMPT_PREFIX
|
2019-03-15 16:00:14 +00:00
|
|
|
_P9K_LEFT_PREFIX+="$_P9K_RETVAL%f%b%k"
|
2019-03-13 17:52:22 +00:00
|
|
|
_p9k_get_icon MULTILINE_LAST_PROMPT_PREFIX
|
2019-03-15 16:00:14 +00:00
|
|
|
_P9K_LEFT_SUFFIX+=$'\n'$_P9K_RETVAL
|
2019-03-13 17:52:22 +00:00
|
|
|
if [[ $POWERLEVEL9K_RPROMPT_ON_NEWLINE != true ]]; then
|
|
|
|
# The right prompt should be on the same line as the first line of the left
|
|
|
|
# prompt. To do so, there is just a quite ugly workaround: Before zsh draws
|
|
|
|
# the RPROMPT, we advise it, to go one line up. At the end of RPROMPT, we
|
|
|
|
# advise it to go one line down. See:
|
|
|
|
# http://superuser.com/questions/357107/zsh-right-justify-in-ps1
|
|
|
|
local LC_ALL="" LC_CTYPE="en_US.UTF-8" # Set the right locale to protect special characters
|
2019-03-15 16:00:14 +00:00
|
|
|
_P9K_RIGHT_PREFIX+='%{'$'\e[1A''%}' # one line up
|
|
|
|
_P9K_RIGHT_SUFFIX+='%{'$'\e[1B''%}' # one line down
|
2019-03-13 17:52:22 +00:00
|
|
|
fi
|
|
|
|
else
|
2019-03-15 16:00:14 +00:00
|
|
|
_P9K_LEFT_PREFIX+="%f%b%k"
|
2019-03-13 17:52:22 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $POWERLEVEL9K_PROMPT_ADD_NEWLINE == true ]]; then
|
|
|
|
repeat ${POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT:-1} { _P9K_LEFT_PREFIX=$'\n'$_P9K_LEFT_PREFIX }
|
|
|
|
fi
|
|
|
|
|
2019-03-15 16:00:14 +00:00
|
|
|
if [[ $ITERM_SHELL_INTEGRATION_INSTALLED == Yes ]]; then
|
|
|
|
_P9K_LEFT_PREFIX="%{$(iterm2_prompt_mark)%}$_P9K_LEFT_PREFIX"
|
|
|
|
fi
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
# If the terminal `LANG` is set to `C`, this theme will not work at all.
|
2019-05-17 22:25:14 +00:00
|
|
|
if [[ $LANG == "C" && $POWERLEVEL9K_IGNORE_TERM_LANG == false ]]; then
|
2019-03-13 16:04:27 +00:00
|
|
|
print -P "\t%F{red}WARNING!%f Your terminal's 'LANG' is set to 'C', which breaks this theme!"
|
|
|
|
print -P "\t%F{red}WARNING!%f Please set your 'LANG' to a UTF-8 language, like 'en_US.UTF-8'"
|
|
|
|
print -P "\t%F{red}WARNING!%f _before_ loading this theme in your \~\.zshrc. Putting"
|
|
|
|
print -P "\t%F{red}WARNING!%f %F{blue}export LANG=\"en_US.UTF-8\"%f at the top of your \~\/.zshrc is sufficient."
|
|
|
|
print -P 'Set POWERLEVEL9K_IGNORE_TERM_LANG=true to suppress this warning.'
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Display a warning if the terminal does not support 256 colors.
|
|
|
|
if [[ $POWERLEVEL9K_IGNORE_TERM_COLORS == false ]]; then
|
2019-05-08 09:31:16 +00:00
|
|
|
if zmodload zsh/terminfo 2>/dev/null && (( $+terminfo[colors] && $terminfo[colors] < 256 )); then
|
|
|
|
print -P '%F{red}WARNING!%f Your terminal appears to support fewer than 256 colors!'
|
|
|
|
print -P 'If your terminal supports 256 colors, please export the appropriate environment variable.'
|
|
|
|
print -P 'In most terminal emulators, adding %F{blue}export TERM=xterm-256color%f to your %F{yellow}~/.zshrc%f is sufficient.'
|
|
|
|
print -P 'Set %F{blue}POWERLEVEL9K_IGNORE_TERM_COLORS=true%f to suppress this warning.'
|
2019-03-13 16:04:27 +00:00
|
|
|
fi
|
|
|
|
fi
|
2018-02-07 22:56:48 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
if segment_in_use longstatus; then
|
2019-05-08 10:48:11 +00:00
|
|
|
print -P '%F{yellow}WARNING!%f The "longstatus" segment is deprecated. Use "%F{blue}status%f" instead.'
|
2019-03-13 16:04:27 +00:00
|
|
|
print -P 'For more informations, have a look at https://github.com/bhilburn/powerlevel9k/blob/master/CHANGELOG.md.'
|
|
|
|
fi
|
2019-03-06 22:04:06 +00:00
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
if segment_in_use vcs; then
|
|
|
|
powerlevel9k_vcs_init
|
|
|
|
if [[ $POWERLEVEL9K_DISABLE_GITSTATUS != true ]] && (( ${POWERLEVEL9K_VCS_BACKENDS[(I)git]} )); then
|
|
|
|
source ${POWERLEVEL9K_GITSTATUS_DIR:-${_P9K_INSTALLATION_DIR}/gitstatus}/gitstatus.plugin.zsh
|
|
|
|
gitstatus_start -m $POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY POWERLEVEL9K
|
|
|
|
fi
|
|
|
|
fi
|
2019-03-08 13:24:42 +00:00
|
|
|
|
2019-05-05 16:33:24 +00:00
|
|
|
if segment_in_use vi_mode && (( $+POWERLEVEL9K_VI_VISUAL_MODE_STRING )); then
|
|
|
|
if is-at-least 5.3; then
|
|
|
|
function _p9k_zle_line_pre_redraw() {
|
|
|
|
[[ $KEYMAP == vicmd ]] &&
|
|
|
|
[[ ${REGION_ACTIVE:-0} != $_P9K_REGION_ACTIVE ]] &&
|
|
|
|
_P9K_REGION_ACTIVE=${REGION_ACTIVE:-0} &&
|
|
|
|
zle && zle .reset-prompt && zle -R
|
|
|
|
}
|
|
|
|
autoload -Uz add-zle-hook-widget
|
|
|
|
add-zle-hook-widget line-pre-redraw _p9k_zle_line_pre_redraw
|
|
|
|
_p9k_g_expand POWERLEVEL9K_VI_VISUAL_MODE_STRING
|
|
|
|
else
|
2019-05-08 10:48:11 +00:00
|
|
|
>&2 print -P '%F{yellow}WARNING!%f POWERLEVEL9K_VI_VISUAL_MODE_STRING requires ZSH >= 5.3.'
|
2019-05-05 16:33:24 +00:00
|
|
|
>&2 print -r "Your zsh version is $ZSH_VERSION. Either upgrade zsh or unset POWERLEVEL9K_VI_VISUAL_MODE_STRING."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-05-18 21:50:06 +00:00
|
|
|
if segment_in_use dir &&
|
|
|
|
[[ $POWERLEVEL9K_SHORTEN_STRATEGY == truncate_with_package_name && $+commands[jq] == 0 ]]; then
|
|
|
|
>&2 print -P '%F{yellow}WARNING!%f %BPOWERLEVEL9K_SHORTEN_STRATEGY=truncate_with_package_name%b requires %F{green}jq%f.'
|
|
|
|
>&2 print -P 'Either install %F{green}jq%f or change the value of %BPOWERLEVEL9K_SHORTEN_STRATEGY%b.'
|
|
|
|
fi
|
|
|
|
|
2019-03-13 17:28:41 +00:00
|
|
|
zle -N zle-keymap-select _p9k_zle_keymap_select
|
|
|
|
|
2019-03-13 16:04:27 +00:00
|
|
|
_P9K_INITIALIZED=1
|
|
|
|
}
|
|
|
|
|
|
|
|
typeset -gi _P9K_ENABLED=0
|
|
|
|
|
|
|
|
prompt_powerlevel9k_setup() {
|
|
|
|
prompt_powerlevel9k_teardown
|
|
|
|
|
|
|
|
add-zsh-hook precmd powerlevel9k_prepare_prompts
|
|
|
|
add-zsh-hook preexec powerlevel9k_preexec
|
|
|
|
|
|
|
|
_P9K_TIMER_START=1e10
|
|
|
|
_P9K_ENABLED=1
|
2015-03-29 16:06:57 +00:00
|
|
|
}
|
2015-01-26 04:52:25 +00:00
|
|
|
|
2017-05-04 06:20:29 +00:00
|
|
|
prompt_powerlevel9k_teardown() {
|
|
|
|
add-zsh-hook -D precmd powerlevel9k_\*
|
|
|
|
add-zsh-hook -D preexec powerlevel9k_\*
|
2017-05-13 01:30:42 +00:00
|
|
|
PROMPT='%m%# '
|
2017-05-23 01:20:56 +00:00
|
|
|
RPROMPT=
|
2019-03-13 16:04:27 +00:00
|
|
|
_P9K_ENABLED=0
|
2017-05-04 06:20:29 +00:00
|
|
|
}
|
|
|
|
|
2019-03-13 19:21:43 +00:00
|
|
|
autoload -U colors && colors
|
|
|
|
autoload -Uz add-zsh-hook
|
|
|
|
|
|
|
|
zmodload zsh/datetime
|
|
|
|
zmodload zsh/mathfunc
|
2019-03-17 13:01:30 +00:00
|
|
|
zmodload zsh/system
|
2019-05-21 10:26:34 +00:00
|
|
|
zmodload -F zsh/stat b:zstat
|
2019-03-13 19:21:43 +00:00
|
|
|
|
2017-01-19 21:48:57 +00:00
|
|
|
prompt_powerlevel9k_setup "$@"
|