1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-12-18 05:40:07 +00:00

Merge branch 'host_user' of https://github.com/onaforeignshore/powerlevel9k into onaforeignshore-host_user

This commit is contained in:
Ben Hilburn 2017-05-22 21:46:17 -04:00
commit 44764285c3
3 changed files with 114 additions and 0 deletions

View file

@ -31,6 +31,11 @@ A new script `debug/font-issues.zsh` was added, so that problems with your font
The `ram` segment now shows the available ram instead of free.
### Add new segments `host` and `user`
The user and host segments allow you to have different icons and colors for both the user and host segments
depending on their state.
## v0.6.0
- Fixed a bug where the tag display was broken on detached HEADs.

View file

@ -92,6 +92,7 @@ The segments that are currently available are:
* `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.
* `history` - The command number for the current line.
* [`host`](#host) - Your current host name
* [`ip`](#ip) - Shows the current IP address.
* [`public_ip`](#public_ip) - Shows your public IP address.
* `load` - Your machine's load averages.
@ -101,6 +102,7 @@ The segments that are currently available are:
* [`status`](#status) - The return code of the previous command.
* `swap` - Prints the current swap size.
* [`time`](#time) - System time.
* [`user`](#user) - Your current username
* [`vi_mode`](#vi_mode)- Your prompt's Vi editing mode (NORMAL|INSERT).
* `ssh` - Indicates whether or not you are in an SSH session.
@ -410,6 +412,35 @@ The `disk_usage` segment will show the usage level of the partition that your cu
|POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL|90|The usage level that triggers a warning state.|
|POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL|95|The usage level that triggers a critical state.|
##### host
The `host` segment (host string) will print the hostname. You can customize the `host` segment.
For example, you can make it to print the full hostname by setting
```
POWERLEVEL9K_HOST_TEMPLATE="`hostname -f`"
```
You can also modify the COLOURS for the two states - LOCAL and REMOTE, by setting
```
POWERLEVEL9K_HOST_LOCAL_BACKGROUND="green"
POWERLEVEL9K_HOST_LOCAL_FOREGROUND="white"
POWERLEVEL9K_HOST_REMOTE_BACKGROUND="red"
POWERLEVEL9K_HOST_REMOTE_FOREGROUND="yellow"
```
Currently, LOCAL hosts will show the host icon and remote hosts will show the SSH icon. You can override them by setting
```
POWERLEVEL9K_HOST_ICON="\uF109 " # 
POWERLEVEL9K_SSH_ICON="\uF489 " # 
```
You can set the `POWERLEVEL9K_HOST_TEMPLATE` variable to change how the hostname is displayed.
See (ZSH Manual)[http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Login-information]
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.
##### ip
This segment tries to examine all currently used network interfaces and prints
@ -502,6 +533,29 @@ segment, as well:
# Output time, date, and a symbol from the "Awesome Powerline Font" set
POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S \uE868 %d.%m.%y}"
```
##### user
The `user` segment (user string) will print the username. You can customize the `user` segment.
For example, you can modify the COLOURS for the two states - DEFAULT and ROOT, by setting
```
POWERLEVEL9K_USER_DEFAULT_BACKGROUND="green"
POWERLEVEL9K_USER_DEFAULT_FOREGROUND="white"
POWERLEVEL9K_USER_ROOT_BACKGROUND="red"
POWERLEVEL9K_USER_ROOT_FOREGROUND="yellow"
```
You can also override the icons by setting
```
POWERLEVEL9K_USER_ICON="\uF415" # 
POWERLEVEL9K_ROOT_ICON="#"
```
| Variable | Default Value | Description |
|----------|---------------|-------------|
|`DEFAULT_USER`|None|Username to consider a "default context" (you can also set `$USER`).|
|`POWERLEVEL9K_ALWAYS_SHOW_USER`|false|Always show the username, but conditionalize the hostname.|
|`POWERLEVEL9K_USER_TEMPLATE`|%n|Default username prompt (username). Refer to the [ZSH Documentation](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html) for all possible expansions|
##### vcs
By default, the `vcs` segment will provide quite a bit of information. Further

View file

@ -604,6 +604,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_USER" == 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"
)
else
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() {