escape properly

This commit is contained in:
romkatv 2019-03-15 14:11:53 +01:00
parent ac04d7b952
commit 42f50bb9f6

View file

@ -197,7 +197,7 @@ left_prompt_segment() {
_p9k_cache_set "$output" "$background_color" _p9k_cache_set "$output" "$background_color"
fi fi
_P9K_PROMPT+="${_P9K_CACHE_VAL[1]}${5}${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" _P9K_PROMPT+="${_P9K_CACHE_VAL[1]}${5//\$/\\$}${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}"
_P9K_LAST_SEGMENT_INDEX=$2 _P9K_LAST_SEGMENT_INDEX=$2
_P9K_CURRENT_BG=$_P9K_CACHE_VAL[2] _P9K_CURRENT_BG=$_P9K_CACHE_VAL[2]
} }
@ -272,7 +272,7 @@ right_prompt_segment() {
_p9k_cache_set "$output" "$background_color" "$icon" _p9k_cache_set "$output" "$background_color" "$icon"
fi fi
_P9K_PROMPT+="${_P9K_CACHE_VAL[1]}${5}${5:+ }${_P9K_CACHE_VAL[3]}" _P9K_PROMPT+="${_P9K_CACHE_VAL[1]}${5//\$/\\$}${5:+ }${_P9K_CACHE_VAL[3]}"
_P9K_CURRENT_BG=$_P9K_CACHE_VAL[2] _P9K_CURRENT_BG=$_P9K_CACHE_VAL[2]
_P9K_LAST_SEGMENT_INDEX=$2 _P9K_LAST_SEGMENT_INDEX=$2
} }
@ -288,9 +288,10 @@ set_default POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER ")"
prompt_anaconda() { prompt_anaconda() {
# Depending on the conda version, either might be set. This # Depending on the conda version, either might be set. This
# variant works even if both are set. # variant works even if both are set.
local _path=$CONDA_ENV_PATH$CONDA_PREFIX local path=$CONDA_ENV_PATH$CONDA_PREFIX
if ! [ -z "$_path" ]; then if [[ -n $path ]]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$POWERLEVEL9K_ANACONDA_LEFT_DELIMITER$(basename $_path)$POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER" 'PYTHON_ICON' local prompt="$POWERLEVEL9K_ANACONDA_LEFT_DELIMITER${${path:t}//\%/%%}$POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER"
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$prompt" 'PYTHON_ICON'
fi fi
} }
@ -299,7 +300,7 @@ prompt_anaconda() {
prompt_aws() { prompt_aws() {
local aws_profile="${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}" local aws_profile="${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}"
if [[ -n "$aws_profile" ]]; then if [[ -n "$aws_profile" ]]; then
"$1_prompt_segment" "$0" "$2" red white "$aws_profile" 'AWS_ICON' "$1_prompt_segment" "$0" "$2" red white "${aws_profile//\%/%%}" 'AWS_ICON'
fi fi
} }
@ -309,7 +310,7 @@ prompt_aws_eb_env() {
# TODO(roman): This is clearly broken. Fix it. # TODO(roman): This is clearly broken. Fix it.
local eb_env=$(grep environment .elasticbeanstalk/config.yml 2> /dev/null | awk '{print $2}') local eb_env=$(grep environment .elasticbeanstalk/config.yml 2> /dev/null | awk '{print $2}')
if [[ -n "$eb_env" ]]; then if [[ -n "$eb_env" ]]; then
"$1_prompt_segment" "$0" "$2" black green "$eb_env" 'AWS_EB_ICON' "$1_prompt_segment" "$0" "$2" black green "${eb_env//\%/%%}" 'AWS_EB_ICON'
fi fi
} }
@ -323,7 +324,7 @@ prompt_background_jobs() {
local prompt local prompt
if [[ $POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE == true && if [[ $POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE == true &&
($n -gt 1 || $POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS == true) ]]; then ($n -gt 1 || $POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS == true) ]]; then
prompt=$n prompt='%j'
fi fi
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "cyan" "$prompt" 'BACKGROUND_JOBS_ICON' "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "cyan" "$prompt" 'BACKGROUND_JOBS_ICON'
} }
@ -596,17 +597,21 @@ set_default POWERLEVEL9K_ALWAYS_SHOW_CONTEXT false
set_default POWERLEVEL9K_ALWAYS_SHOW_USER false set_default POWERLEVEL9K_ALWAYS_SHOW_USER false
set_default POWERLEVEL9K_CONTEXT_TEMPLATE "%n@%m" set_default POWERLEVEL9K_CONTEXT_TEMPLATE "%n@%m"
prompt_context() { prompt_context() {
local current_state="DEFAULT" local content
local content="" if [[ $POWERLEVEL9K_ALWAYS_SHOW_CONTEXT == true ]]; then
content=$POWERLEVEL9K_CONTEXT_TEMPLATE
if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true || "$(whoami)" != "$DEFAULT_USER" || -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then else
local user=$(whoami)
if [[ $user != $DEFAULT_USER || -n $SSH_CLIENT || -n $SSH_TTY ]]; then
content="${POWERLEVEL9K_CONTEXT_TEMPLATE}" content="${POWERLEVEL9K_CONTEXT_TEMPLATE}"
elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then elif [[ $POWERLEVEL9K_ALWAYS_SHOW_USER == true ]]; then
content="$(whoami)" content="${user//\%/%%}"
else else
return return
fi fi
fi
local current_state="DEFAULT"
if [[ "${(%):-%#}" == '#' ]]; then if [[ "${(%):-%#}" == '#' ]]; then
current_state="ROOT" current_state="ROOT"
elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
@ -627,13 +632,14 @@ prompt_context() {
# Note that if $DEFAULT_USER is not set, this prompt segment will always print # Note that if $DEFAULT_USER is not set, this prompt segment will always print
set_default POWERLEVEL9K_USER_TEMPLATE "%n" set_default POWERLEVEL9K_USER_TEMPLATE "%n"
prompt_user() { prompt_user() {
[[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" != true && "$(whoami)" == "$DEFAULT_USER" ]] && return local user=$(whoami)
[[ $POWERLEVEL9K_ALWAYS_SHOW_USER != true && $user == $DEFAULT_USER ]] && return
if [[ "${(%):-%#}" == '#' ]]; then if [[ "${(%):-%#}" == '#' ]]; then
"$1_prompt_segment" "${0}_ROOT" "$2" "${DEFAULT_COLOR}" yellow "${POWERLEVEL9K_USER_TEMPLATE}" ROOT_ICON "$1_prompt_segment" "${0}_ROOT" "$2" "${DEFAULT_COLOR}" yellow "${POWERLEVEL9K_USER_TEMPLATE}" ROOT_ICON
elif [[ -n "$SUDO_COMMAND" ]]; then elif [[ -n "$SUDO_COMMAND" ]]; then
"$1_prompt_segment" "${0}_SUDO" "$2" "${DEFAULT_COLOR}" yellow "${POWERLEVEL9K_USER_TEMPLATE}" SUDO_ICON "$1_prompt_segment" "${0}_SUDO" "$2" "${DEFAULT_COLOR}" yellow "${POWERLEVEL9K_USER_TEMPLATE}" SUDO_ICON
else else
"$1_prompt_segment" "${0}_DEFAULT" "$2" "${DEFAULT_COLOR}" yellow "$(whoami)" USER_ICON "$1_prompt_segment" "${0}_DEFAULT" "$2" "${DEFAULT_COLOR}" yellow "${user//\%/%%}" USER_ICON
fi fi
} }
@ -733,13 +739,11 @@ set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~"
set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false
set_default POWERLEVEL9K_DIR_PATH_ABSOLUTE false set_default POWERLEVEL9K_DIR_PATH_ABSOLUTE false
set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false
set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false
set_default POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER false set_default POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER false
set_default POWERLEVEL9K_SHORTEN_STRATEGY "" set_default POWERLEVEL9K_SHORTEN_STRATEGY ""
set_default POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND "" set_default POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND ""
set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\u2026' set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\u2026'
set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker"
set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD ""
set_default -i POWERLEVEL9K_SHORTEN_DIR_LENGTH -1 set_default -i POWERLEVEL9K_SHORTEN_DIR_LENGTH -1
set_default -a POWERLEVEL9K_DIR_PACKAGE_FILES package.json composer.json set_default -a POWERLEVEL9K_DIR_PACKAGE_FILES package.json composer.json
prompt_dir() { prompt_dir() {
@ -849,11 +853,11 @@ prompt_dir() {
# Remove trailing slash from git path, so that we can # Remove trailing slash from git path, so that we can
# remove that git path from the pwd. # remove that git path from the pwd.
gitPath=${gitPath%/} gitPath=${gitPath%/}
package_path=${$(pwd)%%$gitPath} package_path=${$PWD%%$gitPath}
# Remove trailing slash # Remove trailing slash
package_path=${package_path%/} package_path=${package_path%/}
elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then
package_path=${$(pwd)%%/.git*} package_path=${$PWD%%/.git*}
fi fi
[[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && package_path=${package_path/$HOME/"~"} [[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && package_path=${package_path/$HOME/"~"}
@ -864,7 +868,7 @@ prompt_dir() {
# in the path (this is done by the "zero" pattern; see # in the path (this is done by the "zero" pattern; see
# http://stackoverflow.com/a/40855342/5586433). # http://stackoverflow.com/a/40855342/5586433).
local zero='%([BSUbfksu]|([FB]|){*})' local zero='%([BSUbfksu]|([FB]|){*})'
trunc_path=$(pwd) trunc_path=$PWD
# Then, find the length of the package_path string, and save the # Then, find the length of the package_path string, and save the
# subdirectory path as a substring of the current directory's path from 0 # subdirectory path as a substring of the current directory's path from 0
# to the length of the package path's string # to the length of the package path's string
@ -899,23 +903,43 @@ prompt_dir() {
esac esac
fi fi
# save state of path for highlighting and bold options current_path=${current_path//\%/%%}
local path_opt=$current_path local path_opt=$current_path
local state_path="${(%):-%~}" local current_state icon
local current_state="DEFAULT" if (( ! writable )); then
local icon="FOLDER_ICON" current_state=NOT_WRITABLE
if [[ $state_path == '/etc'* ]]; then icon=LOCK_ICON
current_state='ETC' else
icon='ETC_ICON' case $PWD in
elif (( ! writable )); then /etc*)
current_state="NOT_WRITABLE" current_state=ETC
icon='LOCK_ICON' icon=ETC_ICON
elif [[ $state_path == '~' ]]; then ;;
current_state="HOME" ~)
icon='HOME_ICON' current_state=HOME
elif [[ $state_path == '~'* ]]; then icon=HOME_ICON
current_state="HOME_SUBFOLDER" ;;
icon='HOME_SUB_ICON' ~/*)
current_state=HOME_SUBFOLDER
icon=HOME_SUB_ICON
;;
*)
current_state=DEFAULT
icon=FOLDER_ICON
;;
esac
fi
# This is some weird shit. ~/foo becomes /foo, while /~foo becomes ~foo. Who could want that?
if [[ $POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER == true && ( $path_opt == /?* || $path_opt == '~'?* ) ]]; then
current_path=${current_path[2,-1]}
fi
if [[ $POWERLEVEL9K_HOME_FOLDER_ABBREVIATION != '~' &&
$POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER != true &&
$path_opt == '~'?* ]]; then
current_path=${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}${current_path[2,-1]}
fi fi
# declare variables used for bold and state colors # declare variables used for bold and state colors
@ -930,63 +954,44 @@ prompt_dir() {
fi fi
# determine is the user has set a last directory color # determine is the user has set a last directory color
local dir_state_user_foreground=POWERLEVEL9K_DIR_${current_state}_FOREGROUND local dir_state_user_foreground=POWERLEVEL9K_DIR_${current_state}_FOREGROUND
local dir_state_foreground=${(P)dir_state_user_foreground} local dir_state_foreground=${${(P)dir_state_user_foreground}:-$DEFAULT_COLOR}
[[ -z ${dir_state_foreground} ]] && dir_state_foreground="${DEFAULT_COLOR}"
local dir_name base_name local dir_name=${current_path:h}
# use ZSH substitution to get the dirname and basename instead of calling external functions local base_name=${current_path:t}
dir_name=${path_opt%/*}
base_name=${path_opt##*/}
# if the user wants the last directory colored... # if the user wants the last directory colored...
if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then
# it the path is "/" or "~"
if [[ $path_opt == "/" || $path_opt == "~" ]]; then if [[ $path_opt == "/" || $path_opt == "~" ]]; then
current_path="${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${current_path}${bld_off}" current_path="${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${current_path}${bld_off}"
else # has a subfolder
# test if dirname != basename - they are equal if we use truncate_to_last or truncate_absolute
if [[ $dir_name != $base_name ]]; then
current_path="${dir_name}/${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}${bld_off}"
else else
if [[ $dir_name == '.' ]]; then
current_path="${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}${bld_off}" current_path="${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}${bld_off}"
else
current_path="${dir_name}/${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}${bld_off}"
fi fi
fi fi
else # no coloring else # no coloring
# it the path is "/" or "~"
if [[ $path_opt == "/" || $path_opt == "~" ]]; then if [[ $path_opt == "/" || $path_opt == "~" ]]; then
current_path="${bld_on}${current_path}${bld_off}" current_path="${bld_on}${current_path}${bld_off}"
else # has a subfolder
# test if dirname != basename - they are equal if we use truncate_to_last or truncate_absolute
if [[ $dir_name != $base_name ]]; then
current_path="${dir_name}/${bld_on}${base_name}${bld_off}"
else else
if [[ $dir_name == '.' ]]; then
current_path="${bld_on}${base_name}${bld_off}" current_path="${bld_on}${base_name}${bld_off}"
else
current_path="${dir_name}/${bld_on}${base_name}${bld_off}"
fi fi
fi fi
fi fi
# check if we need to omit the first character and only do it if we are not in "~" or "/"
if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" && $path_opt != "/" && $path_opt != "~" ]]; then
current_path="${current_path[2,-1]}"
fi
# check if the user wants the separator colored. # check if the user wants the separator colored.
if [[ -n ${POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND} && $path_opt != "/" ]]; then if [[ -n ${POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND} ]]; then
# because this contains color changing codes, it is easier to set a variable for what should be replaced
local repl="%F{$POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}/%F{$dir_state_foreground}" local repl="%F{$POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}/%F{$dir_state_foreground}"
# escape the / with a \
current_path=${current_path//\//$repl} current_path=${current_path//\//$repl}
fi fi
if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" && $path_opt != "/" ]]; then if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" ]]; then
current_path=${current_path//\//$POWERLEVEL9K_DIR_PATH_SEPARATOR} current_path=${current_path//\//$POWERLEVEL9K_DIR_PATH_SEPARATOR}
fi fi
if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" && ! "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then
# use :s to only replace the first occurance
current_path=${current_path:s/~/$POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}
fi
_p9k_cache_set "$current_state" "$current_path" "$icon" _p9k_cache_set "$current_state" "$current_path" "$icon"
fi fi
@ -997,7 +1002,7 @@ prompt_dir() {
# Docker machine # Docker machine
prompt_docker_machine() { prompt_docker_machine() {
if [[ -n "$DOCKER_MACHINE_NAME" ]]; then if [[ -n "$DOCKER_MACHINE_NAME" ]]; then
"$1_prompt_segment" "$0" "$2" "magenta" "$DEFAULT_COLOR" "$DOCKER_MACHINE_NAME" 'SERVER_ICON' "$1_prompt_segment" "$0" "$2" "magenta" "$DEFAULT_COLOR" "${DOCKER_MACHINE_NAME//\%/%%}" 'SERVER_ICON'
fi fi
} }
@ -1007,7 +1012,7 @@ prompt_go_version() {
local go_version=$(go version 2>/dev/null | sed -E "s/.*(go[0-9.]*).*/\1/") local go_version=$(go version 2>/dev/null | sed -E "s/.*(go[0-9.]*).*/\1/")
local go_path=$(go env GOPATH 2>/dev/null) local go_path=$(go env GOPATH 2>/dev/null)
if [[ -n "$go_version" && "${PWD##$go_path}" != "$PWD" ]]; then if [[ -n "$go_version" && "${PWD##$go_path}" != "$PWD" ]]; then
"$1_prompt_segment" "$0" "$2" "green" "grey93" "$go_version" "GO_ICON" "$1_prompt_segment" "$0" "$2" "green" "grey93" "${go_version//\%/%%}" "GO_ICON"
fi fi
} }
@ -1028,7 +1033,7 @@ prompt_detect_virt() {
fi fi
if [[ -n "${virt}" ]]; then if [[ -n "${virt}" ]]; then
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt" "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "${virt//\%/%%}"
fi fi
} }
@ -1052,7 +1057,7 @@ prompt_ip() {
local ip=$(p9k::parseIp "${POWERLEVEL9K_IP_INTERFACE}" "${ROOT_PREFIX}") local ip=$(p9k::parseIp "${POWERLEVEL9K_IP_INTERFACE}" "${ROOT_PREFIX}")
if [[ -n "$ip" ]]; then if [[ -n "$ip" ]]; then
"$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON' "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "${ip//\%/%%}" 'NETWORK_ICON'
fi fi
} }
@ -1065,7 +1070,7 @@ prompt_vpn_ip() {
local ip=$(p9k::parseIp "${POWERLEVEL9K_VPN_IP_INTERFACE}" "${ROOT_PREFIX}") local ip=$(p9k::parseIp "${POWERLEVEL9K_VPN_IP_INTERFACE}" "${ROOT_PREFIX}")
if [[ -n "${ip}" ]]; then if [[ -n "${ip}" ]]; then
"$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON' "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "${ip//\%/%%}" 'VPN_ICON'
fi fi
} }
@ -1076,7 +1081,7 @@ prompt_laravel_version() {
if [[ -n "${laravel_version}" && "${laravel_version}" =~ "Laravel Framework" ]]; then if [[ -n "${laravel_version}" && "${laravel_version}" =~ "Laravel Framework" ]]; then
# Strip out everything but the version # Strip out everything but the version
laravel_version="${laravel_version//Laravel Framework /}" laravel_version="${laravel_version//Laravel Framework /}"
"$1_prompt_segment" "$0" "$2" "maroon" "white" "${laravel_version}" 'LARAVEL_ICON' "$1_prompt_segment" "$0" "$2" "maroon" "white" "${laravel_version//\%/%%}" 'LARAVEL_ICON'
fi fi
} }
@ -1144,7 +1149,7 @@ prompt_node_version() {
local node_version=$(node -v 2>/dev/null) local node_version=$(node -v 2>/dev/null)
[[ -z "${node_version}" ]] && return [[ -z "${node_version}" ]] && return
"$1_prompt_segment" "$0" "$2" "green" "white" "${node_version:1}" 'NODE_ICON' "$1_prompt_segment" "$0" "$2" "green" "white" "${${node_version:1}//\%/%%}" 'NODE_ICON'
} }
################################################################ ################################################################
@ -1160,7 +1165,7 @@ prompt_nvm() {
nvm_default=$(nvm_version default) nvm_default=$(nvm_version default)
[[ "$node_version" =~ "$nvm_default" ]] && return [[ "$node_version" =~ "$nvm_default" ]] && return
$1_prompt_segment "$0" "$2" "magenta" "black" "${node_version:1}" 'NODE_ICON' $1_prompt_segment "$0" "$2" "magenta" "black" "${${node_version:1}//\%/%%}" 'NODE_ICON'
} }
################################################################ ################################################################
@ -1168,7 +1173,7 @@ prompt_nvm() {
prompt_nodeenv() { prompt_nodeenv() {
if [[ -n "$NODE_VIRTUAL_ENV" ]]; then if [[ -n "$NODE_VIRTUAL_ENV" ]]; then
local info="$(node -v)[${NODE_VIRTUAL_ENV:t}]" local info="$(node -v)[${NODE_VIRTUAL_ENV:t}]"
"$1_prompt_segment" "$0" "$2" "black" "green" "$info" 'NODE_ICON' "$1_prompt_segment" "$0" "$2" "black" "green" "${info//\%/%%}" 'NODE_ICON'
fi fi
} }
@ -1185,7 +1190,7 @@ prompt_php_version() {
php_version=$(php -v 2>&1 | grep -oe "^PHP\s*[0-9.]*") php_version=$(php -v 2>&1 | grep -oe "^PHP\s*[0-9.]*")
if [[ -n "$php_version" ]]; then if [[ -n "$php_version" ]]; then
"$1_prompt_segment" "$0" "$2" "fuchsia" "grey93" "$php_version" "$1_prompt_segment" "$0" "$2" "fuchsia" "grey93" "${php_version//\%/%%}"
fi fi
} }
@ -1225,7 +1230,7 @@ prompt_rbenv() {
local rbenv_version_name="$(rbenv version-name)" local rbenv_version_name="$(rbenv version-name)"
local rbenv_global="$(rbenv global)" local rbenv_global="$(rbenv global)"
if [[ "${rbenv_version_name}" != "${rbenv_global}" || "${POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then if [[ "${rbenv_version_name}" != "${rbenv_global}" || "${POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then
"$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$rbenv_version_name" 'RUBY_ICON' "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "${rbenv_version_name//\%/%%}" 'RUBY_ICON'
fi fi
fi fi
} }
@ -1251,7 +1256,7 @@ prompt_chruby() {
# Don't show anything if the chruby did not change the default ruby # Don't show anything if the chruby did not change the default ruby
if [[ "$RUBY_ENGINE" != "" ]]; then if [[ "$RUBY_ENGINE" != "" ]]; then
"$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "${chruby_label}" 'RUBY_ICON' "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "${chruby_label//\%/%%}" 'RUBY_ICON'
fi fi
} }
@ -1274,13 +1279,13 @@ prompt_rust_version() {
rust_version=${${rust_version/rustc /}%% *} rust_version=${${rust_version/rustc /}%% *}
if [[ -n "$rust_version" ]]; then if [[ -n "$rust_version" ]]; then
"$1_prompt_segment" "$0" "$2" "darkorange" "$DEFAULT_COLOR" "$rust_version" 'RUST_ICON' "$1_prompt_segment" "$0" "$2" "darkorange" "$DEFAULT_COLOR" "${rust_version//\%/%%}" 'RUST_ICON'
fi fi
} }
# RSpec test ratio # RSpec test ratio
prompt_rspec_stats() { prompt_rspec_stats() {
if [[ (-d app && -d spec) ]]; then if [[ -d app && -d spec ]]; then
local code_amount tests_amount local code_amount tests_amount
code_amount=$(ls -1 app/**/*.rb | wc -l) code_amount=$(ls -1 app/**/*.rb | wc -l)
tests_amount=$(ls -1 spec/**/*.rb | wc -l) tests_amount=$(ls -1 spec/**/*.rb | wc -l)
@ -1296,7 +1301,7 @@ prompt_rvm() {
local version_and_gemset=${$(rvm-prompt v p)/ruby-} local version_and_gemset=${$(rvm-prompt v p)/ruby-}
if [[ -n "$version_and_gemset" ]]; then if [[ -n "$version_and_gemset" ]]; then
"$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON' "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "${version_and_gemset//\%/%%}" 'RUBY_ICON'
fi fi
fi fi
} }
@ -1425,7 +1430,7 @@ prompt_symfony2_version() {
if [[ -f app/bootstrap.php.cache ]]; then if [[ -f app/bootstrap.php.cache ]]; then
local symfony2_version local symfony2_version
symfony2_version=$(grep " VERSION " app/bootstrap.php.cache | sed -e 's/[^.0-9]*//g') symfony2_version=$(grep " VERSION " app/bootstrap.php.cache | sed -e 's/[^.0-9]*//g')
"$1_prompt_segment" "$0" "$2" "grey35" "$DEFAULT_COLOR" "$symfony2_version" 'SYMFONY_ICON' "$1_prompt_segment" "$0" "$2" "grey35" "$DEFAULT_COLOR" "${symfony2_version//\%/%%}" 'SYMFONY_ICON'
fi fi
} }
@ -1452,17 +1457,6 @@ set_default POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME false
set_default POWERLEVEL9K_TIME_FORMAT "%D{%H:%M:%S}" set_default POWERLEVEL9K_TIME_FORMAT "%D{%H:%M:%S}"
prompt_time() { prompt_time() {
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$POWERLEVEL9K_TIME_FORMAT" "TIME_ICON" "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$POWERLEVEL9K_TIME_FORMAT" "TIME_ICON"
# For the reference, here's how the code should ideally look like. However, it's 2ms slower
# for a tiny gain in usability. The difference is that the current code will cause time
# to update when vcs segment goes from grey to green/yellow, but the commented-out code
# won't (unless POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME is true).
#if [[ $POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME == true ]]; then
# local _P9K_TIME=$POWERLEVEL9K_TIME_FORMAT
#else
# [[ -v _P9K_REFRESH_PROMPT ]] || typeset -gH _P9K_TIME=$(print -P $POWERLEVEL9K_TIME_FORMAT)
# typeset -gH _P9K_TIME=$POWERLEVEL9K_TIME_FORMAT
#fi
#"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$_P9K_TIME" "TIME_ICON"
} }
################################################################ ################################################################
@ -1470,9 +1464,6 @@ prompt_time() {
set_default POWERLEVEL9K_DATE_FORMAT "%D{%d.%m.%y}" set_default POWERLEVEL9K_DATE_FORMAT "%D{%d.%m.%y}"
prompt_date() { prompt_date() {
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$POWERLEVEL9K_DATE_FORMAT" "DATE_ICON" "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$POWERLEVEL9K_DATE_FORMAT" "DATE_ICON"
# See comments in prompt_time.
# [[ -v _P9K_REFRESH_PROMPT ]] || typeset -gH _P9K_DATE=$(print -P $POWERLEVEL9K_DATE_FORMAT)
# "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$_P9K_DATE" "DATE_ICON"
} }
################################################################ ################################################################
@ -1481,7 +1472,7 @@ prompt_todo() {
if $(hash todo.sh 2>&-); then if $(hash todo.sh 2>&-); then
count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }') count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }')
if [[ "$count" = <-> ]]; then if [[ "$count" = <-> ]]; then
"$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" "$count" 'TODO_ICON' "$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" "${count//\%/%%}" 'TODO_ICON'
fi fi
fi fi
} }
@ -1634,21 +1625,21 @@ typeset -fH _p9k_vcs_render() {
if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
_p9k_get_icon VCS_BRANCH_ICON _p9k_get_icon VCS_BRANCH_ICON
vcs_prompt+="$_P9K_RETVAL$VCS_STATUS_LOCAL_BRANCH " vcs_prompt+="$_P9K_RETVAL${VCS_STATUS_LOCAL_BRANCH//\%/%%} "
fi fi
if [[ $POWERLEVEL9K_VCS_HIDE_TAGS == false && -n $VCS_STATUS_TAG ]]; then if [[ $POWERLEVEL9K_VCS_HIDE_TAGS == false && -n $VCS_STATUS_TAG ]]; then
_p9k_get_icon VCS_TAG_ICON _p9k_get_icon VCS_TAG_ICON
vcs_prompt+="$_P9K_RETVAL$VCS_STATUS_TAG " vcs_prompt+="$_P9K_RETVAL${VCS_STATUS_TAG//\%/%%} "
fi fi
if [[ -n $VCS_STATUS_ACTION ]]; then if [[ -n $VCS_STATUS_ACTION ]]; then
vcs_prompt+="%F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| $VCS_STATUS_ACTION%f" vcs_prompt+="%F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| ${VCS_STATUS_ACTION//\%/%%}%f"
else else
if [[ -n $VCS_STATUS_REMOTE_BRANCH && if [[ -n $VCS_STATUS_REMOTE_BRANCH &&
$VCS_STATUS_LOCAL_BRANCH != $VCS_STATUS_REMOTE_BRANCH ]]; then $VCS_STATUS_LOCAL_BRANCH != $VCS_STATUS_REMOTE_BRANCH ]]; then
_p9k_get_icon VCS_REMOTE_BRANCH_ICON _p9k_get_icon VCS_REMOTE_BRANCH_ICON
vcs_prompt+="$_P9K_RETVAL$VCS_STATUS_REMOTE_BRANCH " vcs_prompt+="$_P9K_RETVAL${VCS_STATUS_REMOTE_BRANCH//\%/%%} "
fi fi
if [[ $VCS_STATUS_HAS_STAGED == 1 ]]; then if [[ $VCS_STATUS_HAS_STAGED == 1 ]]; then
_p9k_get_icon VCS_STAGED_ICON _p9k_get_icon VCS_STAGED_ICON
@ -1811,7 +1802,7 @@ prompt_vi_mode() {
# https://virtualenv.pypa.io/en/latest/ # https://virtualenv.pypa.io/en/latest/
prompt_virtualenv() { prompt_virtualenv() {
if [[ -n "$VIRTUAL_ENV" ]]; then if [[ -n "$VIRTUAL_ENV" ]]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${VIRTUAL_ENV:t}" 'PYTHON_ICON' "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${${VIRTUAL_ENV:t}//\%/%%}" 'PYTHON_ICON'
fi fi
} }
@ -1821,7 +1812,7 @@ prompt_virtualenv() {
set_default POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW false set_default POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW false
prompt_pyenv() { prompt_pyenv() {
if [[ -n "$PYENV_VERSION" ]]; then if [[ -n "$PYENV_VERSION" ]]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$PYENV_VERSION" 'PYTHON_ICON' "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${PYENV_VERSION//\%/%%}" 'PYTHON_ICON'
elif [ $commands[pyenv] ]; then elif [ $commands[pyenv] ]; then
local pyenv_version_name="$(pyenv version-name)" local pyenv_version_name="$(pyenv version-name)"
local pyenv_global="system" local pyenv_global="system"
@ -1830,7 +1821,7 @@ prompt_pyenv() {
pyenv_global="$(pyenv version-file-read ${pyenv_root}/version)" pyenv_global="$(pyenv version-file-read ${pyenv_root}/version)"
fi fi
if [[ "${pyenv_version_name}" != "${pyenv_global}" || "${POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then if [[ "${pyenv_version_name}" != "${pyenv_global}" || "${POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$pyenv_version_name" 'PYTHON_ICON' "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${pyenv_version_name//\%/%%}" 'PYTHON_ICON'
fi fi
fi fi
} }
@ -1840,10 +1831,10 @@ prompt_pyenv() {
prompt_openfoam() { prompt_openfoam() {
local wm_project_version="$WM_PROJECT_VERSION" local wm_project_version="$WM_PROJECT_VERSION"
local wm_fork="$WM_FORK" local wm_fork="$WM_FORK"
if [[ -n "$wm_project_version" ]] && [[ -z "$wm_fork" ]] ; then if [[ -n "$wm_project_version" && -z "$wm_fork" ]] ; then
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "OF: $(basename "$wm_project_version")" "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "OF: ${${wm_project_version:t}//\%/%%}"
elif [[ -n "$wm_project_version" ]] && [[ -n "$wm_fork" ]] ; then elif [[ -n "$wm_project_version" && -n "$wm_fork" ]] ; then
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "F-X: $(basename "$wm_project_version")" "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "F-X: ${${wm_project_version:t}//\%/%%}"
fi fi
} }
@ -1854,7 +1845,7 @@ prompt_swift_version() {
local swift_version=$(swift --version 2>/dev/null | grep -o -E "[0-9.]+" | head -n 1) local swift_version=$(swift --version 2>/dev/null | grep -o -E "[0-9.]+" | head -n 1)
[[ -z "${swift_version}" ]] && return [[ -z "${swift_version}" ]] && return
"$1_prompt_segment" "$0" "$2" "magenta" "white" "${swift_version}" 'SWIFT_ICON' "$1_prompt_segment" "$0" "$2" "magenta" "white" "${swift_version//\%/%%}" 'SWIFT_ICON'
} }
################################################################ ################################################################
@ -1888,7 +1879,7 @@ prompt_kubecontext() {
k8s_final_text="$cur_ctx/$cur_namespace" k8s_final_text="$cur_ctx/$cur_namespace"
fi fi
"$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_final_text" "KUBERNETES_ICON" "$1_prompt_segment" "$0" "$2" "magenta" "white" "${k8s_final_text//\%/%%}" "KUBERNETES_ICON"
fi fi
} }
@ -1905,7 +1896,7 @@ prompt_dropbox() {
dropbox_status="" dropbox_status=""
fi fi
"$1_prompt_segment" "$0" "$2" "white" "blue" "$dropbox_status" "DROPBOX_ICON" "$1_prompt_segment" "$0" "$2" "white" "blue" "${dropbox_status//\%/%%}" "DROPBOX_ICON"
fi fi
} }
@ -1920,7 +1911,7 @@ prompt_java_version() {
java_version=$(java -version 2>/dev/null && java -fullversion 2>&1 | cut -d '"' -f 2) java_version=$(java -version 2>/dev/null && java -fullversion 2>&1 | cut -d '"' -f 2)
if [[ -n "$java_version" ]]; then if [[ -n "$java_version" ]]; then
"$1_prompt_segment" "$0" "$2" "red" "white" "$java_version" "JAVA_ICON" "$1_prompt_segment" "$0" "$2" "red" "white" "${java_version//\%/%%}" "JAVA_ICON"
fi fi
} }