mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-11 00:00:06 +00:00
Merging the ssh
detection into context
segment, resolving conflicts.
This commit is contained in:
parent
5957aef79a
commit
f68e055f3b
2 changed files with 21 additions and 31 deletions
20
README.md
20
README.md
|
@ -87,7 +87,7 @@ The segments that are currently available are:
|
||||||
**System Status Segments:**
|
**System Status Segments:**
|
||||||
* [`background_jobs`](#background_jobs) - Indicator for background jobs.
|
* [`background_jobs`](#background_jobs) - Indicator for background jobs.
|
||||||
* [`battery`](#battery) - Current battery status.
|
* [`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`](#dir) - Your current working directory.
|
||||||
* `dir_writable` - Displays a lock icon, if you do not have write permissions on the current folder.
|
* `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.
|
* [`disk_usage`](#disk_usage) - Disk usage of your current partition.
|
||||||
|
@ -238,29 +238,25 @@ main theme distribution so that everyone can use it!
|
||||||
|
|
||||||
##### context
|
##### context
|
||||||
|
|
||||||
The `context` segment (user@host string) is conditional. This lets you enable
|
The `context` segment (user@host string) is conditional. By default, it will
|
||||||
it, but only display it if you are not your normal user or on a remote host
|
only print if you are not your 'normal' user (including if you are root), or if
|
||||||
(basically, only print it when it's likely you need it).
|
you are SSH'd to a remote host.
|
||||||
|
|
||||||
To use this feature, make sure the `context` segment is enabled in your prompt
|
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`:
|
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
|
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]
|
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
|
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
|
hostname. Setting N to a negative integer will show that many segments from the
|
||||||
end of the hostname.
|
end of the hostname.
|
||||||
|
|
||||||
| Variable | Default Value | Description |
|
| Variable | Default Value | Description |
|
||||||
|----------|---------------|-------------|
|
|----------|---------------|-------------|
|
||||||
|`DEFAULT_USER`|None|Username to consider a "default context" (you can also use `$USER`)|
|
|`DEFAULT_USER`|None|Username to consider a "default context".|
|
||||||
|`POWERLEVEL9K_CONTEXT_HOST_DEPTH`|%m|Customizable host depth on prompt|
|
|`POWERLEVEL9K_CONTEXT_HOST_DEPTH`|%m|Customizable host depth on prompt.|
|
||||||
|
|`POWERLEVEL9K_ALWAYS_SHOW_CONTEXT`|false|Always show this segment.|
|
||||||
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
|
##### dir
|
||||||
|
|
||||||
|
|
|
@ -537,25 +537,26 @@ prompt_public_ip() {
|
||||||
|
|
||||||
# Context: user@hostname (who am I and where am I)
|
# Context: user@hostname (who am I and where am I)
|
||||||
# Note that if $DEFAULT_USER is not set, this prompt segment will always print
|
# 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() {
|
prompt_context() {
|
||||||
local current_state="DEFAULT"
|
local current_state="DEFAULT"
|
||||||
declare -A context_states
|
typeset -AH context_states
|
||||||
context_states=(
|
context_states=(
|
||||||
"ROOT" "yellow"
|
"ROOT" "yellow"
|
||||||
"DEFAULT" "011"
|
"DEFAULT" "011"
|
||||||
)
|
)
|
||||||
|
|
||||||
local content="$USER"
|
local content="$USER"
|
||||||
if [[ "$USER" != "$DEFAULT_USER" ]]; then
|
|
||||||
|
if [[ "POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
|
||||||
|
|
||||||
if [[ $(print -P "%#") == '#' ]]; then
|
if [[ $(print -P "%#") == '#' ]]; then
|
||||||
current_state="ROOT"
|
current_state="ROOT"
|
||||||
fi
|
fi
|
||||||
if [[ -z "$SSH_CLIENT" && -z "$SSH_TTY" ]]; then
|
|
||||||
if [[ "$POWERLEVEL9K_HIDE_HOST" == "false" || -z "$POWERLEVEL9K_HIDE_HOST" ]]; then
|
content="${content}@${POWERLEVEL9K_CONTEXT_HOST_DEPTH}"
|
||||||
content="${content}@%m"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
content="${content}@%m"
|
|
||||||
fi
|
|
||||||
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}"
|
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -704,13 +705,6 @@ prompt_history() {
|
||||||
"$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" '%h'
|
"$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)
|
# Detection for virtualization (systemd based systems only)
|
||||||
prompt_detect_virt() {
|
prompt_detect_virt() {
|
||||||
if ! command -v systemd-detect-virt;then
|
if ! command -v systemd-detect-virt;then
|
||||||
|
|
Loading…
Reference in a new issue