From 30076080a734c0bff552293b8b2d4e7c69019c03 Mon Sep 17 00:00:00 2001 From: Christian Rebischke Date: Sun, 11 Dec 2016 04:39:45 +0100 Subject: added ssh support and POWERLEVEL9K_HIDE_HOST feature refactorized the sourcecode added true/false switch --- powerlevel9k.zsh-theme | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c4b24b55..f2262994 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -434,13 +434,25 @@ prompt_battery() { # Context: user@hostname (who am I and where am I) # Note that if $DEFAULT_USER is not set, this prompt segment will always print prompt_context() { - if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then + local current_state="DEFAULT" + declare -A context_states + context_states=( + "ROOT" "yellow" + "DEFAULT" "011" + ) + local content="$USER" + if [[ "$USER" != "$DEFAULT_USER" ]]; then if [[ $(print -P "%#") == '#' ]]; then - # Shell runs as root - "$1_prompt_segment" "$0_ROOT" "$2" "$DEFAULT_COLOR" "yellow" "$USER@%m" + current_state="ROOT" + fi + if [[ -z "$SSH_CLIENT" && -z "$SSH_TTY" ]]; then + if [[ "$POWERLEVEL9K_HIDE_HOST" == "false" || -z "$POWERLEVEL9K_HIDE_HOST" ]]; then + content="${content}@%m" + fi else - "$1_prompt_segment" "$0_DEFAULT" "$2" "$DEFAULT_COLOR" "011" "$USER@%m" + content="${content}@%m" fi + "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" fi } -- cgit v1.2.3 From b379f03f148d99a0da8c8eb200f17b3007a87e47 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 30 Jan 2017 21:10:09 +0100 Subject: Add ability to omit the first character in dir path --- README.md | 7 +++++-- powerlevel9k.zsh-theme | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index f7a80a09..04632323 100644 --- a/README.md +++ b/README.md @@ -304,9 +304,12 @@ the path shown would be `my-cool-project`. If you navigate to `$HOME/projects/m If you want to customize the directory separator, you could set: ```zsh -# You'll need patched awesome-terminal fonts for that example -POWERLEVEL9K_DIR_PATH_SEPARATOR="%f "$'\uE0B1'" %F" +# Double quotes are important here! +POWERLEVEL9K_DIR_PATH_SEPARATOR="%F{red} $(print_icon 'LEFT_SUBSEGMENT_SEPARATOR') %F{black}" ``` +To omit the first character (usually a slash that gets replaced if you set `POWERLEVEL9K_DIR_PATH_SEPARATOR`), +you could set `POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true`. + ##### disk_usage diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f104b789..3010790e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -616,6 +616,10 @@ prompt_dir() { 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=$(print -P "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g") fi -- cgit v1.2.3 From ebf808c533ed86ede4b5afcf9206c05b832278db Mon Sep 17 00:00:00 2001 From: Benoit Averty Date: Wed, 10 Aug 2016 00:07:04 +0200 Subject: Add dir_truncate_root option --- functions/utilities.zsh | 15 +++++++++++++++ powerlevel9k.zsh-theme | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/utilities.zsh b/functions/utilities.zsh index f27c7f99..8263ce10 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -208,3 +208,18 @@ function truncatePathFromRight() { echo $1 | sed $SED_EXTENDED_REGEX_PARAMETER \ "s@(([^/]{$((POWERLEVEL9K_SHORTEN_DIR_LENGTH))})([^/]{$delim_len}))[^/]+/@\2$POWERLEVEL9K_SHORTEN_DELIMITER/@g" } + +# Search recursively in parent folders for given file. +function upsearch () { + if test -e "$1"; then + echo "$PWD" + else + if [[ "$PWD" == "/" || "$PWD" == "$HOME" ]]; then + echo "$PWD"; + else + pushd .. > /dev/null + upsearch "$1" + popd > /dev/null + fi + fi +} diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f104b789..c679ba56 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -571,8 +571,7 @@ prompt_custom() { set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" prompt_dir() { local current_path='%~' - if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then - + if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_root_marker" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' case "$POWERLEVEL9K_SHORTEN_STRATEGY" in @@ -610,6 +609,20 @@ prompt_dir() { current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) fi ;; + truncate_with_root_marker) + local dir_truncate_root + + dir_truncate_root=$(upsearch $POWERLEVEL9K_ROOT_MARKER_FILE) + zero='%([BSUbfksu]|([FB]|){*})' + + if [[ "$dir_truncate_root" == "/" || "$dir_truncate_root" == "$HOME" ]]; then + current_path='%~' + elif [[ "$dir_truncate_root" == "$HOME"* ]]; then + current_path="~/$POWERLEVEL9K_SHORTEN_DELIMITER/${dir_truncate_root##*/}${PWD:${#${(S%%)dir_truncate_root//$~zero/}}}" + else + current_path="/$POWERLEVEL9K_SHORTEN_DELIMITER/${dir_truncate_root##*/}${PWD:${#${(S%%)dir_truncate_root//$~zero/}}}" + fi + ;; *) current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" ;; -- cgit v1.2.3 From 5cc2d51b5829d0ae2eefaa115892da71f6a14d79 Mon Sep 17 00:00:00 2001 From: Benoit Averty Date: Wed, 10 Aug 2016 13:00:52 +0200 Subject: Fix bug when truncate root was set to direct subfolder of home or root --- 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 c679ba56..afc4a6bc 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -615,7 +615,7 @@ prompt_dir() { dir_truncate_root=$(upsearch $POWERLEVEL9K_ROOT_MARKER_FILE) zero='%([BSUbfksu]|([FB]|){*})' - if [[ "$dir_truncate_root" == "/" || "$dir_truncate_root" == "$HOME" ]]; then + if [[ "$dir_truncate_root" == "/" || "$dir_truncate_root" == "$HOME" || "${dir_truncate_root%/*}" == "$HOME" || ${dir_truncate_root%/*} == "/" ]]; then current_path='%~' elif [[ "$dir_truncate_root" == "$HOME"* ]]; then current_path="~/$POWERLEVEL9K_SHORTEN_DELIMITER/${dir_truncate_root##*/}${PWD:${#${(S%%)dir_truncate_root//$~zero/}}}" -- cgit v1.2.3 From 9f4772f9930c7d56ab04df900ac94456e5a08a22 Mon Sep 17 00:00:00 2001 From: Benoit Averty Date: Wed, 10 Aug 2016 21:31:58 +0200 Subject: More possibilities with truncate folder marker --- functions/utilities.zsh | 17 +++++++++-------- powerlevel9k.zsh-theme | 30 ++++++++++++++++++------------ 2 files changed, 27 insertions(+), 20 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 8263ce10..22b53c6a 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -211,15 +211,16 @@ function truncatePathFromRight() { # Search recursively in parent folders for given file. function upsearch () { - if test -e "$1"; then + if [[ "$PWD" == "$HOME" || "$PWD" == "/" ]]; then + echo "$PWD" + elif test -e "$1"; then + pushd .. > /dev/null + upsearch "$1" + popd > /dev/null echo "$PWD" else - if [[ "$PWD" == "/" || "$PWD" == "$HOME" ]]; then - echo "$PWD"; - else - pushd .. > /dev/null - upsearch "$1" - popd > /dev/null - fi + pushd .. > /dev/null + upsearch "$1" + popd > /dev/null fi } diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index afc4a6bc..420f7d0b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -571,7 +571,7 @@ prompt_custom() { set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" prompt_dir() { local current_path='%~' - if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_root_marker" ]]; then + if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' case "$POWERLEVEL9K_SHORTEN_STRATEGY" in @@ -609,19 +609,25 @@ prompt_dir() { current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) fi ;; - truncate_with_root_marker) - local dir_truncate_root + truncate_with_folder_marker) + local last_marked_folder marked_folder zero + set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" + + for marked_folder in $(upsearch $POWERLEVEL9K_SHORTEN_FOLDER_MARKER); do + if [[ "$marked_folder" == "/" ]]; then + current_path="/" + elif [[ "$marked_folder" == "$HOME" ]]; then + 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 - dir_truncate_root=$(upsearch $POWERLEVEL9K_ROOT_MARKER_FILE) zero='%([BSUbfksu]|([FB]|){*})' - - if [[ "$dir_truncate_root" == "/" || "$dir_truncate_root" == "$HOME" || "${dir_truncate_root%/*}" == "$HOME" || ${dir_truncate_root%/*} == "/" ]]; then - current_path='%~' - elif [[ "$dir_truncate_root" == "$HOME"* ]]; then - current_path="~/$POWERLEVEL9K_SHORTEN_DELIMITER/${dir_truncate_root##*/}${PWD:${#${(S%%)dir_truncate_root//$~zero/}}}" - else - current_path="/$POWERLEVEL9K_SHORTEN_DELIMITER/${dir_truncate_root##*/}${PWD:${#${(S%%)dir_truncate_root//$~zero/}}}" - fi + current_path=$current_path${PWD:${#${(S%%)last_marked_folder//$~zero/}}} ;; *) current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" -- cgit v1.2.3 From eb865664e4225b94fc01ce1c05f27d1db18e172d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Feb 2017 00:31:04 +0100 Subject: Add comments to the dir segment --- 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 420f7d0b..723954be 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -615,8 +615,10 @@ prompt_dir() { 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##*/}" -- cgit v1.2.3 From 268c3247c95eb11c92054465404e37d8877c0f5d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 3 Feb 2017 20:21:53 +0100 Subject: Do path expansion at first --- 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 3010790e..3e529b3b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -570,7 +570,7 @@ prompt_custom() { # Dir: current working directory set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" prompt_dir() { - local current_path='%~' + local current_path="$(print -P "%~")" if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' @@ -621,7 +621,7 @@ prompt_dir() { fi if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" ]]; then - current_path=$(print -P "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g") + current_path="$( echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g")" fi typeset -AH dir_states -- cgit v1.2.3 From a8af89eeb7db3980f9bef14a96828fc8c8bdb854 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 4 Feb 2017 08:51:52 +0100 Subject: Fix default dir truncation strategy --- 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 3e529b3b..37bdbbb8 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -611,7 +611,7 @@ prompt_dir() { fi ;; *) - current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" + current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" ;; esac fi -- cgit v1.2.3 From 7e25fa1e93fbb02e2276e1d245748d09c7c63e8a Mon Sep 17 00:00:00 2001 From: Christian Rebischke Date: Fri, 10 Feb 2017 17:12:05 +0100 Subject: Added additional ssh identifier for the right statusbar. --- README.md | 1 + powerlevel9k.zsh-theme | 7 +++++++ 2 files changed, 8 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index cd7920e7..82b7ab41 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ The segments that are currently available are: * `swap` - Prints the current swap size. * [`time`](#time) - System time. * [`vi_mode`](#vi_mode)- Your prompt's Vi editing mode (NORMAL|INSERT). +* `SSH` - Additional Identifier for SSH Sessions. **Development Environment Segments:** * [`vcs`](#vcs) - Information about this `git` or `hg` repository (if you are in one). diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 1fdedd6b..57d63005 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -670,6 +670,13 @@ prompt_history() { "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" '%h' } +prompt_detect_ssh(){ + local color="yellow" + if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "$color" "ssh" + fi +} + # Detection for virtualization (systemd based systems only) prompt_detect_virt() { if ! command -v systemd-detect-virt;then -- cgit v1.2.3 From a4cb875615bedc305168c694793616de8d72c1b3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 12 Feb 2017 23:27:16 +0100 Subject: Add documentation about mysterious 'BSUbfksu' pattern --- powerlevel9k.zsh-theme | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d51ec8f2..e6befc6d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -591,7 +591,12 @@ prompt_dir() { package_path=${$(pwd)%%/.git*} fi - zero='%([BSUbfksu]|([FB]|){*})' + # Replace the shortest possible match of the marked folder from + # the current path. Remove the amount of characters up to the + # folder marker from the left. Count only the visible characters + # in the path (this is done by the "zero" pattern; see + # http://stackoverflow.com/a/40855342/5586433). + local zero='%([BSUbfksu]|([FB]|){*})' current_dir=$(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 @@ -613,6 +618,9 @@ prompt_dir() { local last_marked_folder marked_folder zero 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. @@ -628,7 +636,12 @@ prompt_dir() { last_marked_folder=$marked_folder done - zero='%([BSUbfksu]|([FB]|){*})' + # Replace the shortest possible match of the marked folder from + # the current path. Remove the amount of characters up to the + # folder marker from the left. Count only the visible characters + # in the path (this is done by the "zero" pattern; see + # http://stackoverflow.com/a/40855342/5586433). + local zero='%([BSUbfksu]|([FB]|){*})' current_path=$current_path${PWD:${#${(S%%)last_marked_folder//$~zero/}}} ;; *) -- cgit v1.2.3 From f6c65e3cf7b87a07b7dffb0c3d77a6932241c242 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 13 Feb 2017 00:18:34 +0100 Subject: Get rid of unreadable BSU-pattern Now the current folder in `truncate_with_folder_marker` strategy is truncated by cutting off the found folder from the beginning of $PWD. --- powerlevel9k.zsh-theme | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e6befc6d..55e33680 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -615,7 +615,7 @@ prompt_dir() { fi ;; truncate_with_folder_marker) - local last_marked_folder marked_folder zero + 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 @@ -637,12 +637,8 @@ prompt_dir() { done # Replace the shortest possible match of the marked folder from - # the current path. Remove the amount of characters up to the - # folder marker from the left. Count only the visible characters - # in the path (this is done by the "zero" pattern; see - # http://stackoverflow.com/a/40855342/5586433). - local zero='%([BSUbfksu]|([FB]|){*})' - current_path=$current_path${PWD:${#${(S%%)last_marked_folder//$~zero/}}} + # the current path. + current_path=$current_path${PWD#${last_marked_folder}*} ;; *) current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" -- cgit v1.2.3 From f68e055f3bf0403cb4c4a9b3b79adb8471fe3872 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 13 Feb 2017 21:50:37 -0500 Subject: Merging the `ssh` detection into `context` segment, resolving conflicts. --- README.md | 20 ++++++++------------ powerlevel9k.zsh-theme | 32 +++++++++++++------------------- 2 files changed, 21 insertions(+), 31 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index 3b7542fc..d6de6843 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ The segments that are currently available are: **System Status Segments:** * [`background_jobs`](#background_jobs) - Indicator for background jobs. * [`battery`](#battery) - Current battery status. -* [`context`](#context) - Your username and host. +* [`context`](#context) - Your username and host, conditionalized based on $USER and SSH status. * [`dir`](#dir) - Your current working directory. * `dir_writable` - Displays a lock icon, if you do not have write permissions on the current folder. * [`disk_usage`](#disk_usage) - Disk usage of your current partition. @@ -238,29 +238,25 @@ main theme distribution so that everyone can use it! ##### context -The `context` segment (user@host string) is conditional. This lets you enable -it, but only display it if you are not your normal user or on a remote host -(basically, only print it when it's likely you need it). +The `context` segment (user@host string) is conditional. By default, it will +only print if you are not your 'normal' user (including if you are root), or if +you are SSH'd to a remote host. To use this feature, make sure the `context` segment is enabled in your prompt elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`: You can set the `POWERLEVEL9K_CONTEXT_HOST_DEPTH` variable to change how the hostname is displayed. See (ZSH Manual)[http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Login-information] -for details. Default is set to %m which will show the hostname up to the first ‘.’ +for details. The default is set to %m which will show the hostname up to the first ‘.’ You can set it to %{N}m where N is an integer to show that many segments of system hostname. Setting N to a negative integer will show that many segments from the end of the hostname. | Variable | Default Value | Description | |----------|---------------|-------------| -|`DEFAULT_USER`|None|Username to consider a "default context" (you can also use `$USER`)| -|`POWERLEVEL9K_CONTEXT_HOST_DEPTH`|%m|Customizable host depth on prompt| - -You can use POWERLEVEL9K_HIDE_HOST for hiding the hostname in the prompt -when you are not in a ssh session. For example: - - POWERLEVEL9K_HIDE_HOST="yes" +|`DEFAULT_USER`|None|Username to consider a "default context".| +|`POWERLEVEL9K_CONTEXT_HOST_DEPTH`|%m|Customizable host depth on prompt.| +|`POWERLEVEL9K_ALWAYS_SHOW_CONTEXT`|false|Always show this segment.| ##### dir diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b1de8f84..49fdaf09 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -537,26 +537,27 @@ prompt_public_ip() { # 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 +set_default POWERLEVEL9K_CONTEXT_HOST_DEPTH "%m" prompt_context() { local current_state="DEFAULT" - declare -A context_states + typeset -AH context_states context_states=( "ROOT" "yellow" "DEFAULT" "011" ) + local content="$USER" - if [[ "$USER" != "$DEFAULT_USER" ]]; then - if [[ $(print -P "%#") == '#' ]]; then - current_state="ROOT" - fi - if [[ -z "$SSH_CLIENT" && -z "$SSH_TTY" ]]; then - if [[ "$POWERLEVEL9K_HIDE_HOST" == "false" || -z "$POWERLEVEL9K_HIDE_HOST" ]]; then - content="${content}@%m" + + if [[ "POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + + if [[ $(print -P "%#") == '#' ]]; then + current_state="ROOT" fi - else - content="${content}@%m" - fi - "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" + + content="${content}@${POWERLEVEL9K_CONTEXT_HOST_DEPTH}" + + "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" fi } @@ -704,13 +705,6 @@ prompt_history() { "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" '%h' } -prompt_detect_ssh(){ - local color="yellow" - if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then - "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "$color" "ssh" - fi -} - # Detection for virtualization (systemd based systems only) prompt_detect_virt() { if ! command -v systemd-detect-virt;then -- cgit v1.2.3 From 3de352b29627e39dc58ffa5b834e0e23531d95dc Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 13 Feb 2017 22:07:23 -0500 Subject: Adding `ssh` segment back with some minor changes. --- README.md | 2 +- functions/icons.zsh | 3 +++ powerlevel9k.zsh-theme | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/README.md b/README.md index d6de6843..22608cce 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ The segments that are currently available are: * `swap` - Prints the current swap size. * [`time`](#time) - System time. * [`vi_mode`](#vi_mode)- Your prompt's Vi editing mode (NORMAL|INSERT). -* `SSH` - Additional Identifier for SSH Sessions. +* `ssh` - Indicates whether or not you are in an SSH session. **Development Environment Segments:** * [`vcs`](#vcs) - Information about this `git` or `hg` repository (if you are in one). diff --git a/functions/icons.zsh b/functions/icons.zsh index 44d99095..3000f4a6 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -79,6 +79,7 @@ case $POWERLEVEL9K_MODE in SWIFT_ICON '' PUBLIC_IP_ICON '' LOCK_ICON $'\UE138' #  + SSH_ICON '(ssh)' ) ;; 'awesome-fontconfig') @@ -140,6 +141,7 @@ case $POWERLEVEL9K_MODE in SWIFT_ICON '' PUBLIC_IP_ICON '' LOCK_ICON $'\UE138' #  + SSH_ICON '(ssh)' ) ;; *) @@ -201,6 +203,7 @@ case $POWERLEVEL9K_MODE in SWIFT_ICON 'Swift' PUBLIC_IP_ICON '' LOCK_ICON $'\UE0A2' + SSH_ICON '(ssh)' ) ;; esac diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 49fdaf09..10b2b011 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -933,6 +933,12 @@ prompt_rvm() { fi } +prompt_ssh() { + if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'SSH_ICON' + fi +} + # 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 -- cgit v1.2.3 From 6512796afe15cac86ab52972f582b32fd769edac Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 13 Feb 2017 22:29:58 -0500 Subject: Trying to enable always showing user, not working --- powerlevel9k.zsh-theme | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 10b2b011..cf6ad5df 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -538,6 +538,7 @@ prompt_public_ip() { # 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 +set_default POWERLEVEL9K_ALWAYS_SHOW_USER false set_default POWERLEVEL9K_CONTEXT_HOST_DEPTH "%m" prompt_context() { local current_state="DEFAULT" @@ -547,7 +548,7 @@ prompt_context() { "DEFAULT" "011" ) - local content="$USER" + local content="" if [[ "POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then @@ -555,10 +556,15 @@ prompt_context() { current_state="ROOT" fi - content="${content}@${POWERLEVEL9K_CONTEXT_HOST_DEPTH}" + content="$USER@${POWERLEVEL9K_CONTEXT_HOST_DEPTH}" - "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" + elif [[ "POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then + content="$USER" + else + return fi + + "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" } # The 'custom` prompt provides a way for users to invoke commands and display -- cgit v1.2.3 From c65e3217b5fcecf84773c0c9a8a5805a9a97d812 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Tue, 14 Feb 2017 08:58:40 -0500 Subject: context: fixing conditionals in for always showing $USER --- 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 cf6ad5df..5960dbe8 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -550,7 +550,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 ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then if [[ $(print -P "%#") == '#' ]]; then current_state="ROOT" @@ -558,7 +558,7 @@ prompt_context() { content="$USER@${POWERLEVEL9K_CONTEXT_HOST_DEPTH}" - elif [[ "POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then + elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then content="$USER" else return -- cgit v1.2.3