diff options
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 623 |
1 files changed, 445 insertions, 178 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index edb94632..1f13ee5f 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -17,7 +17,7 @@ ################################################################ ## Turn on for Debugging -#PS4='%s%f%b%k%F{blue}%{λ%}%L %F{240}%N:%i%(?.. %F{red}%?) %1(_.%F{yellow}%-1_ .)%s%f%b%k ' +#PS4='%s%f%b%k%F{blue}%{λ%}%L %F{240}%N:%i%(?.. %F{red}%?) %1(_.%F{yellow}%-1_ .)%s%f%b%k ' #zstyle ':vcs_info:*+*:*' debug true #set -o xtrace @@ -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 @@ -272,11 +273,12 @@ right_prompt_segment() { # right-left but reads the opposite, this isn't necessary for the other side. CURRENT_BG='NONE' +################################################################ # Anaconda Environment prompt_anaconda() { # Depending on the conda version, either might be set. This # variant works even if both are set. - _path=$CONDA_ENV_PATH$CONDA_PREFIX + local _path=$CONDA_ENV_PATH$CONDA_PREFIX if ! [ -z "$_path" ]; then # config - can be overwritten in users' zshrc file. set_default POWERLEVEL9K_ANACONDA_LEFT_DELIMITER "(" @@ -285,15 +287,17 @@ prompt_anaconda() { fi } +################################################################ # AWS Profile prompt_aws() { - local aws_profile="$AWS_DEFAULT_PROFILE" + local aws_profile="${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}" if [[ -n "$aws_profile" ]]; then "$1_prompt_segment" "$0" "$2" red white "$aws_profile" 'AWS_ICON' fi } +################################################################ # Current Elastic Beanstalk environment prompt_aws_eb_env() { local eb_env=$(grep environment .elasticbeanstalk/config.yml 2> /dev/null | awk '{print $2}') @@ -303,8 +307,10 @@ prompt_aws_eb_env() { fi } +################################################################ # 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,13 +319,14 @@ 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' fi } +################################################################ # A newline in your prompt, so you can segments on multiple lines. prompt_newline() { local lws newline @@ -337,6 +344,7 @@ prompt_newline() { POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws } +################################################################ # Segment that indicates usage level of current partition. set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false set_default POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90 @@ -379,6 +387,8 @@ prompt_disk_usage() { fi } +################################################################ +# Segment that displays the battery status in levels and colors prompt_battery() { # The battery can have four different states - default to 'unknown'. local current_state='unknown' @@ -489,6 +499,7 @@ prompt_battery() { fi } +################################################################ # Public IP segment # Parameters: # * $1 Alignment: string - left|right @@ -507,7 +518,11 @@ prompt_public_ip() { if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then typeset -i timediff # if saved IP is more than - timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s))) + 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 [[ $timediff -gt $POWERLEVEL9K_PUBLIC_IP_TIMEOUT ]] && refresh_ip=true # If tmp file is empty get a fresh IP [[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=true @@ -551,10 +566,20 @@ prompt_public_ip() { # Draw the prompt segment if [[ -n $public_ip ]]; then - $1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" 'PUBLIC_IP_ICON' + icon='PUBLIC_IP_ICON' + # Check VPN is on if VPN interface is set + if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then + for vpn_iface in $(/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1) + do + icon='VPN_ICON' + break + done + fi + $1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" "$icon" fi } +################################################################ # Context: user@hostname (who am I and where am I) # Note that if $DEFAULT_USER is not set, this prompt segment will always print set_default POWERLEVEL9K_ALWAYS_SHOW_CONTEXT false @@ -564,26 +589,35 @@ prompt_context() { local current_state="DEFAULT" typeset -AH context_states context_states=( - "ROOT" "yellow" - "DEFAULT" "011" + "ROOT" "yellow" + "SUDO" "yellow" + "DEFAULT" "yellow" + "REMOTE" "yellow" + "REMOTE_SUDO" "yellow" ) local content="" - if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then - - if [[ $(print -P "%#") == '#' ]]; then - current_state="ROOT" - fi - + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then content="${POWERLEVEL9K_CONTEXT_TEMPLATE}" - elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then - content="$USER" + content="$(whoami)" else return fi + if [[ $(print -P "%#") == '#' ]]; then + current_state="ROOT" + elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + if sudo -n true 2>/dev/null; then + current_state="REMOTE_SUDO" + else + current_state="REMOTE" + fi + elif sudo -n true 2>/dev/null; then + current_state="SUDO" + fi + "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" } @@ -594,7 +628,7 @@ set_default POWERLEVEL9K_USER_TEMPLATE "%n" prompt_user() { local current_state="DEFAULT" typeset -AH user_state - if [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]]; then + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]]; then if [[ $(print -P "%#") == '#' ]]; then user_state=( "STATE" "ROOT" @@ -603,12 +637,20 @@ prompt_user() { "FOREGROUND_COLOR" "yellow" "VISUAL_IDENTIFIER" "ROOT_ICON" ) + elif sudo -n true 2>/dev/null; then + user_state=( + "STATE" "SUDO" + "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "yellow" + "VISUAL_IDENTIFIER" "SUDO_ICON" + ) else user_state=( "STATE" "DEFAULT" - "CONTENT" "$USER" + "CONTENT" "$(whoami)" "BACKGROUND_COLOR" "${DEFAULT_COLOR}" - "FOREGROUND_COLOR" "011" + "FOREGROUND_COLOR" "yellow" "VISUAL_IDENTIFIER" "USER_ICON" ) fi @@ -635,13 +677,14 @@ prompt_host() { "STATE" "LOCAL" "CONTENT" "${POWERLEVEL9K_HOST_TEMPLATE}" "BACKGROUND_COLOR" "${DEFAULT_COLOR}" - "FOREGROUND_COLOR" "011" + "FOREGROUND_COLOR" "yellow" "VISUAL_IDENTIFIER" "HOST_ICON" ) fi "$1_prompt_segment" "$0_${host_state[STATE]}" "$2" "${host_state[BACKGROUND_COLOR]}" "${host_state[FOREGROUND_COLOR]}" "${host_state[CONTENT]}" "${host_state[VISUAL_IDENTIFIER]}" } +################################################################ # The 'custom` prompt provides a way for users to invoke commands and display # the output in a segment. prompt_custom() { @@ -653,6 +696,7 @@ prompt_custom() { fi } +################################################################ # Display the duration the command needed to run. prompt_command_execution_time() { set_default POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD 3 @@ -682,25 +726,123 @@ 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 } +################################################################ # Dir: current working directory +# Parameters: +# * $1 Alignment: string - left|right +# * $2 Index: integer set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" -set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false +set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false prompt_dir() { - local current_path="$(print -P "%~")" - if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then - set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' + # using $PWD instead of "$(print -P '%~')" to allow use of POWERLEVEL9K_DIR_PATH_ABSOLUTE + local current_path=$PWD # WAS: local current_path="$(print -P '%~')" + # check if the user wants to use absolute paths or "~" paths + [[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path//$HOME/"~"} + # declare all local variables + local paths directory test_dir test_dir_length trunc_path threshhold + # if we are not in "~" or "/", split the paths into an array and exclude "~" + (( ${#current_path} > 1 )) && paths=(${(s:/:)${current_path//"~\/"/}}) || paths=() + # only run the code if SHORTEN_DIR_LENGTH is set, or we are using the two strategies that don't rely on it. + if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_to_last" ]]; then + set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" + # convert delimiter from unicode to literal character, so that we can get the correct length later + local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) case "$POWERLEVEL9K_SHORTEN_STRATEGY" in + truncate_absolute_chars) + if [ ${#current_path} -gt $(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) ]; then + current_path=$POWERLEVEL9K_SHORTEN_DELIMITER${current_path:(-POWERLEVEL9K_SHORTEN_DIR_LENGTH)} + fi + ;; 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") + # truncate characters from the middle of the path + current_path=$(truncatePath $current_path $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER "middle") ;; truncate_from_right) - current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) + # truncate characters from the right of the path + current_path=$(truncatePath "$current_path" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) + ;; + truncate_absolute) + # truncate all characters except the last POWERLEVEL9K_SHORTEN_DIR_LENGTH characters + if [ ${#current_path} -gt $(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) ]; then + current_path=$POWERLEVEL9K_SHORTEN_DELIMITER${current_path:(-POWERLEVEL9K_SHORTEN_DIR_LENGTH)} + fi + ;; + truncate_to_last) + # truncate all characters before the current directory + current_path=${current_path##*/} + ;; + truncate_to_first_and_last) + if (( ${#current_path} > 1 )) && (( ${POWERLEVEL9K_SHORTEN_DIR_LENGTH} > 0 )); then + threshhold=$(( ${POWERLEVEL9K_SHORTEN_DIR_LENGTH} * 2)) + # if we are in "~", add it back into the paths array + [[ $current_path == '~'* ]] && paths=("~" "${paths[@]}") + if (( ${#paths} > $threshhold )); then + local num=$(( ${#paths} - ${POWERLEVEL9K_SHORTEN_DIR_LENGTH} )) + # repace the middle elements + for (( i=$POWERLEVEL9K_SHORTEN_DIR_LENGTH; i<$num; i++ )); do + paths[$i+1]=$POWERLEVEL9K_SHORTEN_DELIMITER + done + [[ $current_path != '~'* ]] && current_path="/" || current_path="" + current_path+="${(j:/:)paths}" + fi + fi + ;; + truncate_to_unique) + # for each parent path component find the shortest unique beginning + # characters sequence. Source: https://stackoverflow.com/a/45336078 + if (( ${#current_path} > 1 )); then # root and home are exceptions and won't have paths + local matching + local cur_path='/' + [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path='' + for directory in ${paths[@]}; do + test_dir='' + for (( i=0; i<${#directory}; i++ )); do + test_dir+="${directory:$i:1}" + matching=("$cur_path"/"$test_dir"*/) + if [[ ${#matching[@]} -eq 1 ]]; then + break + fi + done + trunc_path+="$test_dir/" + cur_path+="$directory/" + done + [[ $current_path == "~"* ]] && trunc_path="~/$trunc_path" + current_path="${trunc_path: : -1}" + fi + ;; + truncate_with_folder_marker) + if (( ${#paths} > 0 )); then # root and home are exceptions and won't have paths, so skip this + local last_marked_folder marked_folder + set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" + + # Search for the folder marker in the parent directories and + # buildup a pattern that is removed from the current path + # later on. + for marked_folder in $(upsearch $POWERLEVEL9K_SHORTEN_FOLDER_MARKER); do + if [[ "$marked_folder" == "/" ]]; then + # If we reached root folder, stop upsearch. + trunc_path="/" + elif [[ "$marked_folder" == "$HOME" ]]; then + # If we reached home folder, stop upsearch. + trunc_path="~" + elif [[ "${marked_folder%/*}" == $last_marked_folder ]]; then + trunc_path="${trunc_path%/}/${marked_folder##*/}" + else + trunc_path="${trunc_path%/}/$POWERLEVEL9K_SHORTEN_DELIMITER/${marked_folder##*/}" + fi + last_marked_folder=$marked_folder + done + + # Replace the shortest possible match of the marked folder from + # the current path. + current_path=$trunc_path${current_path#${last_marked_folder}*} + fi ;; truncate_with_package_name) local name repo_path package_path current_dir zero @@ -725,11 +867,11 @@ prompt_dir() { # in the path (this is done by the "zero" pattern; see # http://stackoverflow.com/a/40855342/5586433). local zero='%([BSUbfksu]|([FB]|){*})' - current_dir=$(pwd) + trunc_path=$(pwd) # 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 # to the length of the package path's string - subdirectory_path=$(truncatePathFromRight "${current_dir:${#${(S%%)package_path//$~zero/}}}") + subdirectory_path=$(truncatePath "${trunc_path:${#${(S%%)package_path//$~zero/}}}" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) # Parse the 'name' from the package.json; if there are any problems, just # print the file path defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json) @@ -750,74 +892,18 @@ 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" - else - current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) fi ;; - truncate_with_folder_marker) - local last_marked_folder marked_folder - set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" - - # Search for the folder marker in the parent directories and - # buildup a pattern that is removed from the current path - # later on. - for marked_folder in $(upsearch $POWERLEVEL9K_SHORTEN_FOLDER_MARKER); do - if [[ "$marked_folder" == "/" ]]; then - # If we reached root folder, stop upsearch. - current_path="/" - elif [[ "$marked_folder" == "$HOME" ]]; then - # If we reached home folder, stop upsearch. - current_path="~" - elif [[ "${marked_folder%/*}" == $last_marked_folder ]]; then - current_path="${current_path%/}/${marked_folder##*/}" - else - current_path="${current_path%/}/$POWERLEVEL9K_SHORTEN_DELIMITER/${marked_folder##*/}" - fi - last_marked_folder=$marked_folder - done - - # Replace the shortest possible match of the marked folder from - # the current path. - current_path=$current_path${PWD#${last_marked_folder}*} - ;; - truncate_to_unique) - # for each parent path component find the shortest unique beginning - # characters sequence. Source: https://stackoverflow.com/a/45336078 - paths=(${(s:/:)PWD}) - cur_path='/' - cur_short_path='/' - for directory in ${paths[@]} - do - cur_dir='' - for (( i=0; i<${#directory}; i++ )); do - cur_dir+="${directory:$i:1}" - matching=("$cur_path"/"$cur_dir"*/) - if [[ ${#matching[@]} -eq 1 ]]; then - break - fi - done - cur_short_path+="$cur_dir/" - cur_path+="$directory/" - done - current_path="${cur_short_path: : -1}" - ;; *) - current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" + if [[ $current_path != "~" ]]; then + current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" + fi ;; esac fi - if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then - current_path="${current_path[2,-1]}" - fi - - if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" ]]; then - current_path="$( echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g")" - fi - - if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" ]]; then - current_path=${current_path/#\~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}} - fi + # save state of path for highlighting and bold options + local path_opt=$current_path typeset -AH dir_states dir_states=( @@ -826,17 +912,89 @@ prompt_dir() { "HOME_SUBFOLDER" "HOME_SUB_ICON" "NOT_WRITABLE" "LOCK_ICON" ) + local state_path="$(print -P '%~')" local current_state="DEFAULT" if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then current_state="NOT_WRITABLE" - elif [[ $(print -P "%~") == '~' ]]; then + elif [[ $state_path == '~' ]]; then current_state="HOME" - elif [[ $(print -P "%~") == '~'* ]]; then + elif [[ $state_path == '~'* ]]; then current_state="HOME_SUBFOLDER" fi + + # declare variables used for bold and state colors + local bld_on bld_off dir_state_foreground dir_state_user_foreground + # test if user wants the last directory printed in bold + if [[ "${(L)POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" == "true" ]]; then + bld_on="%B" + bld_off="%b" + else + bld_on="" + bld_off="" + fi + # determine is the user has set a last directory color + local dir_state_user_foreground=POWERLEVEL9K_DIR_${current_state}_FOREGROUND + local dir_state_foreground=${(P)dir_state_user_foreground} + [[ -z ${dir_state_foreground} ]] && dir_state_foreground="${DEFAULT_COLOR}" + + local dir_name base_name + # use ZSH substitution to get the dirname and basename instead of calling external functions + dir_name=${path_opt%/*} + base_name=${path_opt##*/} + + # if the user wants the last directory colored... + if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then + # it the path is "/" or "~" + if [[ $path_opt == "/" || $path_opt == "~" ]]; then + 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 + current_path="${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}${bld_off}" + fi + fi + else # no coloring + # it the path is "/" or "~" + if [[ $path_opt == "/" || $path_opt == "~" ]]; then + 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 + current_path="${bld_on}${base_name}${bld_off}" + 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. + if [[ -n ${POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND} && $path_opt != "/" ]]; 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}" + # escape the / with a \ + current_path=${current_path//\//$repl} + fi + + if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" && $path_opt != "/" ]]; then + current_path=${current_path//\//$POWERLEVEL9K_DIR_PATH_SEPARATOR} + 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 + "$1_prompt_segment" "$0_${current_state}" "$2" "blue" "$DEFAULT_COLOR" "${current_path}" "${dir_states[$current_state]}" } +################################################################ # Docker machine prompt_docker_machine() { local docker_machine="$DOCKER_MACHINE_NAME" @@ -846,6 +1004,7 @@ prompt_docker_machine() { fi } +################################################################ # GO prompt prompt_go_version() { local go_version @@ -854,15 +1013,17 @@ 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) prompt_detect_virt() { if ! command -v systemd-detect-virt > /dev/null; then @@ -881,7 +1042,8 @@ prompt_detect_virt() { fi } - +################################################################ +# Test icons prompt_icons_test() { for key in ${(@k)icons}; do # The lower color spectrum in ZSH makes big steps. Choosing @@ -892,6 +1054,8 @@ prompt_icons_test() { done } +################################################################ +# Segment to display the current IP address prompt_ip() { if [[ "$OS" == "OSX" ]]; then if defined POWERLEVEL9K_IP_INTERFACE; then @@ -922,6 +1086,8 @@ prompt_ip() { "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON' } +################################################################ +# Segment to display if VPN is active set_default POWERLEVEL9K_VPN_IP_INTERFACE "tun" # prompt if vpn active prompt_vpn_ip() { @@ -932,6 +1098,8 @@ prompt_vpn_ip() { done } +################################################################ +# Segment to display load set_default POWERLEVEL9K_LOAD_WHICH 5 prompt_load() { # The load segment can have three different states @@ -976,9 +1144,9 @@ prompt_load() { # Replace comma load_avg=${load_avg//,/.} - if [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.7") ]]; then + if [[ "$load_avg" -gt $((${cores} * 0.7)) ]]; then current_state="critical" - elif [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.5") ]]; then + elif [[ "$load_avg" -gt $((${cores} * 0.5)) ]]; then current_state="warning" else current_state="normal" @@ -987,8 +1155,8 @@ prompt_load() { "$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg" 'LOAD_ICON' } - -# Node version +################################################################ +# Segment to diplay Node version prompt_node_version() { local node_version=$(node -v 2>/dev/null) [[ -z "${node_version}" ]] && return @@ -996,7 +1164,8 @@ prompt_node_version() { "$1_prompt_segment" "$0" "$2" "green" "white" "${node_version:1}" 'NODE_ICON' } -# Node version from NVM +################################################################ +# Segment to display Node version from NVM # Only prints the segment if different than the default value prompt_nvm() { local node_version nvm_default @@ -1011,7 +1180,8 @@ prompt_nvm() { $1_prompt_segment "$0" "$2" "magenta" "black" "${node_version:1}" 'NODE_ICON' } -# NodeEnv Prompt +################################################################ +# Segment to display NodeEnv prompt_nodeenv() { local nodeenv_path="$NODE_VIRTUAL_ENV" if [[ -n "$nodeenv_path" && "$NODE_VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then @@ -1020,22 +1190,25 @@ prompt_nodeenv() { fi } -# print a little OS icon +################################################################ +# Segment to 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 +################################################################ +# Segment to display PHP version number prompt_php_version() { local 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 } -# Show free RAM and used Swap +################################################################ +# Segment to display free RAM and used Swap prompt_ram() { local base='' local ramfree=0 @@ -1058,22 +1231,25 @@ prompt_ram() { "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$ramfree" $base)" 'RAM_ICON' } + +set_default POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW false # rbenv information prompt_rbenv() { - if which rbenv 2>/dev/null >&2; then + if command 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 + + # Don't show anything if the current Ruby is the same as the global Ruby + # unless `POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW` is set. + if [[ $rbenv_version_name == $rbenv_global && "$POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW" = false ]]; then return fi - - "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$rbenv_version_name" 'RUBY_ICON' fi } -# chruby information +################################################################ +# Segment to display chruby information # see https://github.com/postmodern/chruby/issues/245 for chruby_auto issue with ZSH prompt_chruby() { local chruby_env @@ -1084,23 +1260,27 @@ prompt_chruby() { fi } -# Print an icon if user is root. +################################################################ +# Segment to print an icon if user is root. prompt_root_indicator() { if [[ "$UID" -eq 0 ]]; then "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'ROOT_ICON' fi } -# Print Rust version number +################################################################ +# Segment to display Rust version number prompt_rust_version() { local 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_version" 'RUST_ICON' + "$1_prompt_segment" "$0" "$2" "darkorange" "$DEFAULT_COLOR" "$rust_version" 'RUST_ICON' fi } -# RSpec test ratio + +################################################################ +# Segment to display RSpec test ratio prompt_rspec_stats() { if [[ (-d app && -d spec) ]]; then local code_amount tests_amount @@ -1111,21 +1291,25 @@ prompt_rspec_stats() { fi } -# Ruby Version Manager information +################################################################ +# Segment to display Ruby Version Manager information 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 } +################################################################ +# Segment to display SSH icon when connected prompt_ssh() { if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'SSH_ICON' fi } +################################################################ # 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 # @@ -1146,7 +1330,7 @@ exit_code_or_status() { else local sig=$(( ec - 128 )) local idx=$(( sig + 1 )) - echo "${signals[$idx]}(-${sig})" + echo "SIG${signals[$idx]}(${sig})" fi } @@ -1156,8 +1340,13 @@ prompt_status() { local ec if [[ $POWERLEVEL9K_STATUS_SHOW_PIPESTATUS == true ]]; then - ec_text=$(exit_code_or_status "${RETVALS[1]}") - ec_sum=${RETVALS[1]} + if (( $#RETVALS > 1 )); then + ec_text=$(exit_code_or_status "${RETVALS[1]}") + ec_sum=${RETVALS[1]} + else + ec_text=$(exit_code_or_status "${RETVAL}") + ec_sum=${RETVAL} + fi for ec in "${(@)RETVALS[2,-1]}"; do ec_text="${ec_text}|$(exit_code_or_status "$ec")" @@ -1172,7 +1361,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 @@ -1181,6 +1370,8 @@ prompt_status() { fi } +################################################################ +# Segment to display Swap information prompt_swap() { local swap_used=0 local base='' @@ -1205,6 +1396,7 @@ prompt_swap() { "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$swap_used" $base)" 'SWAP_ICON' } +################################################################ # Symfony2-PHPUnit test ratio prompt_symfony2_tests() { if [[ (-d src && -d app && -f app/AppKernel.php) ]]; then @@ -1216,15 +1408,17 @@ prompt_symfony2_tests() { fi } -# Symfony2-Version +################################################################ +# Segment to display Symfony2-Version 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 } +################################################################ # Show a ratio of tests vs code build_test_stats() { local code_amount="$4" @@ -1240,26 +1434,34 @@ build_test_stats() { (( ratio < 50 )) && "$1_prompt_segment" "$2_BAD" "$3" "red" "$DEFAULT_COLOR" "$headline: $ratio%%" "$6" } +################################################################ # System time prompt_time() { - local time_format="%D{%H:%M:%S}" - if [[ -n "$POWERLEVEL9K_TIME_FORMAT" ]]; then - time_format="$POWERLEVEL9K_TIME_FORMAT" - fi + set_default POWERLEVEL9K_TIME_FORMAT "%D{%H:%M:%S}" - "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$time_format" + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$POWERLEVEL9K_TIME_FORMAT" "TIME_ICON" } +################################################################ +# System date +prompt_date() { + set_default POWERLEVEL9K_DATE_FORMAT "%D{%d.%m.%y}" + + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$POWERLEVEL9K_DATE_FORMAT" "DATE_ICON" +} + +################################################################ # 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 - "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" "$count" 'TODO_ICON' + "$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" "$count" 'TODO_ICON' fi fi } +################################################################ # VCS segment: shows the state of your repository, if you are in a folder under # version control set_default POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND "red" @@ -1325,10 +1527,12 @@ powerlevel9k_vcs_init() { fi } +################################################################ +# Segment to show VCS information prompt_vcs() { VCS_WORKDIR_DIRTY=false VCS_WORKDIR_HALF_DIRTY=false - current_state="" + local current_state="" # Actually invoke vcs_info manually to gather all information. vcs_info @@ -1350,6 +1554,7 @@ prompt_vcs() { fi } +################################################################ # Vi Mode: show editing mode (NORMAL|INSERT) set_default POWERLEVEL9K_VI_INSERT_MODE_STRING "INSERT" set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL" @@ -1359,11 +1564,13 @@ prompt_vi_mode() { "$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "default" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING" ;; main|viins|*) + if [[ -z $POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then return; fi "$1_prompt_segment" "$0_INSERT" "$2" "$DEFAULT_COLOR" "blue" "$POWERLEVEL9K_VI_INSERT_MODE_STRING" ;; esac } +################################################################ # Virtualenv: current working virtualenv # More information on virtualenv (Python): # https://virtualenv.pypa.io/en/latest/ @@ -1374,23 +1581,29 @@ prompt_virtualenv() { fi } +################################################################ # 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 } -# Swift version +################################################################ +# Display openfoam information +prompt_openfoam() { + local wm_project_version="$WM_PROJECT_VERSION" + local wm_fork="$WM_FORK" + if [[ -n "$wm_project_version" ]] && [[ -z "$wm_fork" ]] ; then + "$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 +} + +################################################################ +# Segment to display Swift version prompt_swift_version() { # 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) @@ -1399,30 +1612,67 @@ prompt_swift_version() { "$1_prompt_segment" "$0" "$2" "magenta" "white" "${swift_version}" 'SWIFT_ICON' } +################################################################ # 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) + 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 +} - if [[ -z "$k8s_namespace" ]]; then - k8s_namespace="default" +################################################################ +# Dropbox status +prompt_dropbox() { + # The first column is just the directory, so cut it + local dropbox_status="$(dropbox-cli filestatus . | cut -d\ -f2-)" + + # 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 } +# print Java version number +prompt_java_version() { + local java_version + java_version=$(java -fullversion 2>&1 | cut -d '"' -f 2) + + if [[ -n "$java_version" ]]; then + "$1_prompt_segment" "$0" "$2" "red" "white" "$java_version" "JAVA_ICON" + fi +} ################################################################ # Prompt processing and drawing @@ -1430,6 +1680,7 @@ prompt_kubecontext() { # Main prompt build_left_prompt() { local index=1 + local element for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do # Remove joined information in direct calls element=${element%_joined} @@ -1451,6 +1702,7 @@ build_left_prompt() { # Right prompt build_right_prompt() { local index=1 + local element for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do # Remove joined information in direct calls element=${element%_joined} @@ -1473,6 +1725,7 @@ powerlevel9k_preexec() { set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false powerlevel9k_prepare_prompts() { + local RETVAL RPROMPT_PREFIX RPROMPT_SUFFIX RETVAL=$? RETVALS=( "$pipestatus[@]" ) @@ -1506,11 +1759,28 @@ $(print_icon 'MULTILINE_LAST_PROMPT_PREFIX')' if [[ "$POWERLEVEL9K_DISABLE_RPROMPT" != true ]]; then RPROMPT='$RPROMPT_PREFIX%f%b%k$(build_right_prompt)%{$reset_color%}$RPROMPT_SUFFIX' fi -NEWLINE=' + +local NEWLINE=' ' - [[ $POWERLEVEL9K_PROMPT_ADD_NEWLINE == true ]] && PROMPT="$NEWLINE$PROMPT" + + if [[ $POWERLEVEL9K_PROMPT_ADD_NEWLINE == true ]]; then + NEWLINES="" + repeat ${POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT:-1} { NEWLINES+=$NEWLINE } + PROMPT="$NEWLINES$PROMPT" + fi + + # Allow iTerm integration to work + [[ $ITERM_SHELL_INTEGRATION_INSTALLED == "Yes" ]] && PROMPT="%{$(iterm2_prompt_mark)%}$PROMPT" +} + +zle-keymap-select () { + zle reset-prompt + zle -R } +set_default POWERLEVEL9K_IGNORE_TERM_COLORS false +set_default POWERLEVEL9K_IGNORE_TERM_LANG false + prompt_powerlevel9k_setup() { # The value below was set to better support 32-bit CPUs. # It's the maximum _signed_ integer value on 32-bit CPUs. @@ -1530,23 +1800,18 @@ 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 less 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 - term_lang=$(echo $LANG) - if [[ $term_lang == 'C' ]]; then - 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." + if [[ $POWERLEVEL9K_IGNORE_TERM_LANG == false ]]; then + local term_lang + term_lang=$(echo $LANG) + if [[ $term_lang == 'C' ]]; then + 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." + fi fi defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) @@ -1579,6 +1844,8 @@ prompt_powerlevel9k_setup() { # prepare prompts add-zsh-hook precmd powerlevel9k_prepare_prompts add-zsh-hook preexec powerlevel9k_preexec + + zle -N zle-keymap-select } prompt_powerlevel9k_teardown() { |