From 59e64c90512f4c67340e4baf37f0a22d41f765cc Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Fri, 21 Apr 2017 00:06:28 +0400 Subject: host and user segments --- powerlevel9k.zsh-theme | 57 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index bbd1ec44..c791a845 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -567,6 +567,61 @@ prompt_context() { "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" } +################################################################ +# 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() { + local current_state="DEFAULT" + typeset -AH user_state + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + if [[ $(print -P "%#") == '#' ]]; then + user_state=( + "STATE" "ROOT" + "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "yellow" + "VISUAL_IDENTIFIER" "ROOT_ICON" + ) + elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then + user_state=( + "STATE" "DEFAULT" + "CONTENT" "$USER" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "011" + "VISUAL_IDENTIFIER" "USER_ICON" + ) + fi + fi + "$1_prompt_segment" "${0}_${user_state[STATE]}" "$2" "${user_state[BACKGROUND_COLOR]}" "${user_state[FOREGROUND_COLOR]}" "${user_state[CONTENT]}" "${user_state[VISUAL_IDENTIFIER]}" +} + +################################################################ +# Host: machine (where am I) +set_default POWERLEVEL9K_HOST_TEMPLATE "%m" +prompt_host() { + local current_state="LOCAL" + typeset -AH host_state + if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then + host_state=( + "STATE" "REMOTE" + "CONTENT" "${POWERLEVEL9K_HOST_TEMPLATE}" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "yellow" + "VISUAL_IDENTIFIER" "SSH_ICON" + ) + else + host_state=( + "STATE" "LOCAL" + "CONTENT" "${POWERLEVEL9K_HOST_TEMPLATE}" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "011" + "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() { @@ -664,7 +719,7 @@ prompt_dir() { break; fi done - + local packageName=$(jq '.name' ${pkgFile} 2> /dev/null \ || node -e 'console.log(require(process.argv[1]).name);' ${pkgFile} 2>/dev/null \ || cat "${pkgFile}" 2> /dev/null | grep -m 1 "\"name\"" | awk -F ':' '{print $2}' | awk -F '"' '{print $2}' 2>/dev/null \ -- cgit v1.2.3 From 94ff40d2d1823f805f58759b1420e6fe15e28001 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Thu, 27 Apr 2017 22:16:20 +0400 Subject: Removed POWERLEVEL9K_ALWAYS_SHOW_CONTEXT --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c791a845..0ae046d5 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -574,7 +574,7 @@ set_default POWERLEVEL9K_USER_TEMPLATE "%n" prompt_user() { local current_state="DEFAULT" typeset -AH user_state - if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then if [[ $(print -P "%#") == '#' ]]; then user_state=( "STATE" "ROOT" @@ -583,7 +583,7 @@ prompt_user() { "FOREGROUND_COLOR" "yellow" "VISUAL_IDENTIFIER" "ROOT_ICON" ) - elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then + else user_state=( "STATE" "DEFAULT" "CONTENT" "$USER" -- cgit v1.2.3 From 98a00d31a802887250b359793c371e64cf951e67 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 1 May 2017 21:28:22 -0400 Subject: Merge branch 'battery' of https://github.com/onaforeignshore/powerlevel9k into onaforeignshore-battery --- README.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++--- powerlevel9k.zsh-theme | 21 +++++++++++++++++--- 2 files changed, 67 insertions(+), 6 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index ad2a3e9f..2faeeb8e 100644 --- a/README.md +++ b/README.md @@ -184,9 +184,8 @@ your `~/.zshrc`: ##### battery -This segment will display your current battery status (fails gracefully on -systems without a battery). It is supported on both OSX and Linux (note that it -requires `acpi` on Linux). +The default settings for this segment will display your current battery status (fails gracefully on +systems without a battery). It is supported on both OSX and Linux (note that it requires `acpi` on Linux). | Variable | Default Value | Description | |----------|---------------|-------------| @@ -201,6 +200,53 @@ Note that you can [modify the `_FOREGROUND` color](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization) without affecting the icon color. +The battery segment can also be extended to change the icon automatically depending on the battery level. +This will override the default battery icon. In order to do this, you need to define the +`POWERLEVEL9k_BATTERY_STAGES` variable. + +| Variable | Default Value | Description | +| `POWERLEVEL9K_BATTERY_STAGES`|Unset|A string or array to indicate the stages.| + +If you want to use a string, you can declare the variable as follows: +```zsh +POWERLEVEL9K_BATTERY_STAGES="▁▂▃▄▅▆▇█" +``` + +If you require extra spacing after the icon, you will have to set it as an array, +since spaces in the string will be used as one of the stages and you will get a +missing icon. To do this, declare the variable as follows: +```zsh +POWERLEVEL9K_BATTERY_STAGES=($'\u2581 ' $'\u2582 ' $'\u2583 ' $'\u2584 ' $'\u2585 ' $'\u2586 ' $'\u2587 ' $'\u2588 ') +``` + +You can also use a multiple character "icon" if you want a longer battery icon. To do +this, declare the variable as follows: +```zsh +POWERLEVEL9K_BATTERY_STAGES=( + $'▏ ▏' $'▎ ▏' $'▍ ▏' $'▌ ▏' $'▋ ▏' $'▊ ▏' $'▉ ▏' $'█ ▏' + $'█▏ ▏' $'█▎ ▏' $'█▍ ▏' $'█▌ ▏' $'█▋ ▏' $'█▊ ▏' $'█▉ ▏' $'██ ▏' + $'██ ▏' $'██▎ ▏' $'██▍ ▏' $'██▌ ▏' $'██▋ ▏' $'██▊ ▏' $'██▉ ▏' $'███ ▏' + $'███ ▏' $'███▎ ▏' $'███▍ ▏' $'███▌ ▏' $'███▋ ▏' $'███▊ ▏' $'███▉ ▏' $'████ ▏' + $'████ ▏' $'████▎▏' $'████▍▏' $'████▌▏' $'████▋▏' $'████▊▏' $'████▉▏' $'█████▏' ) +``` + +It is now also possible to change the background of the segment automatically depending on +the battery level. This will override the following variables: `POWERLEVEL9K_BATTERY_CHARGING`, +`POWERLEVEL9K_BATTERY_CHARGED`, `POWERLEVEL9K_BATTERY_DISCONNECTED`, and `POWERLEVEL9K_BATTERY_LOW_COLOR`. +In order to do this, we define a color array (from low to high) as follows: +```zsh +POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND=(196 202 208 214 220 226 190 154 118 82 46) +``` + +|Brightness|Possible Array| +|Bright Colors|(196 202 208 214 220 226 190 154 118 82 46)| +|Normal Colors|(124 130 136 142 148 112 76 40 34 28 22)| +|Subdued Colors|( 88 94 100 106 70 34 28 22)| + +Please note the following: +* an array declarations start with `(` and end with `)`. +* both the icon and background changing levels are automatically calculated, so they can be any length. + ##### command_execution_time Display the time the previous command took to execute if the time is above diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3eba616c..e7665225 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -468,9 +468,24 @@ prompt_battery() { message="$bat_percent%%" fi - # Draw the prompt_segment - if [[ -n $bat_percent ]]; then - "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON' + # 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 + + # override the default color if we are using a color level array + if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then + local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) + local offset=$(( ($bat_percent / $segment) + 1 )) + "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + else + # Draw the prompt_segment + "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" fi } -- cgit v1.2.3 From e6c37b6bc5ba26928ce75720d7fa1c2addb5ccac Mon Sep 17 00:00:00 2001 From: guixxx Date: Sun, 7 May 2017 10:34:54 -0300 Subject: Icons for Windows/Cygwin + Refixes 32-bit support --- functions/icons.zsh | 4 ++++ functions/utilities.zsh | 4 ++++ powerlevel9k.zsh-theme | 10 +++++----- 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/icons.zsh b/functions/icons.zsh index c2cdcba5..7b3bba78 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -42,6 +42,7 @@ case $POWERLEVEL9K_MODE in MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' APPLE_ICON $'\uE26E' #  + WINDOWS_ICON $'\uE26F' #  FREEBSD_ICON $'\U1F608 ' # 😈 ANDROID_ICON $'\uE270' #  LINUX_ICON $'\uE271' #  @@ -112,6 +113,7 @@ case $POWERLEVEL9K_MODE in MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON $'\uF179' #  + WINDOWS_ICON $'\uF17A' #  FREEBSD_ICON $'\U1F608 ' # 😈 ANDROID_ICON $'\uE17B' #  LINUX_ICON $'\uF17C' #  @@ -178,6 +180,7 @@ case $POWERLEVEL9K_MODE in MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON $'\uF179' #  + WINDOWS_ICON $'\uF17A' #  FREEBSD_ICON $'\UF30E ' #  ANDROID_ICON $'\uF17B' #  LINUX_ICON $'\uF17C' #  @@ -244,6 +247,7 @@ case $POWERLEVEL9K_MODE in MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\u2500' MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\u2500 ' APPLE_ICON 'OSX' + WINDOWS_ICON 'WIN' FREEBSD_ICON 'BSD' ANDROID_ICON 'And' LINUX_ICON 'Lx' diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 86e5ba0e..9bd82060 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -85,6 +85,10 @@ case $(uname) in OS='OSX' OS_ICON=$(print_icon 'APPLE_ICON') ;; + CYGWIN_NT-*) + OS='Windows' + OS_ICON=$(print_icon 'WINDOWS_ICON') + ;; FreeBSD) OS='BSD' OS_ICON=$(print_icon 'FREEBSD_ICON') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 19da5bc9..757db12e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1295,7 +1295,7 @@ powerlevel9k_prepare_prompts() { _P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START)) # Reset start time - _P9K_TIMER_START=0xFFFFFFFF + _P9K_TIMER_START=0x7FFFFFFF if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then PROMPT='$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%f%b%k$(build_left_prompt) @@ -1328,12 +1328,12 @@ NEWLINE=' } prompt_powerlevel9k_setup() { - # I decided to use the value below for better supporting 32-bit CPUs, since the previous value "99999999999" was causing issues on my Android phone, which is powered by an armv7l - # We don't have to change that until 19 January of 2038! :) + # The value below was set to better support 32-bit CPUs. + # It's the maximum _signed_ integer value on 32-bit CPUs. + # Please don't change it until 19 January of 2038. ;) # Disable false display of command execution time - # Maximum integer on 32-bit CPUs - _P9K_TIMER_START=2147483647 + _P9K_TIMER_START=0x7FFFFFFF # The prompt function will set these prompt_* options after the setup function # returns. We need prompt_subst so we can safely run commands in the prompt -- cgit v1.2.3 From 543bd2f844c561dea4e7900dd934a007b737331f Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Wed, 3 May 2017 23:53:59 -0400 Subject: status: add option for support pipes Added new option (POWERLEVEL9K_STATUS_SHOW_PIPESTATUS) that shows the status for all piped commands, not just the right-most. Closes #514 --- README.md | 1 + powerlevel9k.zsh-theme | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index caeeccbb..6d3a1fc2 100644 --- a/README.md +++ b/README.md @@ -463,6 +463,7 @@ This segment shows the return code of the last command. |----------|---------------|-------------| |`POWERLEVEL9K_STATUS_VERBOSE`|`true`|Set to false if you wish to not show the error code when the last command returned an error and optionally hide this segment when the last command completed successfully by setting `POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE` to false.| |`POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE`|`false`|Set to true if you wish to show this segment when the last command completed successfully in non-verbose mode.| +|`POWERLEVEL9K_STATUS_SHOW_PIPESTATUS`|`false`|Set to true if you wish to show the exit status for all piped commands.| ##### ram diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2d664911..eb3cc8ab 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1019,10 +1019,30 @@ prompt_ssh() { # Status: return code if verbose, otherwise just an icon if an error occurred set_default POWERLEVEL9K_STATUS_VERBOSE true set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false +set_default POWERLEVEL9K_STATUS_SHOW_PIPESTATUS false prompt_status() { - if [[ "$RETVAL" -ne 0 ]]; then + local ec_text + local ec_sum + local ec + + if [[ $POWERLEVEL9K_STATUS_SHOW_PIPESTATUS == true ]]; then + ec_text=${RETVALS[1]} + ec_sum=${RETVALS[1]} + + for ec in "${(@)RETVALS[2,-1]}"; do + ec_text="${ec_text}|${ec}" + ec_sum=$(( $ec_sum + $ec )) + done + else + # We use RETVAL instead of the right-most RETVALS item because + # PIPE_FAIL may be set. + ec_text=${RETVAL} + ec_sum=${RETVAL} + fi + + if (( ec_sum > 0 )); then if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then - "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$RETVAL" 'CARRIAGE_RETURN_ICON' + "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$ec_text" 'CARRIAGE_RETURN_ICON' else "$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON' fi @@ -1306,6 +1326,7 @@ powerlevel9k_preexec() { set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false powerlevel9k_prepare_prompts() { RETVAL=$? + RETVALS=( "$pipestatus[@]" ) _P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START)) -- cgit v1.2.3 From 25a6c3a4a8f2c8882d89c5634400bb57a82f3a04 Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Fri, 12 May 2017 22:13:37 -0400 Subject: pipestatus: default to true (on) --- README.md | 2 +- powerlevel9k.zsh-theme | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index 6d3a1fc2..cec4c746 100644 --- a/README.md +++ b/README.md @@ -463,7 +463,7 @@ This segment shows the return code of the last command. |----------|---------------|-------------| |`POWERLEVEL9K_STATUS_VERBOSE`|`true`|Set to false if you wish to not show the error code when the last command returned an error and optionally hide this segment when the last command completed successfully by setting `POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE` to false.| |`POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE`|`false`|Set to true if you wish to show this segment when the last command completed successfully in non-verbose mode.| -|`POWERLEVEL9K_STATUS_SHOW_PIPESTATUS`|`false`|Set to true if you wish to show the exit status for all piped commands.| +|`POWERLEVEL9K_STATUS_SHOW_PIPESTATUS`|`true`|Set to true if you wish to show the exit status for all piped commands.| ##### ram diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index eb3cc8ab..0f2445e6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1019,7 +1019,7 @@ prompt_ssh() { # Status: return code if verbose, otherwise just an icon if an error occurred set_default POWERLEVEL9K_STATUS_VERBOSE true set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false -set_default POWERLEVEL9K_STATUS_SHOW_PIPESTATUS false +set_default POWERLEVEL9K_STATUS_SHOW_PIPESTATUS true prompt_status() { local ec_text local ec_sum -- cgit v1.2.3 From 1619c74ad8aff47383989efadc1e4553a83cf4de Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Thu, 4 May 2017 02:32:18 -0400 Subject: newline: add new segment --- README.md | 8 ++++++++ powerlevel9k.zsh-theme | 15 +++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index caeeccbb..b52edeb7 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,7 @@ The segments that are currently available are: * [`command_execution_time`](#command_execution_time) - Display the time the current command took to execute. * [`todo`](http://todotxt.com/) - Shows the number of tasks in your todo.txt tasks file. * `detect_virt` - Virtualization detection with systemd +* `newline` - Continues the prompt on a new line. --------------------------------------------------------------------------------- @@ -442,6 +443,13 @@ segment will not be displayed. |`POWERLEVEL9K_PUBLIC_IP_METHODS`|(dig curl wget)| These methods in that order are used to refresh your IP.| |`POWERLEVEL9K_PUBLIC_IP_NONE`|None|The string displayed when an IP was not obtained| +##### newline + +Puts a newline in your prompt so you can continue using segments on the next line. + +This allows you to use segments on both lines, unlike `POWERLEVEL9K_PROMPT_ON_NEWLINE` and +`POWERLEVEL9K_RPROMPT_ON_NEWLINE`. + ##### rbenv This segment shows the version of Ruby being used when using `rbenv` to change your current Ruby stack. diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2d664911..83c5966e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -337,6 +337,21 @@ prompt_background_jobs() { fi } +# A newline in your prompt, so you can segments on multiple lines. +prompt_newline() { + local lws rws + lws=$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS + rws=$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS + POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS= + POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS= + "$1_prompt_segment" \ + "$0" \ + "$2" \ + "NONE" "NONE" $'\n' + POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws + POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS=$rws +} + # Segment that indicates usage level of current partition. set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false set_default POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90 -- cgit v1.2.3 From 161c995625fc655eb3228a88f5ce1ad79fd1ede0 Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Thu, 4 May 2017 02:44:37 -0400 Subject: newline: can't work with right side --- README.md | 5 +++-- powerlevel9k.zsh-theme | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index b52edeb7..bc9b4462 100644 --- a/README.md +++ b/README.md @@ -447,8 +447,9 @@ segment will not be displayed. Puts a newline in your prompt so you can continue using segments on the next line. -This allows you to use segments on both lines, unlike `POWERLEVEL9K_PROMPT_ON_NEWLINE` and -`POWERLEVEL9K_RPROMPT_ON_NEWLINE`. +This allows you to use segments on both lines, unlike `POWERLEVEL9K_PROMPT_ON_NEWLINE`. + +This only works on the left side. On the right side it does nothing. ##### rbenv diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 83c5966e..bcce12f4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -339,17 +339,15 @@ prompt_background_jobs() { # A newline in your prompt, so you can segments on multiple lines. prompt_newline() { - local lws rws + local lws + [[ "$1" == "right" ]] && return lws=$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS - rws=$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS= - POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS= "$1_prompt_segment" \ "$0" \ "$2" \ "NONE" "NONE" $'\n' POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws - POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS=$rws } # Segment that indicates usage level of current partition. -- cgit v1.2.3 From e9e3e9dc538edc82bf8071919eca2fc9c56292a5 Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Fri, 12 May 2017 21:07:50 -0400 Subject: newline: support PROMPT_ON_NEWLINE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The newline segment will now show ├─ when using `POWERLEVEL9K_PROMPT_ON_NEWLINE` Note: This can be overridden via `POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX` --- functions/icons.zsh | 12 ++++++++---- powerlevel9k.zsh-theme | 8 ++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/icons.zsh b/functions/icons.zsh index 7b3bba78..72e0fbe4 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -39,8 +39,9 @@ case $POWERLEVEL9K_MODE in FAIL_ICON $'\u2718' # ✘ SYMFONY_ICON 'SF' NODE_ICON $'\u2B22' # ⬢ - MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' - MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ + MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON $'\uE26E' #  WINDOWS_ICON $'\uE26F' #  FREEBSD_ICON $'\U1F608 ' # 😈 @@ -111,6 +112,7 @@ case $POWERLEVEL9K_MODE in SYMFONY_ICON 'SF' NODE_ICON $'\u2B22' # ⬢ MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON $'\uF179' #  WINDOWS_ICON $'\uF17A' #  @@ -178,6 +180,7 @@ case $POWERLEVEL9K_MODE in SYMFONY_ICON $'\uE757' #  NODE_ICON $'\uE617 ' #  MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON $'\uF179' #  WINDOWS_ICON $'\uF17A' #  @@ -244,8 +247,9 @@ case $POWERLEVEL9K_MODE in FAIL_ICON $'\u2718' # ✘ SYMFONY_ICON 'SF' NODE_ICON $'\u2B22' # ⬢ - MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\u2500' - MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\u2500 ' + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ + MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON 'OSX' WINDOWS_ICON 'WIN' FREEBSD_ICON 'BSD' diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index bcce12f4..cad455e6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -339,14 +339,18 @@ prompt_background_jobs() { # A newline in your prompt, so you can segments on multiple lines. prompt_newline() { - local lws + local lws newline [[ "$1" == "right" ]] && return + newline=$'\n' lws=$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS + if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then + newline="${newline}$(print_icon 'MULTILINE_NEWLINE_PROMPT_PREFIX')" + fi POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS= "$1_prompt_segment" \ "$0" \ "$2" \ - "NONE" "NONE" $'\n' + "NONE" "NONE" "${newline}" POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws } -- cgit v1.2.3 From 38d5f4d056027984290f97ea60ede9cc74494f3e Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Thu, 4 May 2017 01:27:56 -0400 Subject: nvm: improve default detection This is also (marginally) faster than before. --- powerlevel9k.zsh-theme | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2d664911..d99b6e38 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -889,13 +889,16 @@ prompt_node_version() { # Node version from NVM # Only prints the segment if different than the default value prompt_nvm() { - [[ ! $(type nvm) =~ 'nvm is a shell function'* ]] && return - local node_version=$(nvm current) - [[ -z "${node_version}" ]] || [[ ${node_version} = "none" ]] && return - local nvm_default=$(cat $NVM_DIR/alias/default) + local node_version nvm_default + (( $+functions[nvm_version] )) || return + + node_version=$(nvm_version current) + [[ -z "${node_version}" || ${node_version} == "none" ]] && return + + nvm_default=$(nvm_version default) [[ "$node_version" =~ "$nvm_default" ]] && return - $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' + $1_prompt_segment "$0" "$2" "magenta" "black" "${node_version:1}" 'NODE_ICON' } # NodeEnv Prompt -- cgit v1.2.3 From feb942d4536004ecc862d6c6447599359b64c96a Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Thu, 4 May 2017 02:20:29 -0400 Subject: add function to disable powerlevel9k Sometimes you have to disable your prompt. :-( --- powerlevel9k.zsh-theme | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2d664911..ab7ec346 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1412,4 +1412,9 @@ prompt_powerlevel9k_setup() { add-zsh-hook preexec powerlevel9k_preexec } +prompt_powerlevel9k_teardown() { + add-zsh-hook -D precmd powerlevel9k_\* + add-zsh-hook -D preexec powerlevel9k_\* +} + prompt_powerlevel9k_setup "$@" -- cgit v1.2.3 From 382c8215390373430ae07eea0858e2b3dc97689c Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Fri, 12 May 2017 21:30:42 -0400 Subject: teardown: reset PROMPT and RPROMPT --- powerlevel9k.zsh-theme | 2 ++ 1 file changed, 2 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index ab7ec346..28c606d6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1415,6 +1415,8 @@ prompt_powerlevel9k_setup() { prompt_powerlevel9k_teardown() { add-zsh-hook -D precmd powerlevel9k_\* add-zsh-hook -D preexec powerlevel9k_\* + PROMPT='%m%# ' + RPROPT= } prompt_powerlevel9k_setup "$@" -- cgit v1.2.3 From e0a6246ecc81e94e1f402cac1ddd67d34c1ac5a1 Mon Sep 17 00:00:00 2001 From: Christian Rebischke Date: Sun, 21 May 2017 15:04:24 +0200 Subject: swapped colors for virtualization detection, black on yellow was pain for the eyes --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2d664911..4f30a831 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -790,12 +790,12 @@ prompt_detect_virt() { if [[ "$virt" == "none" ]]; then if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then virt="chroot" - "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$virt" + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt" else ; fi else - "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$virt" + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt" fi } -- cgit v1.2.3 From e844fc4c72e20f84d8022ff9591e75d4a30886cf Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 22 May 2017 21:12:59 -0400 Subject: Incorporating @dritter's feedback from #524. --- README.md | 7 ++++--- functions/icons.zsh | 8 ++++---- powerlevel9k.zsh-theme | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index a4608c41..1e52bfb4 100644 --- a/README.md +++ b/README.md @@ -445,9 +445,10 @@ segment will not be displayed. ##### newline -Puts a newline in your prompt so you can continue using segments on the next line. - -This allows you to use segments on both lines, unlike `POWERLEVEL9K_PROMPT_ON_NEWLINE`. +Puts a newline in your prompt so you can continue using segments on the next +line. This allows you to use segments on both lines, unlike +`POWERLEVEL9K_PROMPT_ON_NEWLINE`, which simply separates segments from the +prompt itself. This only works on the left side. On the right side it does nothing. diff --git a/functions/icons.zsh b/functions/icons.zsh index 72e0fbe4..238b6b9e 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -41,7 +41,7 @@ case $POWERLEVEL9K_MODE in NODE_ICON $'\u2B22' # ⬢ MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ - MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON $'\uE26E' #  WINDOWS_ICON $'\uE26F' #  FREEBSD_ICON $'\U1F608 ' # 😈 @@ -113,7 +113,7 @@ case $POWERLEVEL9K_MODE in NODE_ICON $'\u2B22' # ⬢ MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ - MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON $'\uF179' #  WINDOWS_ICON $'\uF17A' #  FREEBSD_ICON $'\U1F608 ' # 😈 @@ -181,7 +181,7 @@ case $POWERLEVEL9K_MODE in NODE_ICON $'\uE617 ' #  MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ - MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON $'\uF179' #  WINDOWS_ICON $'\uF17A' #  FREEBSD_ICON $'\UF30E ' #  @@ -249,7 +249,7 @@ case $POWERLEVEL9K_MODE in NODE_ICON $'\u2B22' # ⬢ MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ - MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON 'OSX' WINDOWS_ICON 'WIN' FREEBSD_ICON 'BSD' diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e4629646..ec10be85 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1352,7 +1352,7 @@ powerlevel9k_prepare_prompts() { if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then PROMPT='$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%f%b%k$(build_left_prompt) -$(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')' +$(print_icon 'MULTILINE_LAST_PROMPT_PREFIX')' 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 -- cgit v1.2.3 From a7409272ac215a4cdb9b8ac17fe78b521306c383 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 22 May 2017 21:20:56 -0400 Subject: Fixing typo in #525 to teardown `RPROMPT` --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2138f54b..291439ef 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1454,7 +1454,7 @@ prompt_powerlevel9k_teardown() { add-zsh-hook -D precmd powerlevel9k_\* add-zsh-hook -D preexec powerlevel9k_\* PROMPT='%m%# ' - RPROPT= + RPROMPT= } prompt_powerlevel9k_setup "$@" -- cgit v1.2.3 From cf806f097b42c798223d6dc68ff551b4fc90ea43 Mon Sep 17 00:00:00 2001 From: Christo Kotze Date: Tue, 23 May 2017 19:14:52 +0400 Subject: updated render check logic --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0ae046d5..d7ae04ff 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -574,7 +574,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" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]]; then if [[ $(print -P "%#") == '#' ]]; then user_state=( "STATE" "ROOT" @@ -592,8 +592,8 @@ prompt_user() { "VISUAL_IDENTIFIER" "USER_ICON" ) fi + "$1_prompt_segment" "${0}_${user_state[STATE]}" "$2" "${user_state[BACKGROUND_COLOR]}" "${user_state[FOREGROUND_COLOR]}" "${user_state[CONTENT]}" "${user_state[VISUAL_IDENTIFIER]}" fi - "$1_prompt_segment" "${0}_${user_state[STATE]}" "$2" "${user_state[BACKGROUND_COLOR]}" "${user_state[FOREGROUND_COLOR]}" "${user_state[CONTENT]}" "${user_state[VISUAL_IDENTIFIER]}" } ################################################################ -- cgit v1.2.3 From d8d6c752fdeabf4de96ba96a361069e1fe8e65da Mon Sep 17 00:00:00 2001 From: Jordan Taylor Date: Fri, 26 May 2017 09:02:14 -0400 Subject: added the current context prompt for your kubectl config --- powerlevel9k.zsh-theme | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 666ce965..fa2e94ab 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1353,6 +1353,20 @@ prompt_dir_writable() { fi } +# Kubernetes Current Context +prompt_kubecontext() { + local kubectl=$(kubectl version 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) + "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace \u2388" + fi +} + + ################################################################ # Prompt processing and drawing ################################################################ -- cgit v1.2.3 From c11c3a55de2be5a9e11b55426d0afbca43aace4d Mon Sep 17 00:00:00 2001 From: Jason Hutchinson Date: Fri, 26 May 2017 13:27:17 -0500 Subject: use p9k print_icon for kubecontext segment --- functions/icons.zsh | 4 ++++ powerlevel9k.zsh-theme | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/icons.zsh b/functions/icons.zsh index 238b6b9e..e38d66a2 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -84,6 +84,7 @@ case $POWERLEVEL9K_MODE in LOCK_ICON $'\UE138' #  EXECUTION_TIME_ICON $'\UE89C' #  SSH_ICON '(ssh)' + KUBERNETES_ICON $'\U2388' # ⎈ ) ;; 'awesome-fontconfig') @@ -152,6 +153,7 @@ case $POWERLEVEL9K_MODE in LOCK_ICON $'\UE138' #  EXECUTION_TIME_ICON $'\uF253' SSH_ICON '(ssh)' + KUBERNETES_ICON $'\U2388' # ⎈ ) ;; 'nerdfont-complete'|'nerdfont-fontconfig') @@ -220,6 +222,7 @@ case $POWERLEVEL9K_MODE in LOCK_ICON $'\UF023' #  EXECUTION_TIME_ICON $'\uF252' #  SSH_ICON $'\uF489' #  + KUBERNETES_ICON $'\U2388' # ⎈ ) ;; *) @@ -288,6 +291,7 @@ case $POWERLEVEL9K_MODE in LOCK_ICON $'\UE0A2' EXECUTION_TIME_ICON 'Dur' SSH_ICON '(ssh)' + KUBERNETES_ICON $'\U2388' # ⎈ ) ;; esac diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index fa2e94ab..0d794a85 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1362,7 +1362,7 @@ prompt_kubecontext() { 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) - "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace \u2388" + "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace" "KUBERNETES_ICON" fi } -- cgit v1.2.3 From 932e4edeaf5508a65e269e88668b588f2e6cac0f Mon Sep 17 00:00:00 2001 From: Jason Hutchinson Date: Fri, 26 May 2017 13:29:06 -0500 Subject: fix variable name typo --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0d794a85..d86dfe27 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1355,9 +1355,9 @@ prompt_dir_writable() { # Kubernetes Current Context prompt_kubecontext() { - local kubectl=$(kubectl version 2>/dev/null) + local kubectl_version=$(kubectl version 2>/dev/null) - if [[ -n "kubectl_version" ]]; then + 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 -- cgit v1.2.3 From 6f0c809a7dd81a277b7c1ec5bf9b7272ef9e3d7f Mon Sep 17 00:00:00 2001 From: Jason Hutchinson Date: Fri, 26 May 2017 13:34:11 -0500 Subject: empty namespace value is 'default' --- powerlevel9k.zsh-theme | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d86dfe27..668748d2 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1362,6 +1362,10 @@ prompt_kubecontext() { 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) + + if [[ -z "$k8s_namespace" ]]; then + k8s_namespace="default" + fi "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace" "KUBERNETES_ICON" fi } -- cgit v1.2.3 From 5eec2e28d0e44b2ac168fc3e08a38d68d4cb4fbe Mon Sep 17 00:00:00 2001 From: David Sabatie Date: Wed, 31 May 2017 17:32:42 +0200 Subject: add vpn ip to prompt --- README.md | 9 +++++++++ functions/icons.zsh | 16 ++++++++++------ powerlevel9k.zsh-theme | 11 +++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index 890875ad..5b9cb24a 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ The segments that are currently available are: * `history` - The command number for the current line. * [`host`](#host) - Your current host name * [`ip`](#ip) - Shows the current IP address. +* [`vpn`](#vpn) - Shows the current VPN IP address. * [`public_ip`](#public_ip) - Shows your public IP address. * `load` - Your machine's load averages. * `os_icon` - Display a nice little icon, depending on your operating system. @@ -444,6 +445,14 @@ specify the correct network interface by setting: |----------|---------------|-------------| |`POWERLEVEL9K_IP_INTERFACE`|None|The NIC for which you wish to display the IP address. Example: `eth0`.| +##### vpn + +This segment tries to extract the VPN related IP addresses from nmcli, based on the NIC type: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_VPN_IP_INTERFACE`|tun|The VPN NIC type| + ##### public_ip This segment will display your public IP address. There are several methods of obtaining this diff --git a/functions/icons.zsh b/functions/icons.zsh index 238b6b9e..9b5953e3 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -84,6 +84,7 @@ case $POWERLEVEL9K_MODE in LOCK_ICON $'\UE138' #  EXECUTION_TIME_ICON $'\UE89C' #  SSH_ICON '(ssh)' + VPN_ICON '(vpn)' ) ;; 'awesome-fontconfig') @@ -145,13 +146,14 @@ case $POWERLEVEL9K_MODE in VCS_GIT_GITLAB_ICON $'\uF296 ' #  VCS_HG_ICON $'\uF0C3 ' #  VCS_SVN_ICON '(svn) ' - RUST_ICON $'\uE6A8' #  + RUST_ICON $'\uE6A8' #  PYTHON_ICON $'\U1F40D' # 🐍 SWIFT_ICON '' PUBLIC_IP_ICON '' LOCK_ICON $'\UE138' #  EXECUTION_TIME_ICON $'\uF253' SSH_ICON '(ssh)' + VPN_ICON $'\uF023' ) ;; 'nerdfont-complete'|'nerdfont-fontconfig') @@ -174,7 +176,7 @@ case $POWERLEVEL9K_MODE in TEST_ICON $'\uF188' #  TODO_ICON $'\uF133' #  BATTERY_ICON $'\UF240 ' #  - DISK_ICON $'\uF0A0' #  + DISK_ICON $'\uF0A0' #  OK_ICON $'\uF00C' #  FAIL_ICON $'\uF00D' #  SYMFONY_ICON $'\uE757' #  @@ -210,16 +212,17 @@ case $POWERLEVEL9K_MODE in VCS_GIT_ICON $'\uF113 ' #  VCS_GIT_GITHUB_ICON $'\uE709 ' #  VCS_GIT_BITBUCKET_ICON $'\uE703 ' #  - VCS_GIT_GITLAB_ICON $'\uF296 ' #  + VCS_GIT_GITLAB_ICON $'\uF296 ' #  VCS_HG_ICON $'\uF0C3 ' #  VCS_SVN_ICON $'\uE72D ' #  RUST_ICON $'\uE7A8 ' #  PYTHON_ICON $'\UE73C ' #  SWIFT_ICON $'\uE755' #  PUBLIC_IP_ICON $'\UF0AC' #  - LOCK_ICON $'\UF023' #  - EXECUTION_TIME_ICON $'\uF252' #  - SSH_ICON $'\uF489' #  + LOCK_ICON $'\UF023' #  + EXECUTION_TIME_ICON $'\uF252' #  + SSH_ICON $'\uF489' #  + VPN_ICON '(vpn)' ) ;; *) @@ -288,6 +291,7 @@ case $POWERLEVEL9K_MODE in LOCK_ICON $'\UE0A2' EXECUTION_TIME_ICON 'Dur' SSH_ICON '(ssh)' + VPN_ICON '(vpn)' ) ;; esac diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 666ce965..760de5a9 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -914,6 +914,17 @@ prompt_ip() { "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON' } +set_default POWERLEVEL9K_VPN_IP_INTERFACE "tun" +# prompt if vpn active +prompt_vpn_ip() { + for vpn_iface in $(ip tuntap | grep -e ^"$POWERLEVEL9K_VPN_IP_INTERFACE" | cut -d":" -f1) + do + ip=$(ip -4 a show "$vpn_iface" | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*") + "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON' + done +} + + prompt_load() { # The load segment can have three different states local current_state="unknown" -- cgit v1.2.3 From 9a3d2e4ca14897c98f5215c5961a1a3cfd214da2 Mon Sep 17 00:00:00 2001 From: David Sabatie Date: Sat, 3 Jun 2017 20:11:24 +0200 Subject: vpn prompt: change "ip" to "ifconfig" to be used on OSX --- powerlevel9k.zsh-theme | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index dc7f0388..5058e3b6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -917,14 +917,13 @@ prompt_ip() { set_default POWERLEVEL9K_VPN_IP_INTERFACE "tun" # prompt if vpn active prompt_vpn_ip() { - for vpn_iface in $(ip tuntap | grep -e ^"$POWERLEVEL9K_VPN_IP_INTERFACE" | cut -d":" -f1) + for vpn_iface in $(/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_VPN_IP_INTERFACE" | cut -d":" -f1) do - ip=$(ip -4 a show "$vpn_iface" | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*") + ip=$(/sbin/ifconfig "$vpn_iface" | grep -o "inet\s.*" | cut -d' ' -f2) "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON' done } - prompt_load() { # The load segment can have three different states local current_state="unknown" -- cgit v1.2.3 From 65c770606b621a9d1cf809345f7baac6c800ff2a Mon Sep 17 00:00:00 2001 From: Pavel Peganov Date: Sun, 11 Jun 2017 04:09:00 +0300 Subject: Fixed RVM segment for usernames with dashes Having a username with a dash, such as mine, `d-side`, currently results in RVM segment displaying the wrong thing, e. g. `side/.rvm/rubies/ruby`. This fixes the issue. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 26ab9cd5..657d691d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -990,7 +990,7 @@ prompt_rvm() { local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') [ "$gemset" != "" ] && gemset="@$gemset" - local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') + local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $NF}') if [[ -n "$version$gemset" ]]; then "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version$gemset" 'RUBY_ICON' -- cgit v1.2.3 From 3dddcf519d2df2164a918a9b64b71510633932b6 Mon Sep 17 00:00:00 2001 From: Derek Bassett Date: Mon, 26 Jun 2017 13:51:41 -0600 Subject: Resolves issue #553 where prompt hangs on kubectl version. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index dc7f0388..534a5892 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1366,7 +1366,7 @@ prompt_dir_writable() { # Kubernetes Current Context prompt_kubecontext() { - local kubectl_version=$(kubectl version 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 -- cgit v1.2.3 From 3bf0f18e266be2a6582736f3e2270bd0d0bc6afc Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Sat, 8 Jul 2017 01:07:40 -0400 Subject: Cleaned up installation directory detection - Used ZSH built-in magic to get the installation directory. - Works with symlinks. - No longer calls out to external program 'dirname'. - Fixed issue with spaces in the path. - No longer leak the variables 'filename' and 'script_location'. --- powerlevel9k.zsh-theme | 67 +++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 42 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index dc7f0388..3773b727 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -17,74 +17,57 @@ ################################################################ ## 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 ' #zstyle ':vcs_info:*+*:*' debug true #set -o xtrace # Try to set the installation path -if [[ -n "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then - # If an installation path was set manually, - # it should trump any other location found. - # Do nothing. This is all right, as we use the - # POWERLEVEL9K_INSTALLATION_PATH for further processing. -elif [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then - # Check if the theme was called as a function (e.g., from prezto) - autoload -U is-at-least - if is-at-least 5.0.8; then - # Try to find the correct path of the script. - POWERLEVEL9K_INSTALLATION_PATH=$(whence -v $0 | sed "s/$0 is a shell function from //") - elif [[ -f "${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/init.zsh" ]]; then - # If there is an prezto installation, we assume that powerlevel9k is linked there. - POWERLEVEL9K_INSTALLATION_PATH="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" - fi +if [[ -n "$POWERLEVEL9K_INSTALLATION_DIR" ]]; then + p9k_directory=${POWERLEVEL9K_INSTALLATION_DIR:A} else - # Last resort: Set installation path is script path - POWERLEVEL9K_INSTALLATION_PATH="$0" -fi - -# Resolve the installation path -if [[ -L "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then - # If this theme is sourced as a symlink, we need to locate the real URL - filename="${POWERLEVEL9K_INSTALLATION_PATH:A}" -elif [[ -d "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then - # Directory - filename="${POWERLEVEL9K_INSTALLATION_PATH}/powerlevel9k.zsh-theme" -elif [[ -f "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then - # Script is a file - filename="$POWERLEVEL9K_INSTALLATION_PATH" -elif [[ -z "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then - # Fallback: specify an installation path! - print -P "%F{red}We could not locate the installation path of powerlevel9k.%f" - print -P "Please specify by setting %F{blue}POWERLEVEL9K_INSTALLATION_PATH%f (full path incl. file name) at the very beginning of your ~/.zshrc" - return 1 -else - print -P "%F{red}Script location could not be found! Maybe your %F{blue}POWERLEVEL9K_INSTALLATION_PATH%F{red} is not correct?%f" - return 1 + 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 + p9k_directory=$PWD + 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 + p9k_directory=${${(%):-%x}:A:h} + fi fi -script_location="$(dirname $filename)" ################################################################ # Source icon functions ################################################################ -source $script_location/functions/icons.zsh +source "${p9k_directory}/functions/icons.zsh" ################################################################ # Source utility functions ################################################################ -source $script_location/functions/utilities.zsh +source "${p9k_directory}/functions/utilities.zsh" ################################################################ # Source color functions ################################################################ -source $script_location/functions/colors.zsh +source "${p9k_directory}/functions/colors.zsh" ################################################################ # Source VCS_INFO hooks / helper functions ################################################################ -source $script_location/functions/vcs.zsh +source "${p9k_directory}/functions/vcs.zsh" + +# cleanup temporary variables. +unset p9k_directory ################################################################ # Color Scheme -- cgit v1.2.3 From aca0f31eb00df91a2b40ac6baea8efb64bd84cab Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Wed, 12 Jul 2017 01:02:46 -0400 Subject: Replaced a sed call with pure ZSH --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 534a5892..2e8c30bb 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -811,7 +811,7 @@ prompt_dir() { fi if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" ]]; then - current_path="$( echo "${current_path}" | sed "s/^~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}/")" + current_path=${current_path/#\~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}} fi typeset -AH dir_states -- cgit v1.2.3 From a4f1ce990b219b4ce66018aa59a72b3c24b69dd9 Mon Sep 17 00:00:00 2001 From: AdrienHorgnies Date: Sat, 15 Jul 2017 21:28:27 +0200 Subject: change status segment option set --- powerlevel9k.zsh-theme | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b08155ed..73682f38 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1087,9 +1087,13 @@ prompt_ssh() { fi } -# Status: return code if verbose, otherwise just an icon if an error occurred +# old options, retro compatibility set_default POWERLEVEL9K_STATUS_VERBOSE true set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false +# 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 +set_default POWERLEVEL9K_STATUS_CROSS false +set_default POWERLEVEL9K_STATUS_OK true set_default POWERLEVEL9K_STATUS_SHOW_PIPESTATUS true prompt_status() { local ec_text @@ -1112,12 +1116,12 @@ prompt_status() { fi if (( ec_sum > 0 )); then - if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then + if [[ "$POWERLEVEL9K_STATUS_CROSS" == false && "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$ec_text" 'CARRIAGE_RETURN_ICON' else "$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON' fi - elif [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true || "$POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE" == true ]]; then + elif [[ "$POWERLEVEL9K_STATUS_OK" == true ]] && [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true || "$POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE" == true ]]; then "$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "green" "" 'OK_ICON' fi } -- cgit v1.2.3 From be6c0320252d2c750884a90664a26b58eb824920 Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Wed, 26 Jul 2017 23:39:49 -0400 Subject: rvm: handle -head, etc. more gracefully. Closes #575 --- powerlevel9k.zsh-theme | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 16904af7..d6ce38f1 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1070,13 +1070,10 @@ prompt_rspec_stats() { # Ruby Version Manager information prompt_rvm() { - local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') - [ "$gemset" != "" ] && gemset="@$gemset" + local version_and_gemset=${rvm_env_string/ruby-} - local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $NF}') - - if [[ -n "$version$gemset" ]]; then - "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version$gemset" 'RUBY_ICON' + if [[ -n "$version_and_gemset" ]]; then + "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON' fi } -- cgit v1.2.3 From f93ad073b792a2bda81a4ffb0584aa398866f81b Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Wed, 26 Jul 2017 22:21:18 -0400 Subject: status: show signal name This makes signal exit status easy to understand. Instead of just showing exit code "137", you now see "KILL(-9)". Based on #580 by @sei40kr (thanks!) --- README.md | 1 + powerlevel9k.zsh-theme | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index dce219ac..dd79cd65 100644 --- a/README.md +++ b/README.md @@ -508,6 +508,7 @@ This segment shows the return code of the last command. |`POWERLEVEL9K_STATUS_CROSS`|`false`|Set to true if you wish not to show the error code when the last command returned an error and optionally hide this segment when the last command completed successfully by setting `POWERLEVEL9K_STATUS_OK` to false.| |`POWERLEVEL9K_STATUS_OK`|`true`|Set to true if you wish to show this segment when the last command completed successfully, false to hide it.| |`POWERLEVEL9K_STATUS_SHOW_PIPESTATUS`|`true`|Set to true if you wish to show the exit status for all piped commands.| +|`POWERLEVEL9K_STATUS_HIDE_SIGNAME`|`false`|Set to true return the raw exit code (`1-255`). When set to true, values over 128 are shown as `SIGNAME(-n)` (e.g. `KILL(-9)`)| ##### ram diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 16904af7..20c59c01 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1086,31 +1086,47 @@ prompt_ssh() { fi } -# old options, retro compatibility -set_default POWERLEVEL9K_STATUS_VERBOSE true -set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false # 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 +# set_default POWERLEVEL9K_STATUS_CROSS false set_default POWERLEVEL9K_STATUS_OK true set_default POWERLEVEL9K_STATUS_SHOW_PIPESTATUS true +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 + if [[ "$POWERLEVEL9K_STATUS_HIDE_SIGNAME" = true ]]; then + echo "$ec" + elif (( ec <= 128 )); then + echo "$ec" + else + local sig=$(( ec - 128 )) + local idx=$(( sig + 1 )) + echo "${signals[$idx]}(-${sig})" + fi +} + prompt_status() { local ec_text local ec_sum local ec if [[ $POWERLEVEL9K_STATUS_SHOW_PIPESTATUS == true ]]; then - ec_text=${RETVALS[1]} + ec_text=$(exit_code_or_status "${RETVALS[1]}") ec_sum=${RETVALS[1]} for ec in "${(@)RETVALS[2,-1]}"; do - ec_text="${ec_text}|${ec}" + ec_text="${ec_text}|$(exit_code_or_status "$ec")" ec_sum=$(( $ec_sum + $ec )) done else # We use RETVAL instead of the right-most RETVALS item because # PIPE_FAIL may be set. - ec_text=${RETVAL} + ec_text=$(exit_code_or_status "${RETVAL}") ec_sum=${RETVAL} fi -- cgit v1.2.3 From 0b298e7df423882ba797b80a4e4b5a9a0546b666 Mon Sep 17 00:00:00 2001 From: Seong Yong-ju Date: Tue, 27 Jun 2017 19:32:24 +0900 Subject: Fixed an issue of indicator of Vi mode Fixed an issue that the indicator of Vi mode won't appear correctly at first. --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 26ab9cd5..015fa41e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1192,12 +1192,12 @@ set_default POWERLEVEL9K_VI_INSERT_MODE_STRING "INSERT" set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL" prompt_vi_mode() { case ${KEYMAP} in - main|viins) - "$1_prompt_segment" "$0_INSERT" "$2" "$DEFAULT_COLOR" "blue" "$POWERLEVEL9K_VI_INSERT_MODE_STRING" - ;; vicmd) "$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "default" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING" ;; + main|viins|*) + "$1_prompt_segment" "$0_INSERT" "$2" "$DEFAULT_COLOR" "blue" "$POWERLEVEL9K_VI_INSERT_MODE_STRING" + ;; esac } -- cgit v1.2.3 From b567ab22c2889726974dcfed543cc9ecb7e190cb Mon Sep 17 00:00:00 2001 From: Richard Tippl Date: Tue, 8 Aug 2017 19:44:20 +0200 Subject: Implemented functionality from dir_writable to dir When variable POWERLEVEL9K_DIR_SHOW_WRITABLE is set to true, dir prompt will have new state NOT_WRITABLE. This state will be set when user doesn't have permission to write in current working directory as in prompt dir_writable. When mode that allows icons is set, LOCK_ICON is used. --- powerlevel9k.zsh-theme | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c2b53374..807495ec 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -802,9 +802,12 @@ prompt_dir() { "DEFAULT" "FOLDER_ICON" "HOME" "HOME_ICON" "HOME_SUBFOLDER" "HOME_SUB_ICON" + "NOT_WRITABLE" "LOCK_ICON" ) local current_state="DEFAULT" - if [[ $(print -P "%~") == '~' ]]; then + if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == "true" && ! -w "$PWD" ]]; then + current_state="NOT_WRITABLE" + elif [[ $(print -P "%~") == '~' ]]; then current_state="HOME" elif [[ $(print -P "%~") == '~'* ]]; then current_state="HOME_SUBFOLDER" -- cgit v1.2.3 From c4a1d91118abe95f4f5ce0580ffe58b452affefa Mon Sep 17 00:00:00 2001 From: Richard Tippl Date: Thu, 10 Aug 2017 17:49:42 +0200 Subject: Added a default value for DIR_SHOW_WRITABLE. Variable POWERLEVEL9K_DIR_SHOW_WRITABLE is now default set to false. --- powerlevel9k.zsh-theme | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 807495ec..8c78cb00 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -689,6 +689,7 @@ prompt_command_execution_time() { # Dir: current working directory set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" +set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false prompt_dir() { local current_path="$(print -P "%~")" if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then @@ -805,7 +806,7 @@ prompt_dir() { "NOT_WRITABLE" "LOCK_ICON" ) local current_state="DEFAULT" - if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == "true" && ! -w "$PWD" ]]; then + if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then current_state="NOT_WRITABLE" elif [[ $(print -P "%~") == '~' ]]; then current_state="HOME" -- cgit v1.2.3 From 99b7ec26b24418329d0ab81f0c649037cc399254 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Thu, 10 Aug 2017 11:56:12 -0700 Subject: Add back the prompt_sp option for zsh >= 5.4.1 In 5.4.1, this option was reset between prompts, so to retain the previous default behavior, this should be added back. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5bd5f586..b21e2ff4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1341,11 +1341,11 @@ prompt_powerlevel9k_setup() { # returns. We need prompt_subst so we can safely run commands in the prompt # without them being double expanded and we need prompt_percent to expand the # common percent escape sequences. - prompt_opts=(subst percent cr) + prompt_opts=(cr percent sp subst) # Borrowed from promptinit, sets the prompt options in case the theme was # not initialized via promptinit. - setopt noprompt{bang,cr,percent,subst} "prompt${^prompt_opts[@]}" + setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" # Display a warning if the terminal does not support 256 colors local term_colors -- cgit v1.2.3 From 73a9ee7c870fcc93182c17f7d9d0c6942116169d Mon Sep 17 00:00:00 2001 From: Miroslav Šedivý <6774676+eumiro@users.noreply.github.com> Date: Fri, 11 Aug 2017 22:44:18 +0200 Subject: add TRUNCATE_TO_UNIQUE shortening dir strategy This creates the shortest unique path elements that can be unambiguously expanded to the original path. --- README.md | 1 + powerlevel9k.zsh-theme | 21 +++++++++++++++++++++ test/segments/dir.spec | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index 1f7dcadb..e428e6d8 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,7 @@ Customizations available are: |`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: "/ro../Pr../office". How many characters will be untouched is controlled by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`.| |`truncate_with_package_name`|Search for a `package.json` or `composer.json` and prints the `name` field to abbreviate the directory path. The precedence and/or files could be set by `POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json)`. If you have [jq](https://stedolan.github.io/jq/) installed, it will dramatically improve the speed of this strategy.| |`truncate_with_folder_marker`|Search for a file that is specified by `POWERLEVEL9K_SHORTEN_FOLDER_MARKER` and truncate everything before that (if found, otherwise stop on $HOME and ROOT).| +|`truncate_to_unique`|Parse all parent path components and truncate them to the shortest unique length. If you copy&paste the result to a shell, after hitting TAB it should expand to the original path unambiguously.| For example, if you wanted the truncation behavior of the `fish` shell, which truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following: diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5bd5f586..3869d262 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -709,6 +709,27 @@ prompt_dir() { # 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 + 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")" ;; diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 3a6af649..dea54750 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -381,4 +381,25 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat unset POWERLEVEL9K_SHORTEN_STRATEGY } +function testTruncateToUniqueWorks() { + POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique' + mkdir -p /tmp/powerlevel9k-test/adam/devl + mkdir -p /tmp/powerlevel9k-test/alice/devl + mkdir -p /tmp/powerlevel9k-test/alice/docs + mkdir -p /tmp/powerlevel9k-test/bob/docs + cd /tmp/powerlevel9k-test/alice/devl + + assertEquals "%K{blue} %F{black}txXxpxXxalxXxde %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + unset POWERLEVEL9K_DIR_PATH_SEPARATOR + unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER + unset POWERLEVEL9K_SHORTEN_DIR_LENGTH + unset POWERLEVEL9K_SHORTEN_STRATEGY +} + source shunit2/source/2.1/src/shunit2 -- cgit v1.2.3 From e464b4e2a559508f9f4e0a9bc28a3b1e7d08fbd6 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sat, 12 Aug 2017 13:49:50 -0400 Subject: Adding reference for `truncate_to_unique` code. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3869d262..3baa50ce 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -711,7 +711,7 @@ prompt_dir() { ;; truncate_to_unique) # for each parent path component find the shortest unique beginning - # characters sequence + # characters sequence. Source: https://stackoverflow.com/a/45336078 paths=(${(s:/:)PWD}) cur_path='/' cur_short_path='/' -- cgit v1.2.3 From 582edf200c825abbc75ec8a643b2e7ecdbd59561 Mon Sep 17 00:00:00 2001 From: Tadek Teleżyński Date: Thu, 17 Aug 2017 21:54:26 +0200 Subject: Add average choice to load extension This commit adds a functionality to choose if one wants to see 1, 5 or 15 minutes average. Resolves issue #604 --- README.md | 13 ++++++++++++- powerlevel9k.zsh-theme | 23 +++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index 9c17c2c5..9c0c3ab5 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ The segments that are currently available are: * [`ip`](#ip) - Shows the current IP address. * [`vpn`](#vpn) - Shows the current VPN IP address. * [`public_ip`](#public_ip) - Shows your public IP address. -* `load` - Your machine's load averages. +* [`load`](#load) - Your machine's load averages. * `os_icon` - Display a nice little icon, depending on your operating system. * `ram` - Show free RAM. * `root_indicator` - An indicator if the user has superuser status. @@ -482,6 +482,17 @@ segment will not be displayed. |`POWERLEVEL9K_PUBLIC_IP_METHODS`|(dig curl wget)| These methods in that order are used to refresh your IP.| |`POWERLEVEL9K_PUBLIC_IP_NONE`|None|The string displayed when an IP was not obtained| +##### load + +Displays one of your load averages with appropriate state coloring. The thresholds are: +- `0.7 * NUM_CORES <`: critical +- `0.5 * NUM_CORES <`: warning +- `less`: normal + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_LOAD_WHICH`|5|Which average to show. Possible values: 1, 5 or 15| + ##### newline Puts a newline in your prompt so you can continue using segments on the next diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3c34f0bb..b03a9374 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -937,6 +937,8 @@ prompt_load() { local current_state="unknown" local cores + set_default POWERLEVEL9K_LOAD_WHICH 5 + typeset -AH load_states load_states=( 'critical' 'red' @@ -945,31 +947,40 @@ prompt_load() { ) if [[ "$OS" == "OSX" ]] || [[ "$OS" == "BSD" ]]; then - load_avg_1min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1) + + if [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 1 ]]; then + load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 1p) + elif [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 5 ]]; then + load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 2p) + else + load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 3p) + fi + if [[ "$OS" == "OSX" ]]; then cores=$(sysctl -n hw.logicalcpu) else cores=$(sysctl -n hw.ncpu) fi else - load_avg_1min=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) + load_avg=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) cores=$(nproc) fi # Replace comma - load_avg_1min=${load_avg_1min//,/.} + load_avg=${load_avg//,/.} - if [[ "$load_avg_1min" -gt $(bc -l <<< "${cores} * 0.7") ]]; then + if [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.7") ]]; then current_state="critical" - elif [[ "$load_avg_1min" -gt $(bc -l <<< "${cores} * 0.5") ]]; then +elif [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.5") ]]; then current_state="warning" else current_state="normal" fi - "$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg_1min" 'LOAD_ICON' + "$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg" 'LOAD_ICON' } + # Node version prompt_node_version() { local node_version=$(node -v 2>/dev/null) -- cgit v1.2.3 From 2c388b6c809189551eab94a8a43346987fdfc330 Mon Sep 17 00:00:00 2001 From: Richard Tippl Date: Sun, 27 Aug 2017 22:42:52 +0200 Subject: Fix average selection in load segment. Removed duplicate code selecting which load average to use. Fixed load average selection being in OSX/BSD part of if, making it not work on non OSX/BSD systems. Optimized actually getting the load average. --- powerlevel9k.zsh-theme | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b03a9374..5aa280c6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -932,13 +932,14 @@ prompt_vpn_ip() { done } +set_default POWERLEVEL9K_LOAD_WHICH 5 prompt_load() { # The load segment can have three different states local current_state="unknown" + local load_select=2 + local load_avg local cores - set_default POWERLEVEL9K_LOAD_WHICH 5 - typeset -AH load_states load_states=( 'critical' 'red' @@ -946,32 +947,38 @@ prompt_load() { 'normal' 'green' ) - if [[ "$OS" == "OSX" ]] || [[ "$OS" == "BSD" ]]; then - - if [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 1 ]]; then - load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 1p) - elif [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 5 ]]; then - load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 2p) - else - load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 3p) - fi + case "$POWERLEVEL9K_LOAD_WHICH" in + 1) + load_select=1 + ;; + 5) + load_select=2 + ;; + 15) + load_select=3 + ;; + esac - if [[ "$OS" == "OSX" ]]; then - cores=$(sysctl -n hw.logicalcpu) - else - cores=$(sysctl -n hw.ncpu) - fi - else - load_avg=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) - cores=$(nproc) - fi + 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 + ;; + *) + load_avg=$(cut -d" " -f${load_select} /proc/loadavg) + cores=$(nproc) + esac # Replace comma load_avg=${load_avg//,/.} if [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.7") ]]; then current_state="critical" -elif [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.5") ]]; then + elif [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.5") ]]; then current_state="warning" else current_state="normal" -- cgit v1.2.3 From 48b4bd1aa4b39bb43dc6e853dd5f4b42cd21700b Mon Sep 17 00:00:00 2001 From: Yann David Date: Thu, 31 Aug 2017 14:15:11 -0400 Subject: Fix prompt_kubecontext:local:1: not valid in this context: Version: --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5aa280c6..322de3b7 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1408,7 +1408,7 @@ prompt_dir_writable() { # Kubernetes Current Context 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 -- cgit v1.2.3 From 692335975cfc10bc35fe04b758395120c04112cd Mon Sep 17 00:00:00 2001 From: trashbat Date: Tue, 5 Sep 2017 15:46:12 +0100 Subject: Changed "less than" to "fewer than". --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5aa280c6..93aca4db 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1533,7 +1533,7 @@ prompt_powerlevel9k_setup() { 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 "%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." -- cgit v1.2.3 From f996d2d6ed3aa82f697f8b96afd57eb3b0593875 Mon Sep 17 00:00:00 2001 From: Hal Gentz Date: Thu, 28 Sep 2017 22:07:37 -0600 Subject: Fixes issue #619 Signed-off-by: Hal Gentz --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7e7b4e11..e3ebf59f 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -570,7 +570,7 @@ prompt_context() { local content="" - if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then if [[ $(print -P "%#") == '#' ]]; then current_state="ROOT" -- cgit v1.2.3 From ec47f1b583d5e40e299f9b4b065fe1626240e5e5 Mon Sep 17 00:00:00 2001 From: Hal Gentz Date: Thu, 28 Sep 2017 22:20:58 -0600 Subject: These probably have similar bugs Signed-off-by: Hal Gentz --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e3ebf59f..97d13a3c 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -579,7 +579,7 @@ prompt_context() { content="${POWERLEVEL9K_CONTEXT_TEMPLATE}" elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then - content="$USER" + content="$(whoami)" else return fi @@ -594,7 +594,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" @@ -606,7 +606,7 @@ prompt_user() { else user_state=( "STATE" "DEFAULT" - "CONTENT" "$USER" + "CONTENT" "$(whoami)" "BACKGROUND_COLOR" "${DEFAULT_COLOR}" "FOREGROUND_COLOR" "011" "VISUAL_IDENTIFIER" "USER_ICON" -- cgit v1.2.3 From 20b69370a679b6c3a8a2084615206d78fe0ae542 Mon Sep 17 00:00:00 2001 From: sbutler2901 Date: Thu, 12 Oct 2017 02:02:45 -0400 Subject: Bug fix for prompt_public_ip. The OSX date command does not have the -r option for getting the last modification time of a file. The stat command is being used instead --- powerlevel9k.zsh-theme | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 97d13a3c..f6646c63 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -507,7 +507,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 -- cgit v1.2.3 From 43e766209b0e6061bbf62c029098cd92a9408c1f Mon Sep 17 00:00:00 2001 From: Brian Moran Date: Fri, 27 Oct 2017 12:11:48 -0400 Subject: ISS-650 Fix PYTHONPATH appearing in prompt - Modify prompt_dir function to set current_path based on pwd and replace $HOME with ~ --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b03a9374..5ba9e43d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -691,7 +691,7 @@ set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false prompt_dir() { - local current_path="$(print -P "%~")" + local current_path=$(pwd | sed -e "s,^$HOME,~,") if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' -- cgit v1.2.3 From 47c7077cde833217db8a4dadbabaf38e6ff490d3 Mon Sep 17 00:00:00 2001 From: Marc Hauptmann Date: Tue, 31 Oct 2017 16:47:21 +0100 Subject: declared variables as 'local' Prevents warning messages from zsh --- powerlevel9k.zsh-theme | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f6646c63..3c173e9f 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1332,7 +1332,7 @@ powerlevel9k_vcs_init() { 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 @@ -1434,6 +1434,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} -- cgit v1.2.3 From 82bc300c625831ac7fc0e6067e1ea460e8fd0e59 Mon Sep 17 00:00:00 2001 From: Antons Kranga Date: Tue, 7 Nov 2017 11:30:23 +0200 Subject: Add support for both AWS_PROFILE and AWS_DEFAULT_PROFILE --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f33d5a9a..73178865 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -287,7 +287,7 @@ prompt_anaconda() { # 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' -- cgit v1.2.3 From 37f24dcc5f2898321a463f6a131020a6ee195f2c Mon Sep 17 00:00:00 2001 From: David Jetelina Date: Tue, 14 Nov 2017 18:58:16 +0100 Subject: Kubernetes segment shorter if possible Fixes #675 --- powerlevel9k.zsh-theme | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 73178865..17f1eac0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1423,7 +1423,18 @@ prompt_kubecontext() { if [[ -z "$k8s_namespace" ]]; then k8s_namespace="default" fi - "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace" "KUBERNETES_ICON" + + local k8s_final_text="" + + if [[ "$k8s_context" == "k8s_namespace" ]]; then + # No reason to print out the same identificator twice + k8s_final_text="k8s_context" + else + k8s_final_text="$k8s_context/$k8s_namespace" + fi + + + "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_final_text" "KUBERNETES_ICON" fi } -- cgit v1.2.3 From b8afde5598d1defe7e300a273dac5efd4194876f Mon Sep 17 00:00:00 2001 From: David Jetelina Date: Tue, 14 Nov 2017 19:01:20 +0100 Subject: added forgotten $ --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 17f1eac0..27608382 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1428,7 +1428,7 @@ prompt_kubecontext() { if [[ "$k8s_context" == "k8s_namespace" ]]; then # No reason to print out the same identificator twice - k8s_final_text="k8s_context" + k8s_final_text="$k8s_context" else k8s_final_text="$k8s_context/$k8s_namespace" fi -- cgit v1.2.3 From bc8a83208f9b4aa8fcc29cc35a0eeec3ae67c5b9 Mon Sep 17 00:00:00 2001 From: dinhnv Date: Wed, 22 Nov 2017 11:30:24 +0700 Subject: pyenv promt segment uses $PYENV_VERSION environment variable" --- powerlevel9k.zsh-theme | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 73178865..b65c2077 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1379,18 +1379,10 @@ 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 } -- cgit v1.2.3 From 6e931f6047994ebb4a83924c298678d059e183d4 Mon Sep 17 00:00:00 2001 From: Torben Hartmann Date: Mon, 27 Nov 2017 21:38:03 +0100 Subject: Fixed Issue with whitespaces in path. --- powerlevel9k.zsh-theme | 3 +++ 1 file changed, 3 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 73178865..5dd394ea 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -695,7 +695,10 @@ 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' -- cgit v1.2.3 From 02fbaf2c4befcc9a291f391a1a045d1a055332c0 Mon Sep 17 00:00:00 2001 From: Torben Hartmann Date: Tue, 5 Dec 2017 17:30:49 +0100 Subject: IFS Fix attemp --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5dd394ea..fb344f25 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -695,10 +695,10 @@ 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 tmp="$IFS" local IFS="" local current_path=$(pwd | sed -e "s,^$HOME,~,") - local IFS=$tmp + local IFS="$tmp" if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' -- cgit v1.2.3 From 3a94826ed198ba9a569c77d163202707cda42530 Mon Sep 17 00:00:00 2001 From: LeMarsu Date: Mon, 15 Jan 2018 08:58:05 +0100 Subject: fix: Remove dependency of bc for load widget --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 97e99f43..14d7bd81 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -983,9 +983,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" -- cgit v1.2.3 From a761e3c28a78cfbf7d7ca9cde5bdcd1126c2996c Mon Sep 17 00:00:00 2001 From: Conrad Haupt Date: Mon, 12 Mar 2018 14:28:17 +0200 Subject: Fixed home abbreviation not being exclusive with circular navigation --- powerlevel9k.zsh-theme | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 14d7bd81..12d05db3 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -809,7 +809,9 @@ prompt_dir() { 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 -- cgit v1.2.3 From fe33c401bac783181e0fc53401685fa9b2ad0e24 Mon Sep 17 00:00:00 2001 From: Christian Höltje Date: Mon, 26 Mar 2018 14:55:06 -0400 Subject: workaround for ZSH status behavior `$pipestatus` is returning all zeros when using `[[ ]]` expressions that are false. This works around it by using `$status` (A.K.A. `$?`) when `$pipestatus` has only 1 items. Fixes #749 --- powerlevel9k.zsh-theme | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 14d7bd81..2255a04a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1163,8 +1163,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")" -- cgit v1.2.3 From 9f7b0b7404a3d5307755d5e55ddc33e2e39090ba Mon Sep 17 00:00:00 2001 From: Ryan Davidson Date: Tue, 3 Apr 2018 13:52:13 +0100 Subject: #777 Add POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW variable to display prompt_rbenv if rbenv_version_name is the same as rbenv_global --- powerlevel9k.zsh-theme | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 14d7bd81..07902ba6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1065,14 +1065,15 @@ 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 + if [[ $rbenv_version_name == $rbenv_global && "$POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW" = false ]]; then return fi @@ -1418,7 +1419,7 @@ prompt_kubecontext() { if [[ -z "$k8s_namespace" ]]; then k8s_namespace="default" fi - + local k8s_final_text="" if [[ "$k8s_context" == "k8s_namespace" ]]; then @@ -1427,8 +1428,8 @@ prompt_kubecontext() { else k8s_final_text="$k8s_context/$k8s_namespace" fi - - + + "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_final_text" "KUBERNETES_ICON" fi } -- cgit v1.2.3