expose P9K_SSH and make it available as soon as p10k is sourced

pull/186/head
romkatv 5 years ago
parent 3090ae6633
commit 727d42ff48

@ -1062,7 +1062,7 @@ prompt_context() {
if ! _p9k_cache_get $0 "${(%):-%#}"; then if ! _p9k_cache_get $0 "${(%):-%#}"; then
local -i enabled=1 local -i enabled=1
local content local content
if [[ $_POWERLEVEL9K_ALWAYS_SHOW_CONTEXT == 0 && -n $DEFAULT_USER && $_P9K_SSH == 0 ]]; then if [[ $_POWERLEVEL9K_ALWAYS_SHOW_CONTEXT == 0 && -n $DEFAULT_USER && $P9K_SSH == 0 ]]; then
local user="$(whoami)" local user="$(whoami)"
if [[ $user == $DEFAULT_USER ]]; then if [[ $user == $DEFAULT_USER ]]; then
if (( _POWERLEVEL9K_ALWAYS_SHOW_USER )); then if (( _POWERLEVEL9K_ALWAYS_SHOW_USER )); then
@ -1078,7 +1078,7 @@ prompt_context() {
state="DEFAULT" state="DEFAULT"
if [[ "${(%):-%#}" == '#' ]]; then if [[ "${(%):-%#}" == '#' ]]; then
state="ROOT" state="ROOT"
elif (( _P9K_SSH )); then elif (( P9K_SSH )); then
if [[ -n "$SUDO_COMMAND" ]]; then if [[ -n "$SUDO_COMMAND" ]]; then
state="REMOTE_SUDO" state="REMOTE_SUDO"
else else
@ -1128,7 +1128,7 @@ prompt_user() {
################################################################ ################################################################
# Host: machine (where am I) # Host: machine (where am I)
prompt_host() { prompt_host() {
if (( _P9K_SSH )); then if (( P9K_SSH )); then
_p9k_prompt_segment "$0_REMOTE" "${_p9k_color1}" yellow SSH_ICON 0 '' "$_POWERLEVEL9K_HOST_TEMPLATE" _p9k_prompt_segment "$0_REMOTE" "${_p9k_color1}" yellow SSH_ICON 0 '' "$_POWERLEVEL9K_HOST_TEMPLATE"
else else
_p9k_prompt_segment "$0_LOCAL" "${_p9k_color1}" yellow HOST_ICON 0 '' "$_POWERLEVEL9K_HOST_TEMPLATE" _p9k_prompt_segment "$0_LOCAL" "${_p9k_color1}" yellow HOST_ICON 0 '' "$_POWERLEVEL9K_HOST_TEMPLATE"
@ -1994,7 +1994,7 @@ prompt_rvm() {
################################################################ ################################################################
# Segment to display SSH icon when connected # Segment to display SSH icon when connected
prompt_ssh() { prompt_ssh() {
if (( _P9K_SSH )); then if (( P9K_SSH )); then
_p9k_prompt_segment "$0" "$_p9k_color1" "yellow" 'SSH_ICON' 0 '' '' _p9k_prompt_segment "$0" "$_p9k_color1" "yellow" 'SSH_ICON' 0 '' ''
fi fi
} }
@ -4039,25 +4039,27 @@ _p9k_init_ssh() {
# #
# License: https://github.com/sindresorhus/pure/blob/e8abf9d37185ec9b7b4398ca9c5eba555a1028eb/license. # License: https://github.com/sindresorhus/pure/blob/e8abf9d37185ec9b7b4398ca9c5eba555a1028eb/license.
[[ -n $_P9K_SSH ]] && return [[ -n $P9K_SSH ]] && return
export _P9K_SSH=0 typeset -gix P9K_SSH=0
if [[ -n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION ]]; then if [[ -n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION ]]; then
_P9K_SSH=1 P9K_SSH=1
return return
fi fi
# When changing user on a remote system, the $SSH_CONNECTION environment variable can be lost. # When changing user on a remote system, the $SSH_CONNECTION environment variable can be lost.
# Attempt detection via `who`. # Attempt detection via `who`.
(( $+commands[who] )) || return (( $+commands[who] )) || return
local w && w="$(who -m 2>/dev/null)" || w=${(@M)${(f)"$(who 2>/dev/null)"}:#*[[:space:]]${TTY#/dev/}[[:space:]]*}
local ipv6='(([0-9a-fA-F]+:)|:){2,}[0-9a-fA-F]+' # Simplified, only checks partial pattern. local ipv6='(([0-9a-fA-F]+:)|:){2,}[0-9a-fA-F]+' # Simplified, only checks partial pattern.
local ipv4='([0-9]{1,3}\.){3}[0-9]+' # Simplified, allows invalid ranges. local ipv4='([0-9]{1,3}\.){3}[0-9]+' # Simplified, allows invalid ranges.
# Assume two non-consecutive periods represents a hostname. Matches `x.y.z`, but not `x.y`. # Assume two non-consecutive periods represents a hostname. Matches `x.y.z`, but not `x.y`.
local hostname='([.][^. ]+){2}' local hostname='([.][^. ]+){2}'
local w
w="$(who -m 2>/dev/null)" || w=${(@M)${(f)"$(who 2>/dev/null)"}:#*[[:space:]]${TTY#/dev/}[[:space:]]*}
# Usually the remote address is surrounded by parenthesis but not on all systems (e.g., Busybox). # Usually the remote address is surrounded by parenthesis but not on all systems (e.g., Busybox).
[[ $w =~ "\(?($ipv4|$ipv6|$hostname)\)?\$" ]] && _P9K_SSH=1 [[ $w =~ "\(?($ipv4|$ipv6|$hostname)\)?\$" ]] && P9K_SSH=1
} }
_p9k_must_init() { _p9k_must_init() {
@ -4086,7 +4088,6 @@ _p9k_init() {
_p9k_init_vars _p9k_init_vars
_p9k_init_params _p9k_init_params
_p9k_init_prompt _p9k_init_prompt
_p9k_init_ssh
local uname="$(uname)" local uname="$(uname)"
if [[ $uname == Linux && "$(uname -o 2>/dev/null)" == Android ]]; then if [[ $uname == Linux && "$(uname -o 2>/dev/null)" == Android ]]; then
@ -4505,4 +4506,5 @@ zmodload zsh/system
zmodload -F zsh/stat b:zstat zmodload -F zsh/stat b:zstat
zmodload -F zsh/net/socket b:zsocket zmodload -F zsh/net/socket b:zsocket
_p9k_init_ssh
prompt_powerlevel9k_setup prompt_powerlevel9k_setup

Loading…
Cancel
Save