1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-12-22 15:21:56 +00:00

Merge branch 'next' into newline-count

This commit is contained in:
Ben Hilburn 2018-03-06 21:24:53 -05:00 committed by GitHub
commit 203d0839f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 163 additions and 9 deletions

View file

@ -321,7 +321,7 @@ main theme distribution so that everyone can use 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.
you are SSH'd to a remote host. `SUDO` and `REMOTE_SUDO` states are also available to show whether the current user or remote user has superuser privileges.
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`.
@ -384,6 +384,7 @@ Customizations available are:
| Strategy Name | Description |
|---------------|-------------|
|Default|Truncate whole directories from left. How many is defined by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`|
|`truncate_absolute_chars`|Truncates an absolute number of characters from the left such that the number of characters that your path displays (with or without `POWERLEVEL9K_SHORTEN_DELIMITER`) is no more than `POWERLEVEL9K_SHORTEN_DIR_LENGTH` + the length of `POWERLEVEL9K_SHORTEN_DELIMITER` |
|`truncate_middle`|Truncates the middle part of a folder. E.g. you are in a folder named `~/MySuperProjects/AwesomeFiles/BoringOffice`, then it will truncated to `~/MyS..cts/Awe..les/BoringOffice`, if `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3` is also set (controls the amount of characters to be left).|
|`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: "/ro../Pr../office". How many characters will be untouched is controlled by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`.|
|`truncate_with_package_name`|Search for a `package.json` or `composer.json` and prints the `name` field to abbreviate the directory path. The precedence and/or files could be set by `POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json)`. If you have [jq](https://stedolan.github.io/jq/) installed, it will dramatically improve the speed of this strategy.|
@ -589,6 +590,7 @@ You can also override the icons by setting:
```
POWERLEVEL9K_USER_ICON="\uF415" # 
POWERLEVEL9K_ROOT_ICON="#"
POWERLEVEL9K_SUDO_ICON=$'\uF09C' # 
```
| Variable | Default Value | Description |
@ -612,6 +614,7 @@ customization is provided via:
|`POWERLEVEL9K_VCS_GIT_HOOKS`|`(vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname)`|Layout of the segment for git repositories.|
|`POWERLEVEL9K_VCS_HG_HOOKS`|`(vcs-detect-changes)`|Layout of the segment for Mercurial repositories.|
|`POWERLEVEL9K_VCS_SVN_HOOKS`|`(vcs-detect-changes svn-detect-changes)`|Layout of the segment for SVN repositories.|
|`POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND`|`red`|The color of the foreground font during actions (e.g., `REBASE`).|
##### vcs symbols
@ -647,6 +650,8 @@ you are using the [ZSH Line Editor](http://zsh.sourceforge.net/Doc/Release/Zsh-L
|`POWERLEVEL9K_VI_INSERT_MODE_STRING`|`"INSERT"`|String to display while in 'Insert' mode.|
|`POWERLEVEL9K_VI_COMMAND_MODE_STRING`|`"NORMAL"`|String to display while in 'Command' mode.|
To hide the segment entirely when in `INSERT` mode, set `POWERLEVEL9K_VI_INSERT_MODE_STRING=''`
#### Unit Test Ratios
The `symfony2_tests` and `rspec_stats` segments both show a ratio of "real"

0
functions/colors.zsh Normal file → Executable file
View file

72
functions/icons.zsh Normal file → Executable file
View file

@ -27,6 +27,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON $'\uE801' # 
SUDO_ICON $'\uF09C' # 
RUBY_ICON $'\uE847 ' # 
AWS_ICON $'\uE895' # 
AWS_EB_ICON $'\U1F331 ' # 🌱
@ -47,6 +48,19 @@ case $POWERLEVEL9K_MODE in
FREEBSD_ICON $'\U1F608 ' # 😈
ANDROID_ICON $'\uE270' # 
LINUX_ICON $'\uE271' # 
LINUX_ARCH_ICON 'Arc'
LINUX_DEBIAN_ICON 'Deb'
LINUX_UBUNTU_ICON 'Ubu'
LINUX_CENTOS_ICON 'Cen'
LINUX_COREOS_ICON 'Cor'
LINUX_ELEMENTARY_ICON 'Elm'
LINUX_MINT_ICON 'LMi'
LINUX_FEDORA_ICON 'Fed'
LINUX_GENTOO_ICON 'Gen'
LINUX_MAGEIA_ICON 'Mag'
LINUX_OPENSUSE_ICON 'OSu'
LINUX_SABAYON_ICON 'Sab'
LINUX_SLACKWARE_ICON 'Sla'
SUNOS_ICON $'\U1F31E ' # 🌞
HOME_ICON $'\uE12C' # 
HOME_SUB_ICON $'\uE18D' # 
@ -105,6 +119,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON $'\uF201' # 
SUDO_ICON $'\uF09C' # 
RUBY_ICON $'\uF219 ' # 
AWS_ICON $'\uF270' # 
AWS_EB_ICON $'\U1F331 ' # 🌱
@ -125,6 +140,19 @@ case $POWERLEVEL9K_MODE in
FREEBSD_ICON $'\U1F608 ' # 😈
ANDROID_ICON $'\uE17B' # 
LINUX_ICON $'\uF17C' # 
LINUX_ARCH_ICON 'Arc'
LINUX_DEBIAN_ICON 'Deb'
LINUX_UBUNTU_ICON 'Ubu'
LINUX_CENTOS_ICON 'Cen'
LINUX_COREOS_ICON 'Cor'
LINUX_ELEMENTARY_ICON 'Elm'
LINUX_MINT_ICON 'LMi'
LINUX_FEDORA_ICON 'Fed'
LINUX_GENTOO_ICON 'Gen'
LINUX_MAGEIA_ICON 'Mag'
LINUX_OPENSUSE_ICON 'OSu'
LINUX_SABAYON_ICON 'Sab'
LINUX_SLACKWARE_ICON 'Sla'
SUNOS_ICON $'\uF185 ' # 
HOME_ICON $'\uF015' # 
HOME_SUB_ICON $'\uF07C' # 
@ -151,7 +179,7 @@ case $POWERLEVEL9K_MODE in
VCS_GIT_GITLAB_ICON $'\uF296 ' # 
VCS_HG_ICON $'\uF0C3 ' # 
VCS_SVN_ICON '(svn) '
RUST_ICON $'\uE6A8' # 
RUST_ICON $'\uE6A8' # 
PYTHON_ICON $'\ue63c' # 
SWIFT_ICON ''
GO_ICON ''
@ -188,6 +216,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON '\u'$CODEPOINT_OF_OCTICONS_ZAP # 
SUDO_ICON '\u'$CODEPOINT_OF_AWESOME_UNLOCK # 
RUBY_ICON '\u'$CODEPOINT_OF_OCTICONS_RUBY' ' # 
AWS_ICON '\u'$CODEPOINT_OF_AWESOME_SERVER # 
AWS_EB_ICON $'\U1F331 ' # 🌱
@ -205,6 +234,19 @@ case $POWERLEVEL9K_MODE in
APPLE_ICON '\u'$CODEPOINT_OF_AWESOME_APPLE # 
FREEBSD_ICON $'\U1F608 ' # 😈
LINUX_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX # 
LINUX_ARCH_ICON 'Arc'
LINUX_DEBIAN_ICON 'Deb'
LINUX_UBUNTU_ICON 'Ubu'
LINUX_CENTOS_ICON 'Cen'
LINUX_COREOS_ICON 'Cor'
LINUX_ELEMENTARY_ICON 'Elm'
LINUX_MINT_ICON 'LMi'
LINUX_FEDORA_ICON 'Fed'
LINUX_GENTOO_ICON 'Gen'
LINUX_MAGEIA_ICON 'Mag'
LINUX_OPENSUSE_ICON 'OSu'
LINUX_SABAYON_ICON 'Sab'
LINUX_SLACKWARE_ICON 'Sla'
SUNOS_ICON '\u'$CODEPOINT_OF_AWESOME_SUN_O' ' # 
HOME_ICON '\u'$CODEPOINT_OF_AWESOME_HOME # 
HOME_SUB_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_OPEN # 
@ -259,6 +301,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON $'\uE614 ' # 
SUDO_ICON $'\uF09C' # 
RUBY_ICON $'\uF219 ' # 
AWS_ICON $'\uF270' # 
AWS_EB_ICON $'\UF1BD ' # 
@ -278,6 +321,19 @@ case $POWERLEVEL9K_MODE in
WINDOWS_ICON $'\uF17A' # 
FREEBSD_ICON $'\UF30E ' # 
ANDROID_ICON $'\uF17B' # 
LINUX_ARCH_ICON $'\uF300' # 
LINUX_DEBIAN_ICON $'\uF302' # 
LINUX_UBUNTU_ICON $'\uF30C' # 
LINUX_CENTOS_ICON $'\uF301' # 
LINUX_COREOS_ICON $'\uF30F' # 
LINUX_ELEMENTARY_ICON $'\uF311' # 
LINUX_FEDORA_ICON $'\uF303' # 
LINUX_GENTOO_ICON $'\uF310' # 
LINUX_MINT_ICON $'\uF304' # 
LINUX_MAGEIA_ICON $'\uF306' # 
LINUX_OPENSUSE_ICON $'\uF308' # 
LINUX_SABAYON_ICON $'\uF313' # 
LINUX_SLACKWARE_ICON $'\uF30A' # 
LINUX_ICON $'\uF17C' # 
SUNOS_ICON $'\uF185 ' # 
HOME_ICON $'\uF015' # 
@ -333,6 +389,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON $'\u26A1' # ⚡
SUDO_ICON $'\uE0A2' # 
RUBY_ICON ''
AWS_ICON 'AWS:'
AWS_EB_ICON $'\U1F331 ' # 🌱
@ -353,6 +410,19 @@ case $POWERLEVEL9K_MODE in
FREEBSD_ICON 'BSD'
ANDROID_ICON 'And'
LINUX_ICON 'Lx'
LINUX_ARCH_ICON 'Arc'
LINUX_DEBIAN_ICON 'Deb'
LINUX_UBUNTU_ICON 'Ubu'
LINUX_CENTOS_ICON 'Cen'
LINUX_COREOS_ICON 'Cor'
LINUX_ELEMENTARY_ICON 'Elm'
LINUX_MINT_ICON 'LMi'
LINUX_FEDORA_ICON 'Fed'
LINUX_GENTOO_ICON 'Gen'
LINUX_MAGEIA_ICON 'Mag'
LINUX_OPENSUSE_ICON 'OSu'
LINUX_SABAYON_ICON 'Sab'
LINUX_SLACKWARE_ICON 'Sla'
SUNOS_ICON 'Sun'
HOME_ICON ''
HOME_SUB_ICON ''

47
functions/utilities.zsh Normal file → Executable file
View file

@ -103,7 +103,52 @@ case $(uname) in
;;
Linux)
OS='Linux'
OS_ICON=$(print_icon 'LINUX_ICON')
os_release_id="$(grep -E '^ID=([a-zA-Z]*)' /etc/os-release | cut -d '=' -f 2)"
case "$os_release_id" in
"arch")
OS_ICON=$(print_icon 'LINUX_ARCH_ICON')
;;
"debian")
OS_ICON=$(print_icon 'LINUX_DEBIAN_ICON')
;;
"ubuntu")
OS_ICON=$(print_icon 'LINUX_UBUNTU_ICON')
;;
"elementary")
OS_ICON=$(print_icon 'LINUX_ELEMENTARY_ICON')
;;
"fedora")
OS_ICON=$(print_icon 'LINUX_FEDORA_ICON')
;;
"coreos")
OS_ICON=$(print_icon 'LINUX_COREOS_ICON')
;;
"gentoo")
OS_ICON=$(print_icon 'LINUX_GENTOO_ICON')
;;
"mageia")
OS_ICON=$(print_icon 'LINUX_MAGEIA_ICON')
;;
"centos")
OS_ICON=$(print_icon 'LINUX_CENTOS_ICON')
;;
"opensuse"|"tumbleweed")
OS_ICON=$(print_icon 'LINUX_OPENSUSE_ICON')
;;
"sabayon")
OS_ICON=$(print_icon 'LINUX_SABAYON_ICON')
;;
"slackware")
OS_ICON=$(print_icon 'LINUX_SLACKWARE_ICON')
;;
"linuxmint")
OS_ICON=$(print_icon 'LINUX_MINT_ICON')
;;
*)
OS='Linux'
OS_ICON=$(print_icon 'LINUX_ICON')
;;
esac
# Check if we're running on Android
case $(uname -o 2>/dev/null) in

