summaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme161
1 files changed, 96 insertions, 65 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 3f25d195..d5b3ef75 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -127,8 +127,8 @@ left_prompt_segment() {
[[ -n $FG_COLOR_MODIFIER ]] && 4="$FG_COLOR_MODIFIER"
local bg fg
- [[ -n "$3" ]] && bg="%K{$3}" || bg="%k"
- [[ -n "$4" ]] && fg="%F{$4}" || fg="%f"
+ [[ -n "$3" ]] && bg="$(backgroundColor $3)" || bg="$(backgroundColor)"
+ [[ -n "$4" ]] && fg="$(foregroundColor $4)" || fg="$(foregroundColor)"
if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "$3" "$CURRENT_BG"; then
echo -n "$bg%F{$CURRENT_BG}"
@@ -142,8 +142,8 @@ left_prompt_segment() {
# subsegment (or the default color). This should have
# enough contrast.
local complement
- [[ -n "$4" ]] && complement="$4" || complement=$DEFAULT_COLOR
- echo -n "$bg%F{$complement}"
+ [[ -n "$4" ]] && complement="$fg" || complement="$(foregroundColor $DEFAULT_COLOR)"
+ echo -n "${bg}${complement}"
if [[ $joined == false ]]; then
echo -n "$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS"
fi
@@ -218,8 +218,8 @@ right_prompt_segment() {
[[ -n $FG_COLOR_MODIFIER ]] && 4="$FG_COLOR_MODIFIER"
local bg fg
- [[ -n "$3" ]] && bg="%K{$3}" || bg="%k"
- [[ -n "$4" ]] && fg="%F{$4}" || fg="%f"
+ [[ -n "$3" ]] && bg="$(backgroundColor $3)" || bg="$(backgroundColor)"
+ [[ -n "$4" ]] && fg="$(foregroundColor $4)" || fg="$(foregroundColor)"
# If CURRENT_RIGHT_BG is "NONE", we are the first right segment.
if [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]]; then
@@ -229,10 +229,11 @@ right_prompt_segment() {
# subsegment (or the default color). This should have
# enough contrast.
local complement
- [[ -n "$4" ]] && complement="$4" || complement=$DEFAULT_COLOR
- echo -n "%F{$complement}$(print_icon 'RIGHT_SUBSEGMENT_SEPARATOR')%f"
+ [[ -n "$4" ]] && complement="$fg" || complement="$(foregroundColor $DEFAULT_COLOR)"
+ echo -n "$complement$(print_icon 'RIGHT_SUBSEGMENT_SEPARATOR')%f"
else
- echo -n "%F{$3}$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f"
+ # Use the new BG color for the foreground with separator
+ echo -n "$(foregroundColor $3)$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f"
fi
fi
@@ -305,6 +306,7 @@ prompt_aws_eb_env() {
# Segment to indicate background jobs with an icon.
set_default POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE true
+set_default POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS false
prompt_background_jobs() {
local background_jobs_number=${$(jobs -l | wc -l)// /}
local wrong_lines=`jobs -l | awk '/pwd now/{ count++ } END {print count}'`
@@ -313,7 +315,7 @@ prompt_background_jobs() {
fi
if [[ background_jobs_number -gt 0 ]]; then
local background_jobs_number_print=""
- if [[ "$POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE" == "true" ]] && [[ "$background_jobs_number" -gt 1 ]]; then
+ if [[ "$POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE" == "true" ]] && ([[ "$background_jobs_number" -gt 1 ]] || [[ "$POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS" == "true" ]]); then
background_jobs_number_print="$background_jobs_number"
fi
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "cyan" "$background_jobs_number_print" 'BACKGROUND_JOBS_ICON'
@@ -578,25 +580,26 @@ prompt_context() {
typeset -AH context_states
context_states=(
"ROOT" "yellow"
- "DEFAULT" "011"
+ "DEFAULT" "yellow"
+ "REMOTE" "yellow"
)
local content=""
if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
-
- if [[ $(print -P "%#") == '#' ]]; then
- current_state="ROOT"
- fi
-
content="${POWERLEVEL9K_CONTEXT_TEMPLATE}"
-
elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then
content="$(whoami)"
else
return
fi
+ if [[ $(print -P "%#") == '#' ]]; then
+ current_state="ROOT"
+ elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
+ current_state="REMOTE"
+ fi
+
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}"
}
@@ -621,7 +624,7 @@ prompt_user() {
"STATE" "DEFAULT"
"CONTENT" "$(whoami)"
"BACKGROUND_COLOR" "${DEFAULT_COLOR}"
- "FOREGROUND_COLOR" "011"
+ "FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "USER_ICON"
)
fi
@@ -648,7 +651,7 @@ prompt_host() {
"STATE" "LOCAL"
"CONTENT" "${POWERLEVEL9K_HOST_TEMPLATE}"
"BACKGROUND_COLOR" "${DEFAULT_COLOR}"
- "FOREGROUND_COLOR" "011"
+ "FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "HOST_ICON"
)
fi
@@ -695,7 +698,7 @@ prompt_command_execution_time() {
fi
if (( _P9K_COMMAND_DURATION >= POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )); then
- "$1_prompt_segment" "$0" "$2" "red" "226" "${humanReadableDuration}" 'EXECUTION_TIME_ICON'
+ "$1_prompt_segment" "$0" "$2" "red" "yellow1" "${humanReadableDuration}" 'EXECUTION_TIME_ICON'
fi
}
@@ -704,16 +707,19 @@ set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/"
set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~"
set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false
prompt_dir() {
+ local tmp="$IFS"
+ local IFS=""
local current_path=$(pwd | sed -e "s,^$HOME,~,")
+ local IFS="$tmp"
if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then
set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026'
case "$POWERLEVEL9K_SHORTEN_STRATEGY" in
truncate_middle)
- current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g")
+ current_path=$(echo "$current_path" | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g")
;;
truncate_from_right)
- current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" )
+ current_path=$(truncatePathFromRight "$current_path" )
;;
truncate_with_package_name)
local name repo_path package_path current_dir zero
@@ -763,8 +769,12 @@ prompt_dir() {
# Instead of printing out the full path, print out the name of the package
# from the package.json and append the current subdirectory
current_path="`echo $packageName | tr -d '"'`$subdirectory_path"
+ if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then
+ # add space before the packageName to allow for removing the "first" character, without messing up the package name.
+ current_path=" ${current_path}"
+ fi
else
- current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" )
+ current_path=$(truncatePathFromRight "$current_path" )
fi
;;
truncate_with_folder_marker)
@@ -867,13 +877,13 @@ prompt_go_version() {
go_path=$(go env GOPATH 2>/dev/null)
if [[ -n "$go_version" && "${PWD##$go_path}" != "$PWD" ]]; then
- "$1_prompt_segment" "$0" "$2" "green" "255" "$go_version" "GO_ICON"
+ "$1_prompt_segment" "$0" "$2" "green" "grey93" "$go_version" "GO_ICON"
fi
}
# Command number (in local history)
prompt_history() {
- "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" '%h'
+ "$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" '%h'
}
# Detection for virtualization (systemd based systems only)
@@ -1035,7 +1045,7 @@ prompt_nodeenv() {
# print a little OS icon
prompt_os_icon() {
- "$1_prompt_segment" "$0" "$2" "black" "255" "$OS_ICON"
+ "$1_prompt_segment" "$0" "$2" "black" "white" "$OS_ICON"
}
# print PHP version number
@@ -1044,7 +1054,7 @@ prompt_php_version() {
php_version=$(php -v 2>&1 | grep -oe "^PHP\s*[0-9.]*")
if [[ -n "$php_version" ]]; then
- "$1_prompt_segment" "$0" "$2" "013" "255" "$php_version"
+ "$1_prompt_segment" "$0" "$2" "fuchsia" "grey93" "$php_version"
fi
}
@@ -1072,17 +1082,17 @@ prompt_ram() {
}
# rbenv information
+set_default POWERLEVEL9K_RBENV_ALWAYS false
prompt_rbenv() {
if which rbenv 2>/dev/null >&2; then
local rbenv_version_name="$(rbenv version-name)"
local rbenv_global="$(rbenv global)"
- # Don't show anything if the current Ruby is the same as the global Ruby.
- if [[ $rbenv_version_name == $rbenv_global ]]; then
- return
+ # Don't show anything if the current Ruby is the same as the global Ruby
+ # unless `POWERLEVEL9K_RBENV_ALWAYS` is set.
+ if [[ $POWERLEVEL9K_RBENV_ALWAYS == true || $rbenv_version_name != $rbenv_global ]];then
+ "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$rbenv_version_name" 'RUBY_ICON'
fi
-
- "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$rbenv_version_name" 'RUBY_ICON'
fi
}
@@ -1110,7 +1120,7 @@ prompt_rust_version() {
rust_version=$(rustc --version 2>&1 | grep -oe "^rustc\s*[^ ]*" | grep -o '[0-9.a-z\\\-]*$')
if [[ -n "$rust_version" ]]; then
- "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "Rust $rust_version" 'RUST_ICON'
+ "$1_prompt_segment" "$0" "$2" "darkorange" "$DEFAULT_COLOR" "Rust $rust_version" 'RUST_ICON'
fi
}
# RSpec test ratio
@@ -1129,7 +1139,7 @@ prompt_rvm() {
local version_and_gemset=${rvm_env_string/ruby-}
if [[ -n "$version_and_gemset" ]]; then
- "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON'
+ "$1_prompt_segment" "$0" "$2" "grey35" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON'
fi
}
@@ -1159,7 +1169,7 @@ exit_code_or_status() {
else
local sig=$(( ec - 128 ))
local idx=$(( sig + 1 ))
- echo "${signals[$idx]}(-${sig})"
+ echo "SIG${signals[$idx]}(${sig})"
fi
}
@@ -1185,7 +1195,7 @@ prompt_status() {
if (( ec_sum > 0 )); then
if [[ "$POWERLEVEL9K_STATUS_CROSS" == false && "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then
- "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$ec_text" 'CARRIAGE_RETURN_ICON'
+ "$1_prompt_segment" "$0_ERROR" "$2" "red" "yellow1" "$ec_text" 'CARRIAGE_RETURN_ICON'
else
"$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON'
fi
@@ -1234,7 +1244,7 @@ prompt_symfony2_version() {
if [[ -f app/bootstrap.php.cache ]]; then
local symfony2_version
symfony2_version=$(grep " VERSION " app/bootstrap.php.cache | sed -e 's/[^.0-9]*//g')
- "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$symfony2_version" 'SYMFONY_ICON'
+ "$1_prompt_segment" "$0" "$2" "grey35" "$DEFAULT_COLOR" "$symfony2_version" 'SYMFONY_ICON'
fi
}
@@ -1268,7 +1278,7 @@ 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
- "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" "$count" 'TODO_ICON'
+ "$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" "$count" 'TODO_ICON'
fi
fi
}
@@ -1388,21 +1398,23 @@ prompt_virtualenv() {
}
# pyenv: current active python version (with restrictions)
-# More information on pyenv (Python version manager like rbenv and rvm):
-# https://github.com/yyuu/pyenv
-# the prompt parses output of pyenv version and only displays the first word
+# https://github.com/pyenv/pyenv#choosing-the-python-version
prompt_pyenv() {
- local pyenv_version="$(pyenv version 2>/dev/null)"
- pyenv_version="${pyenv_version%% *}"
- # XXX: The following should return the same as above.
- # This reads better for devs familiar with sed/awk/grep/cut utilities
- # Using shell expansion/substitution may hamper future maintainability
- #local pyenv_version="$(pyenv version 2>/dev/null | head -n1 | cut -d' ' -f1)"
- if [[ -n "$pyenv_version" && "$pyenv_version" != "system" ]]; then
- "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$pyenv_version" 'PYTHON_ICON'
+ if [[ -n "$PYENV_VERSION" ]]; then
+ "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$PYENV_VERSION" 'PYTHON_ICON'
fi
}
+prompt_openfoam() {
+ local wm_project_version="$WM_PROJECT_VERSION"
+ local wm_fork="$WM_FORK"
+ if [[ -n "$wm_project_version" ]] && [[ -z "$wm_fork" ]] ; then
+ "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "OF: $(basename "$wm_project_version")"
+ elif [[ -n "$wm_project_version" ]] && [[ -n "$wm_fork" ]] ; then
+ "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "F-X: $(basename "$wm_project_version")"
+ fi
+}
+
# Swift version
prompt_swift_version() {
# Get the first number as this is probably the "main" version number..
@@ -1415,25 +1427,51 @@ prompt_swift_version() {
# dir_writable: Display information about the user's permission to write in the current directory
prompt_dir_writable() {
if [[ ! -w "$PWD" ]]; then
- "$1_prompt_segment" "$0_FORBIDDEN" "$2" "red" "226" "" 'LOCK_ICON'
+ "$1_prompt_segment" "$0_FORBIDDEN" "$2" "red" "yellow1" "" 'LOCK_ICON'
fi
}
-# Kubernetes Current Context
+# Kubernetes Current Context/Namespace
prompt_kubecontext() {
local kubectl_version="$(kubectl version --client 2>/dev/null)"
if [[ -n "$kubectl_version" ]]; then
- # Get the current Kubernetes config context's namespaece
- local k8s_namespace=$(kubectl config get-contexts --no-headers | grep '*' | awk '{print $5}')
# Get the current Kuberenetes context
- local k8s_context=$(kubectl config current-context)
+ 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
+
+ local k8s_final_text=""
+
+ if [[ "$cur_ctx" == "cur_namespace" ]]; then
+ # No reason to print out the same identificator twice
+ k8s_final_text="$cur_ctx"
+ else
+ k8s_final_text="$cur_ctx/$cur_namespace"
+ fi
+
+ "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_final_text" "KUBERNETES_ICON"
+ fi
+}
+
+# Dropbox status
+prompt_dropbox() {
+ # The first column is just the directory, so cut it
+ local dropbox_status="$(dropbox-cli filestatus . | cut -d\ -f2-)"
- if [[ -z "$k8s_namespace" ]]; then
- k8s_namespace="default"
+ # Only show if the folder is tracked and dropbox is running
+ if [[ "$dropbox_status" != 'unwatched' && "$dropbox_status" != "isn't running!" ]]; then
+ # If "up to date", only show the icon
+ if [[ "$dropbox_status" =~ 'up to date' ]]; then
+ dropbox_status=""
fi
- "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace" "KUBERNETES_ICON"
+
+ "$1_prompt_segment" "$0" "$2" "white" "blue" "$dropbox_status" "DROPBOX_ICON"
fi
+
}
@@ -1544,14 +1582,7 @@ prompt_powerlevel9k_setup() {
setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}"
# Display a warning if the terminal does not support 256 colors
- local term_colors
- term_colors=$(echotc Co 2>/dev/null)
- if (( ! $? && ${term_colors:-0} < 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 "_before_ loading this theme in your \~\/.zshrc. In most terminal emulators, putting"
- print -P "%F{blue}export TERM=\"xterm-256color\"%f at the top of your \~\/.zshrc is sufficient."
- fi
+ termColors
# If the terminal `LANG` is set to `C`, this theme will not work at all.
local term_lang