diff options
-rw-r--r-- | README.md | 6 | ||||
-rwxr-xr-x | powerlevel9k.zsh-theme | 28 |
2 files changed, 29 insertions, 5 deletions
@@ -102,6 +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. **Development Environment Segments:** * [`vcs`](#vcs) - Information about this `git` or `hg` repository (if you are in one). @@ -256,6 +257,11 @@ end of the hostname. |`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" + ##### dir The `dir` segment shows the current working directory. When using the "Awesome diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 8cd1331e..b1de8f84 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -538,14 +538,25 @@ 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 prompt_context() { - set_default POWERLEVEL9K_CONTEXT_HOST_DEPTH "%m" - 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@$POWERLEVEL9K_CONTEXT_HOST_DEPTH" + 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@$POWERLEVEL9K_CONTEXT_HOST_DEPTH" + content="${content}@%m" fi + "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" fi } @@ -693,6 +704,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 |