0
functions/vcs.zsh Normal file → Executable file
View file

View file

@ -589,9 +589,11 @@ prompt_context() {
local current_state="DEFAULT"
typeset -AH context_states
context_states=(
"ROOT" "yellow"
"DEFAULT" "yellow"
"REMOTE" "yellow"
"ROOT" "yellow"
"SUDO" "yellow"
"DEFAULT" "yellow"
"REMOTE" "yellow"
"REMOTE_SUDO" "yellow"
)
local content=""
@ -607,7 +609,13 @@ prompt_context() {
if [[ $(print -P "%#") == '#' ]]; then
current_state="ROOT"
elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
current_state="REMOTE"
if sudo -n true 2>/dev/null; then
current_state="REMOTE_SUDO"
else
current_state="REMOTE"
fi
elif sudo -n true 2>/dev/null; then
current_state="SUDO"
fi
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}"
@ -629,6 +637,14 @@ prompt_user() {
"FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "ROOT_ICON"
)
elif sudo -n true 2>/dev/null; then
user_state=(
"STATE" "SUDO"
"CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}"
"BACKGROUND_COLOR" "${DEFAULT_COLOR}"
"FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "SUDO_ICON"
)
else
user_state=(
"STATE" "DEFAULT"
@ -728,6 +744,11 @@ prompt_dir() {
set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026'
case "$POWERLEVEL9K_SHORTEN_STRATEGY" in
truncate_absolute_chars)
if [ ${#current_path} -gt $(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) ]; then
current_path=$POWERLEVEL9K_SHORTEN_DELIMITER${current_path:(-POWERLEVEL9K_SHORTEN_DIR_LENGTH)}
fi
;;
truncate_middle)
current_path=$(echo "$current_path" | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g")
;;
@ -1023,9 +1044,9 @@ prompt_load() {
# Replace comma
load_avg=${load_avg//,/.}
if [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.7") ]]; then
if [[ "$load_avg" -gt $((${cores} * 0.7)) ]]; then
current_state="critical"
elif [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.5") ]]; then
elif [[ "$load_avg" -gt $((${cores} * 0.5)) ]]; then
current_state="warning"
else
current_state="normal"
@ -1437,6 +1458,7 @@ prompt_vi_mode() {
"$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "default" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING"
;;
main|viins|*)
if [[ -z $POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then return; fi
"$1_prompt_segment" "$0_INSERT" "$2" "$DEFAULT_COLOR" "blue" "$POWERLEVEL9K_VI_INSERT_MODE_STRING"
;;
esac
@ -1623,15 +1645,25 @@ $(print_icon 'MULTILINE_LAST_PROMPT_PREFIX')'
NEWLINE='
'
if [[ $POWERLEVEL9K_PROMPT_ADD_NEWLINE == true ]]; then
NEWLINES=""
repeat ${POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT:-1} { NEWLINES+=$NEWLINE }
PROMPT="$NEWLINES$PROMPT"
fi
# Allow iTerm integration to work
[[ $ITERM_SHELL_INTEGRATION_INSTALLED == "Yes" ]] && PROMPT="%{$(iterm2_prompt_mark)%}$PROMPT"
}
zle-keymap-select () {
zle reset-prompt
zle -R
}
set_default POWERLEVEL9K_IGNORE_TERM_COLORS false
set_default POWERLEVEL9K_IGNORE_TERM_LANG false
prompt_powerlevel9k_setup() {
# The value below was set to better support 32-bit CPUs.
# It's the maximum _signed_ integer value on 32-bit CPUs.
@ -1695,6 +1727,8 @@ prompt_powerlevel9k_setup() {
# prepare prompts
add-zsh-hook precmd powerlevel9k_prepare_prompts
add-zsh-hook preexec powerlevel9k_preexec
zle -N zle-keymap-select
}
prompt_powerlevel9k_teardown() {