From 5ee0054298263d0043d2f6da35d3ea949b04f434 Mon Sep 17 00:00:00 2001 From: romkatv Date: Wed, 13 Mar 2019 17:04:27 +0100 Subject: [PATCH] don't read configuration options until the first precmd; plus massive refactoring and cleanup --- functions/colors.zsh | 109 +---- functions/icons.zsh | 1034 ++++++++++++++++++++------------------- functions/utilities.zsh | 255 +--------- powerlevel9k.zsh-theme | 685 +++++++++++++------------- 4 files changed, 892 insertions(+), 1191 deletions(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index 80abb6be..d8b7cbe8 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -6,10 +6,9 @@ # https://github.com/bhilburn/powerlevel9k ################################################################ -typeset -gAh __P9K_COLORS # https://jonasjacek.github.io/colors/ # use color names by default to allow dark/light themes to adjust colors based on names -__P9K_COLORS=( +typeset -gAh __P9K_COLORS=( black 000 red 001 green 002 @@ -270,89 +269,29 @@ __P9K_COLORS=( grey93 255 ) -function termColors() { - if [[ $POWERLEVEL9K_IGNORE_TERM_COLORS == true ]]; then - return - fi - - local term_colors - - if which tput &>/dev/null; then - term_colors=$(tput colors) - else - term_colors=$(echotc Co) - fi - if (( ! $? && ${term_colors:-0} < 256 )); then - print -P "%F{red}WARNING!%f Your terminal appears to support fewer than 256 colors!" - print -P "If your terminal supports 256 colors, please export the appropriate environment variable" - print -P "_before_ loading this theme in your \~\/.zshrc. In most terminal emulators, putting" - print -P "%F{blue}export TERM=\"xterm-256color\"%f at the top of your \~\/.zshrc is sufficient." - fi -} - -# get the proper color code if it does not exist as a name. -function getColor() { - # If Color is not numerical, try to get the color code. - if [[ "$1" != <-> ]]; then - 1=$(getColorCode $1) - fi - echo -n "$1" -} - -# empty paramenter resets (stops) background color -function backgroundColor() { - echo -n "%K{$(getColor $1)}" -} - -# empty paramenter resets (stops) foreground color -function foregroundColor() { - echo -n "%F{$(getColor $1)}" -} - -# Get numerical color codes. That way we translate ANSI codes -# into ZSH-Style color codes. +# For user convenience: type `getColorCode background` or `getColorCode foreground` to see +# the list of predefined colors. function getColorCode() { - # Early exit: Check if given value is already numerical - if [[ "$1" == <-> ]]; then - # Pad color with zeroes - echo -n "${(l:3::0:)1}" - return - fi - - local colorName="${1}" - # Check if value is none with any case. - if [[ "${(L)colorName}" == "none" ]]; then - echo -n 'none' - elif [[ "${colorName}" == "foreground" ]]; then - # for testing purposes in terminal - # call via `getColorCode foreground` - for i in "${(k@)__P9K_COLORS}"; do - print -P "$(foregroundColor $i)$(getColor $i) - $i%f" - done - elif [[ "${colorName}" == "background" ]]; then - # call via `getColorCode background` - for i in "${(k@)__P9K_COLORS}"; do - print -P "$(backgroundColor $i)$(getColor $i) - $i%k" - done - else - # Strip eventual "bg-" prefixes - colorName=${colorName#bg-} - # Strip eventual "fg-" prefixes - colorName=${colorName#fg-} - # Strip eventual "br" prefixes ("bright" colors) - colorName=${colorName#br} - echo -n $__P9K_COLORS[$colorName] + if (( ARGC == 1 )); then + case $1 in + foreground) + local k + for k in "${(k@)__P9K_COLORS}"; do + local v=${__P9K_COLORS[$k]} + print -P "%F{$v}$v - $k%f" + done + return + ;; + background) + local k + for k in "${(k@)__P9K_COLORS}"; do + local v=${__P9K_COLORS[$k]} + print -P "%K{$v}$v - $k%k" + done + return + ;; + esac fi -} - -# Check if two colors are equal, even if one is specified as ANSI code. -function isSameColor() { - if [[ "$1" == "NONE" || "$2" == "NONE" ]]; then - return 1 - fi - - local color1=$(getColorCode "$1") - local color2=$(getColorCode "$2") - - return $(( color1 != color2 )) + echo "Usage: getColorCode background|foreground" >&2 + return 1 } diff --git a/functions/icons.zsh b/functions/icons.zsh index 28cbb709..2147add8 100755 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -13,530 +13,534 @@ # Initialize the icon list according to the user's `POWERLEVEL9K_MODE`. typeset -gAH icons -() { # add scope to protect the users locale and not overwrite LC_CTYPE! -case $POWERLEVEL9K_MODE in - 'flat'|'awesome-patched') - # Awesome-Patched Font required! See: - # https://github.com/gabrielelana/awesome-terminal-fonts/tree/patching-strategy/patched - # Set the right locale to protect special characters - local LC_ALL="" LC_CTYPE="en_US.UTF-8" - icons=( - LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  - RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  - LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace - LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  - RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  - CARRIAGE_RETURN_ICON $'\u21B5' # ↵ - ROOT_ICON $'\uE801' #  - SUDO_ICON $'\uF09C' #  - RUBY_ICON $'\uE847 ' #  - AWS_ICON $'\uE895' #  - AWS_EB_ICON $'\U1F331 ' # 🌱 - BACKGROUND_JOBS_ICON $'\uE82F ' #  - TEST_ICON $'\uE891' #  - TODO_ICON $'\u2611' # ☑ - BATTERY_ICON $'\uE894' #  - DISK_ICON $'\uE1AE ' #  - OK_ICON $'\u2714' # ✔ - FAIL_ICON $'\u2718' # ✘ - SYMFONY_ICON 'SF' - NODE_ICON $'\u2B22' # ⬢ - MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ - MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ - MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ - APPLE_ICON $'\uE26E' #  - WINDOWS_ICON $'\uE26F' #  - FREEBSD_ICON $'\U1F608 ' # 😈 - ANDROID_ICON $'\uE270' #  - LINUX_ICON $'\uE271' #  - LINUX_ARCH_ICON $'\uE271' #  - LINUX_DEBIAN_ICON $'\uE271' #  - LINUX_UBUNTU_ICON $'\uE271' #  - LINUX_CENTOS_ICON $'\uE271' #  - LINUX_COREOS_ICON $'\uE271' #  - LINUX_ELEMENTARY_ICON $'\uE271' #  - LINUX_MINT_ICON $'\uE271' #  - LINUX_FEDORA_ICON $'\uE271' #  - LINUX_GENTOO_ICON $'\uE271' #  - LINUX_MAGEIA_ICON $'\uE271' #  - LINUX_NIXOS_ICON $'\uE271' #  - LINUX_MANJARO_ICON $'\uE271' #  - LINUX_DEVUAN_ICON $'\uE271' #  - LINUX_ALPINE_ICON $'\uE271' #  - LINUX_AOSC_ICON $'\uE271' #  - LINUX_OPENSUSE_ICON $'\uE271' #  - LINUX_SABAYON_ICON $'\uE271' #  - LINUX_SLACKWARE_ICON $'\uE271' #  - SUNOS_ICON $'\U1F31E ' # 🌞 - HOME_ICON $'\uE12C' #  - HOME_SUB_ICON $'\uE18D' #  - FOLDER_ICON $'\uE818' #  - NETWORK_ICON $'\uE1AD' #  - ETC_ICON $'\uE82F' #  - LOAD_ICON $'\uE190 ' #  - SWAP_ICON $'\uE87D' #  - RAM_ICON $'\uE1E2 ' #  - SERVER_ICON $'\uE895' #  - VCS_UNTRACKED_ICON $'\uE16C' #  - VCS_UNSTAGED_ICON $'\uE17C' #  - VCS_STAGED_ICON $'\uE168' #  - VCS_STASH_ICON $'\uE133 ' #  - #VCS_INCOMING_CHANGES_ICON $'\uE1EB ' #  - #VCS_INCOMING_CHANGES_ICON $'\uE80D ' #  - VCS_INCOMING_CHANGES_ICON $'\uE131 ' #  - #VCS_OUTGOING_CHANGES_ICON $'\uE1EC ' #  - #VCS_OUTGOING_CHANGES_ICON $'\uE80E ' #  - VCS_OUTGOING_CHANGES_ICON $'\uE132 ' #  - VCS_TAG_ICON $'\uE817 ' #  - VCS_BOOKMARK_ICON $'\uE87B' #  - VCS_COMMIT_ICON $'\uE821 ' #  - VCS_BRANCH_ICON $'\uE220 ' #  - VCS_REMOTE_BRANCH_ICON $'\u2192' # → - VCS_GIT_ICON $'\uE20E ' #  - VCS_GIT_GITHUB_ICON $'\uE20E ' # - VCS_GIT_BITBUCKET_ICON $'\uE20E ' # - VCS_GIT_GITLAB_ICON $'\uE20E ' # - VCS_HG_ICON $'\uE1C3 ' #  - VCS_SVN_ICON '(svn) ' - RUST_ICON '(rust)' - PYTHON_ICON $'\ue63c' #  - SWIFT_ICON '' - GO_ICON '' - PUBLIC_IP_ICON '' - LOCK_ICON $'\UE138' #  - EXECUTION_TIME_ICON $'\UE89C' #  - SSH_ICON '(ssh)' - VPN_ICON '(vpn)' - KUBERNETES_ICON $'\U2388' # ⎈ - DROPBOX_ICON $'\UF16B' #  - DATE_ICON $'\uE184' #  - TIME_ICON $'\uE12E' #  - JAVA_ICON $'\U2615' # ☕︎ - LARAVEL_ICON '' - ) - ;; - 'awesome-fontconfig') - # fontconfig with awesome-font required! See - # https://github.com/gabrielelana/awesome-terminal-fonts - # Set the right locale to protect special characters - local LC_ALL="" LC_CTYPE="en_US.UTF-8" - icons=( - LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  - RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  - LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace - LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  - RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  - CARRIAGE_RETURN_ICON $'\u21B5' # ↵ - ROOT_ICON $'\uF201' #  - SUDO_ICON $'\uF09C' #  - RUBY_ICON $'\uF219 ' #  - AWS_ICON $'\uF270' #  - AWS_EB_ICON $'\U1F331 ' # 🌱 - BACKGROUND_JOBS_ICON $'\uF013 ' #  - TEST_ICON $'\uF291' #  - TODO_ICON $'\u2611' # ☑ - BATTERY_ICON $'\U1F50B' # 🔋 - DISK_ICON $'\uF0A0 ' #  - OK_ICON $'\u2714' # ✔ - FAIL_ICON $'\u2718' # ✘ - SYMFONY_ICON 'SF' - NODE_ICON $'\u2B22' # ⬢ - MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ - MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ - MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ - APPLE_ICON $'\uF179' #  - WINDOWS_ICON $'\uF17A' #  - FREEBSD_ICON $'\U1F608 ' # 😈 - ANDROID_ICON $'\uE17B' #  - LINUX_ICON $'\uF17C' #  - LINUX_ARCH_ICON $'\uF17C' #  - LINUX_DEBIAN_ICON $'\uF17C' #  - LINUX_UBUNTU_ICON $'\uF17C' #  - LINUX_CENTOS_ICON $'\uF17C' #  - LINUX_COREOS_ICON $'\uF17C' #  - LINUX_ELEMENTARY_ICON $'\uF17C' #  - LINUX_MINT_ICON $'\uF17C' #  - LINUX_FEDORA_ICON $'\uF17C' #  - LINUX_GENTOO_ICON $'\uF17C' #  - LINUX_MAGEIA_ICON $'\uF17C' #  - LINUX_NIXOS_ICON $'\uF17C' #  - LINUX_MANJARO_ICON $'\uF17C' #  - LINUX_DEVUAN_ICON $'\uF17C' #  - LINUX_ALPINE_ICON $'\uF17C' #  - LINUX_AOSC_ICON $'\uF17C' #  - LINUX_OPENSUSE_ICON $'\uF17C' #  - LINUX_SABAYON_ICON $'\uF17C' #  - LINUX_SLACKWARE_ICON $'\uF17C' #  - SUNOS_ICON $'\uF185 ' #  - HOME_ICON $'\uF015' #  - HOME_SUB_ICON $'\uF07C' #  - FOLDER_ICON $'\uF115' #  - ETC_ICON $'\uF013 ' #  - NETWORK_ICON $'\uF09E' #  - LOAD_ICON $'\uF080 ' #  - SWAP_ICON $'\uF0E4' #  - RAM_ICON $'\uF0E4' #  - SERVER_ICON $'\uF233' #  - VCS_UNTRACKED_ICON $'\uF059' #  - VCS_UNSTAGED_ICON $'\uF06A' #  - VCS_STAGED_ICON $'\uF055' #  - VCS_STASH_ICON $'\uF01C ' #  - VCS_INCOMING_CHANGES_ICON $'\uF01A ' #  - VCS_OUTGOING_CHANGES_ICON $'\uF01B ' #  - VCS_TAG_ICON $'\uF217 ' #  - VCS_BOOKMARK_ICON $'\uF27B' #  - VCS_COMMIT_ICON $'\uF221 ' #  - VCS_BRANCH_ICON $'\uF126 ' #  - VCS_REMOTE_BRANCH_ICON $'\u2192' # → - VCS_GIT_ICON $'\uF1D3 ' #  - VCS_GIT_GITHUB_ICON $'\uF113 ' #  - VCS_GIT_BITBUCKET_ICON $'\uF171 ' #  - VCS_GIT_GITLAB_ICON $'\uF296 ' #  - VCS_HG_ICON $'\uF0C3 ' #  - VCS_SVN_ICON '(svn) ' - RUST_ICON $'\uE6A8' #  - PYTHON_ICON $'\ue63c' #  - SWIFT_ICON '' - GO_ICON '' - PUBLIC_IP_ICON '' - LOCK_ICON $'\UF023' #  - EXECUTION_TIME_ICON $'\uF253' - SSH_ICON '(ssh)' - VPN_ICON $'\uF023' - KUBERNETES_ICON $'\U2388' # ⎈ - DROPBOX_ICON $'\UF16B' #  - DATE_ICON $'\uF073 ' #  - TIME_ICON $'\uF017 ' #  - JAVA_ICON $'\U2615' # ☕︎ - LARAVEL_ICON '' - ) - ;; - 'awesome-mapped-fontconfig') - # mapped fontconfig with awesome-font required! See - # https://github.com/gabrielelana/awesome-terminal-fonts - # don't forget to source the font maps in your startup script - # Set the right locale to protect special characters - local LC_ALL="" LC_CTYPE="en_US.UTF-8" - if [ -z "$AWESOME_GLYPHS_LOADED" ]; then - echo "Powerlevel9k warning: Awesome-Font mappings have not been loaded. - Source a font mapping in your shell config, per the Awesome-Font docs - (https://github.com/gabrielelana/awesome-terminal-fonts), - Or use a different Powerlevel9k font configuration."; - fi +set_default POWERLEVEL9K_HIDE_BRANCH_ICON false +set_default POWERLEVEL9K_MODE "" - icons=( - LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  - RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  - LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace - LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  - 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 ' # 🌱 - BACKGROUND_JOBS_ICON '\u'$CODEPOINT_OF_AWESOME_COG' ' #  - TEST_ICON '\u'$CODEPOINT_OF_AWESOME_BUG #  - TODO_ICON '\u'$CODEPOINT_OF_AWESOME_CHECK_SQUARE_O #  - BATTERY_ICON '\U'$CODEPOINT_OF_AWESOME_BATTERY_FULL #  - DISK_ICON '\u'$CODEPOINT_OF_AWESOME_HDD_O' ' #  - OK_ICON '\u'$CODEPOINT_OF_AWESOME_CHECK #  - FAIL_ICON '\u'$CODEPOINT_OF_AWESOME_TIMES #  - SYMFONY_ICON 'SF' - NODE_ICON $'\u2B22' # ⬢ - MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ - MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ - APPLE_ICON '\u'$CODEPOINT_OF_AWESOME_APPLE #  - FREEBSD_ICON $'\U1F608 ' # 😈 - LINUX_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_ARCH_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_DEBIAN_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_UBUNTU_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_CENTOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_COREOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_ELEMENTARY_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_MINT_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_FEDORA_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_GENTOO_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_MAGEIA_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_NIXOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_MANJARO_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_DEVUAN_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_ALPINE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_AOSC_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_OPENSUSE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_SABAYON_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_SLACKWARE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - SUNOS_ICON '\u'$CODEPOINT_OF_AWESOME_SUN_O' ' #  - HOME_ICON '\u'$CODEPOINT_OF_AWESOME_HOME #  - HOME_SUB_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_OPEN #  - FOLDER_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_O #  - ETC_ICON '\u'$CODEPOINT_OF_AWESOME_COG' ' #  - NETWORK_ICON '\u'$CODEPOINT_OF_AWESOME_RSS #  - LOAD_ICON '\u'$CODEPOINT_OF_AWESOME_BAR_CHART' ' #  - SWAP_ICON '\u'$CODEPOINT_OF_AWESOME_DASHBOARD #  - RAM_ICON '\u'$CODEPOINT_OF_AWESOME_DASHBOARD #  - SERVER_ICON '\u'$CODEPOINT_OF_AWESOME_SERVER #  - VCS_UNTRACKED_ICON '\u'$CODEPOINT_OF_AWESOME_QUESTION_CIRCLE #  - VCS_UNSTAGED_ICON '\u'$CODEPOINT_OF_AWESOME_EXCLAMATION_CIRCLE #  - VCS_STAGED_ICON '\u'$CODEPOINT_OF_AWESOME_PLUS_CIRCLE #  - VCS_STASH_ICON '\u'$CODEPOINT_OF_AWESOME_INBOX' ' #  - VCS_INCOMING_CHANGES_ICON '\u'$CODEPOINT_OF_AWESOME_ARROW_CIRCLE_DOWN' ' #  - VCS_OUTGOING_CHANGES_ICON '\u'$CODEPOINT_OF_AWESOME_ARROW_CIRCLE_UP' ' #  - VCS_TAG_ICON '\u'$CODEPOINT_OF_AWESOME_TAG' ' #  - VCS_BOOKMARK_ICON '\u'$CODEPOINT_OF_OCTICONS_BOOKMARK #  - VCS_COMMIT_ICON '\u'$CODEPOINT_OF_OCTICONS_GIT_COMMIT' ' #  - VCS_BRANCH_ICON '\u'$CODEPOINT_OF_OCTICONS_GIT_BRANCH' ' #  - VCS_REMOTE_BRANCH_ICON '\u'$CODEPOINT_OF_OCTICONS_REPO_PUSH #  - VCS_GIT_ICON '\u'$CODEPOINT_OF_AWESOME_GIT' ' #  - VCS_GIT_GITHUB_ICON '\u'$CODEPOINT_OF_AWESOME_GITHUB_ALT' ' #  - VCS_GIT_BITBUCKET_ICON '\u'$CODEPOINT_OF_AWESOME_BITBUCKET' ' #  - VCS_GIT_GITLAB_ICON '\u'$CODEPOINT_OF_AWESOME_GITLAB' ' #  - VCS_HG_ICON '\u'$CODEPOINT_OF_AWESOME_FLASK' ' #  - VCS_SVN_ICON '(svn) ' - RUST_ICON $'\uE6A8' #  - PYTHON_ICON $'\U1F40D' # 🐍 - SWIFT_ICON $'\uE655' #  - PUBLIC_IP_ICON '\u'$CODEPOINT_OF_AWESOME_GLOBE #  - LOCK_ICON '\u'$CODEPOINT_OF_AWESOME_LOCK #  - EXECUTION_TIME_ICON '\u'$CODEPOINT_OF_AWESOME_HOURGLASS_END #  - SSH_ICON '(ssh)' - VPN_ICON '\u'$CODEPOINT_OF_AWESOME_LOCK - KUBERNETES_ICON $'\U2388' # ⎈ - DROPBOX_ICON '\u'$CODEPOINT_OF_AWESOME_DROPBOX #  - DATE_ICON $'\uF073 ' #  - TIME_ICON $'\uF017 ' #  - JAVA_ICON $'\U2615' # ☕︎ - LARAVEL_ICON '' - ) - ;; - 'nerdfont-complete'|'nerdfont-fontconfig') - # nerd-font patched (complete) font required! See - # https://github.com/ryanoasis/nerd-fonts - # http://nerdfonts.com/#cheat-sheet - # Set the right locale to protect special characters - local LC_ALL="" LC_CTYPE="en_US.UTF-8" - icons=( - LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  - RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  - LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace - LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  - RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  - CARRIAGE_RETURN_ICON $'\u21B5' # ↵ - ROOT_ICON $'\uE614 ' #  - SUDO_ICON $'\uF09C' #  - RUBY_ICON $'\uF219 ' #  - AWS_ICON $'\uF270' #  - AWS_EB_ICON $'\UF1BD ' #  - BACKGROUND_JOBS_ICON $'\uF013 ' #  - TEST_ICON $'\uF188' #  - TODO_ICON $'\uF133' #  - BATTERY_ICON $'\UF240 ' #  - DISK_ICON $'\uF0A0' #  - OK_ICON $'\uF00C' #  - FAIL_ICON $'\uF00D' #  - SYMFONY_ICON $'\uE757' #  - NODE_ICON $'\uE617 ' #  - MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ - MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ - MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ - APPLE_ICON $'\uF179' #  - WINDOWS_ICON $'\uF17A' #  - FREEBSD_ICON $'\UF30C ' #  - ANDROID_ICON $'\uF17B' #  - LINUX_ARCH_ICON $'\uF303' #  - LINUX_CENTOS_ICON $'\uF304' #  - LINUX_COREOS_ICON $'\uF305' #  - LINUX_DEBIAN_ICON $'\uF306' #  - LINUX_ELEMENTARY_ICON $'\uF309' #  - LINUX_FEDORA_ICON $'\uF30a' #  - LINUX_GENTOO_ICON $'\uF30d' #  - LINUX_MAGEIA_ICON $'\uF310' #  - LINUX_MINT_ICON $'\uF30e' #  - LINUX_NIXOS_ICON $'\uF313' #  - LINUX_MANJARO_ICON $'\uF312' #  - LINUX_DEVUAN_ICON $'\uF307' #  - LINUX_ALPINE_ICON $'\uF300' #  - LINUX_AOSC_ICON $'\uF301' #  - LINUX_OPENSUSE_ICON $'\uF314' #  - LINUX_SABAYON_ICON $'\uF317' #  - LINUX_SLACKWARE_ICON $'\uF319' #  - LINUX_UBUNTU_ICON $'\uF31b' #  - LINUX_ICON $'\uF17C' #  - SUNOS_ICON $'\uF185 ' #  - HOME_ICON $'\uF015' #  - HOME_SUB_ICON $'\uF07C' #  - FOLDER_ICON $'\uF115' #  - ETC_ICON $'\uF013' #  - NETWORK_ICON $'\uF1EB' #  - LOAD_ICON $'\uF080 ' #  - SWAP_ICON $'\uF464' #  - RAM_ICON $'\uF0E4' #  - SERVER_ICON $'\uF0AE' #  - VCS_UNTRACKED_ICON $'\uF059' #  - VCS_UNSTAGED_ICON $'\uF06A' #  - VCS_STAGED_ICON $'\uF055' #  - VCS_STASH_ICON $'\uF01C ' #  - VCS_INCOMING_CHANGES_ICON $'\uF01A ' #  - VCS_OUTGOING_CHANGES_ICON $'\uF01B ' #  - VCS_TAG_ICON $'\uF02B ' #  - VCS_BOOKMARK_ICON $'\uF461 ' #  - VCS_COMMIT_ICON $'\uE729 ' #  - VCS_BRANCH_ICON $'\uF126 ' #  - VCS_REMOTE_BRANCH_ICON $'\uE728 ' #  - VCS_GIT_ICON $'\uF1D3 ' #  - VCS_GIT_GITHUB_ICON $'\uF113 ' #  - VCS_GIT_BITBUCKET_ICON $'\uE703 ' #  - VCS_GIT_GITLAB_ICON $'\uF296 ' #  - VCS_HG_ICON $'\uF0C3 ' #  - VCS_SVN_ICON $'\uE72D ' #  - RUST_ICON $'\uE7A8 ' #  - PYTHON_ICON $'\UE73C ' #  - SWIFT_ICON $'\uE755' #  - GO_ICON $'\uE626' #  - PUBLIC_IP_ICON $'\UF0AC' #  - LOCK_ICON $'\UF023' #  - EXECUTION_TIME_ICON $'\uF252' #  - SSH_ICON $'\uF489' #  - VPN_ICON '(vpn)' - KUBERNETES_ICON $'\U2388' # ⎈ - DROPBOX_ICON $'\UF16B' #  - DATE_ICON $'\uF073 ' #  - TIME_ICON $'\uF017 ' #  - JAVA_ICON $'\U2615' # ☕︎ - LARAVEL_ICON $'\ue73f ' #  - ) - ;; - *) - # Powerline-Patched Font required! - # See https://github.com/Lokaltog/powerline-fonts - # Set the right locale to protect special characters - local LC_ALL="" LC_CTYPE="en_US.UTF-8" - icons=( - LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  - RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  - LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace - LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  - RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  - CARRIAGE_RETURN_ICON $'\u21B5' # ↵ - ROOT_ICON $'\u26A1' # ⚡ - SUDO_ICON $'\uE0A2' #  - RUBY_ICON '' - AWS_ICON 'AWS:' - AWS_EB_ICON $'\U1F331 ' # 🌱 - BACKGROUND_JOBS_ICON $'\u2699' # ⚙ - TEST_ICON '' - TODO_ICON $'\u2611' # ☑ - BATTERY_ICON $'\U1F50B' # 🔋 - DISK_ICON $'hdd ' - OK_ICON $'\u2714' # ✔ - FAIL_ICON $'\u2718' # ✘ - SYMFONY_ICON 'SF' - NODE_ICON $'\u2B22' # ⬢ - MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ - MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ - MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ - APPLE_ICON 'OSX' - WINDOWS_ICON 'WIN' - 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_NIXOS_ICON 'Nix' - LINUX_MANJARO_ICON 'Man' - LINUX_DEVUAN_ICON 'Dev' - LINUX_ALPINE_ICON 'Alp' - LINUX_AOSC_ICON 'Aos' - LINUX_OPENSUSE_ICON 'OSu' - LINUX_SABAYON_ICON 'Sab' - LINUX_SLACKWARE_ICON 'Sla' - SUNOS_ICON 'Sun' - HOME_ICON '' - HOME_SUB_ICON '' - FOLDER_ICON '' - ETC_ICON $'\u2699' # ⚙ - NETWORK_ICON 'IP' - LOAD_ICON 'L' - SWAP_ICON 'SWP' - RAM_ICON 'RAM' - SERVER_ICON '' - VCS_UNTRACKED_ICON '?' - VCS_UNSTAGED_ICON $'\u25CF' # ● - VCS_STAGED_ICON $'\u271A' # ✚ - VCS_STASH_ICON $'\u235F' # ⍟ - VCS_INCOMING_CHANGES_ICON $'\u2193' # ↓ - VCS_OUTGOING_CHANGES_ICON $'\u2191' # ↑ - VCS_TAG_ICON '' - VCS_BOOKMARK_ICON $'\u263F' # ☿ - VCS_COMMIT_ICON '' - VCS_BRANCH_ICON $'\uE0A0 ' #  - VCS_REMOTE_BRANCH_ICON $'\u2192' # → - VCS_GIT_ICON '' - VCS_GIT_GITHUB_ICON '' - VCS_GIT_BITBUCKET_ICON '' - VCS_GIT_GITLAB_ICON '' - VCS_HG_ICON '' - VCS_SVN_ICON '' - RUST_ICON 'Rust' - PYTHON_ICON '' - SWIFT_ICON 'Swift' - GO_ICON 'Go' - PUBLIC_IP_ICON '' - LOCK_ICON $'\UE0A2' - EXECUTION_TIME_ICON 'Dur' - SSH_ICON '(ssh)' - VPN_ICON '(vpn)' - KUBERNETES_ICON $'\U2388' # ⎈ - DROPBOX_ICON 'Dropbox' - DATE_ICON '' - TIME_ICON '' - JAVA_ICON $'\U2615' # ☕︎ - LARAVEL_ICON '' - ) - ;; -esac +function _p9k_init_icons() { + case $POWERLEVEL9K_MODE in + 'flat'|'awesome-patched') + # Awesome-Patched Font required! See: + # https://github.com/gabrielelana/awesome-terminal-fonts/tree/patching-strategy/patched + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace + LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  + CARRIAGE_RETURN_ICON $'\u21B5' # ↵ + ROOT_ICON $'\uE801' #  + SUDO_ICON $'\uF09C' #  + RUBY_ICON $'\uE847 ' #  + AWS_ICON $'\uE895' #  + AWS_EB_ICON $'\U1F331 ' # 🌱 + BACKGROUND_JOBS_ICON $'\uE82F ' #  + TEST_ICON $'\uE891' #  + TODO_ICON $'\u2611' # ☑ + BATTERY_ICON $'\uE894' #  + DISK_ICON $'\uE1AE ' #  + OK_ICON $'\u2714' # ✔ + FAIL_ICON $'\u2718' # ✘ + SYMFONY_ICON 'SF' + NODE_ICON $'\u2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + APPLE_ICON $'\uE26E' #  + WINDOWS_ICON $'\uE26F' #  + FREEBSD_ICON $'\U1F608 ' # 😈 + ANDROID_ICON $'\uE270' #  + LINUX_ICON $'\uE271' #  + LINUX_ARCH_ICON $'\uE271' #  + LINUX_DEBIAN_ICON $'\uE271' #  + LINUX_UBUNTU_ICON $'\uE271' #  + LINUX_CENTOS_ICON $'\uE271' #  + LINUX_COREOS_ICON $'\uE271' #  + LINUX_ELEMENTARY_ICON $'\uE271' #  + LINUX_MINT_ICON $'\uE271' #  + LINUX_FEDORA_ICON $'\uE271' #  + LINUX_GENTOO_ICON $'\uE271' #  + LINUX_MAGEIA_ICON $'\uE271' #  + LINUX_NIXOS_ICON $'\uE271' #  + LINUX_MANJARO_ICON $'\uE271' #  + LINUX_DEVUAN_ICON $'\uE271' #  + LINUX_ALPINE_ICON $'\uE271' #  + LINUX_AOSC_ICON $'\uE271' #  + LINUX_OPENSUSE_ICON $'\uE271' #  + LINUX_SABAYON_ICON $'\uE271' #  + LINUX_SLACKWARE_ICON $'\uE271' #  + SUNOS_ICON $'\U1F31E ' # 🌞 + HOME_ICON $'\uE12C' #  + HOME_SUB_ICON $'\uE18D' #  + FOLDER_ICON $'\uE818' #  + NETWORK_ICON $'\uE1AD' #  + ETC_ICON $'\uE82F' #  + LOAD_ICON $'\uE190 ' #  + SWAP_ICON $'\uE87D' #  + RAM_ICON $'\uE1E2 ' #  + SERVER_ICON $'\uE895' #  + VCS_UNTRACKED_ICON $'\uE16C' #  + VCS_UNSTAGED_ICON $'\uE17C' #  + VCS_STAGED_ICON $'\uE168' #  + VCS_STASH_ICON $'\uE133 ' #  + #VCS_INCOMING_CHANGES_ICON $'\uE1EB ' #  + #VCS_INCOMING_CHANGES_ICON $'\uE80D ' #  + VCS_INCOMING_CHANGES_ICON $'\uE131 ' #  + #VCS_OUTGOING_CHANGES_ICON $'\uE1EC ' #  + #VCS_OUTGOING_CHANGES_ICON $'\uE80E ' #  + VCS_OUTGOING_CHANGES_ICON $'\uE132 ' #  + VCS_TAG_ICON $'\uE817 ' #  + VCS_BOOKMARK_ICON $'\uE87B' #  + VCS_COMMIT_ICON $'\uE821 ' #  + VCS_BRANCH_ICON $'\uE220 ' #  + VCS_REMOTE_BRANCH_ICON $'\u2192' # → + VCS_GIT_ICON $'\uE20E ' #  + VCS_GIT_GITHUB_ICON $'\uE20E ' # + VCS_GIT_BITBUCKET_ICON $'\uE20E ' # + VCS_GIT_GITLAB_ICON $'\uE20E ' # + VCS_HG_ICON $'\uE1C3 ' #  + VCS_SVN_ICON '(svn) ' + RUST_ICON '(rust)' + PYTHON_ICON $'\ue63c' #  + SWIFT_ICON '' + GO_ICON '' + PUBLIC_IP_ICON '' + LOCK_ICON $'\UE138' #  + EXECUTION_TIME_ICON $'\UE89C' #  + SSH_ICON '(ssh)' + VPN_ICON '(vpn)' + KUBERNETES_ICON $'\U2388' # ⎈ + DROPBOX_ICON $'\UF16B' #  + DATE_ICON $'\uE184' #  + TIME_ICON $'\uE12E' #  + JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' + ) + ;; + 'awesome-fontconfig') + # fontconfig with awesome-font required! See + # https://github.com/gabrielelana/awesome-terminal-fonts + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace + LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  + CARRIAGE_RETURN_ICON $'\u21B5' # ↵ + ROOT_ICON $'\uF201' #  + SUDO_ICON $'\uF09C' #  + RUBY_ICON $'\uF219 ' #  + AWS_ICON $'\uF270' #  + AWS_EB_ICON $'\U1F331 ' # 🌱 + BACKGROUND_JOBS_ICON $'\uF013 ' #  + TEST_ICON $'\uF291' #  + TODO_ICON $'\u2611' # ☑ + BATTERY_ICON $'\U1F50B' # 🔋 + DISK_ICON $'\uF0A0 ' #  + OK_ICON $'\u2714' # ✔ + FAIL_ICON $'\u2718' # ✘ + SYMFONY_ICON 'SF' + NODE_ICON $'\u2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + APPLE_ICON $'\uF179' #  + WINDOWS_ICON $'\uF17A' #  + FREEBSD_ICON $'\U1F608 ' # 😈 + ANDROID_ICON $'\uE17B' #  + LINUX_ICON $'\uF17C' #  + LINUX_ARCH_ICON $'\uF17C' #  + LINUX_DEBIAN_ICON $'\uF17C' #  + LINUX_UBUNTU_ICON $'\uF17C' #  + LINUX_CENTOS_ICON $'\uF17C' #  + LINUX_COREOS_ICON $'\uF17C' #  + LINUX_ELEMENTARY_ICON $'\uF17C' #  + LINUX_MINT_ICON $'\uF17C' #  + LINUX_FEDORA_ICON $'\uF17C' #  + LINUX_GENTOO_ICON $'\uF17C' #  + LINUX_MAGEIA_ICON $'\uF17C' #  + LINUX_NIXOS_ICON $'\uF17C' #  + LINUX_MANJARO_ICON $'\uF17C' #  + LINUX_DEVUAN_ICON $'\uF17C' #  + LINUX_ALPINE_ICON $'\uF17C' #  + LINUX_AOSC_ICON $'\uF17C' #  + LINUX_OPENSUSE_ICON $'\uF17C' #  + LINUX_SABAYON_ICON $'\uF17C' #  + LINUX_SLACKWARE_ICON $'\uF17C' #  + SUNOS_ICON $'\uF185 ' #  + HOME_ICON $'\uF015' #  + HOME_SUB_ICON $'\uF07C' #  + FOLDER_ICON $'\uF115' #  + ETC_ICON $'\uF013 ' #  + NETWORK_ICON $'\uF09E' #  + LOAD_ICON $'\uF080 ' #  + SWAP_ICON $'\uF0E4' #  + RAM_ICON $'\uF0E4' #  + SERVER_ICON $'\uF233' #  + VCS_UNTRACKED_ICON $'\uF059' #  + VCS_UNSTAGED_ICON $'\uF06A' #  + VCS_STAGED_ICON $'\uF055' #  + VCS_STASH_ICON $'\uF01C ' #  + VCS_INCOMING_CHANGES_ICON $'\uF01A ' #  + VCS_OUTGOING_CHANGES_ICON $'\uF01B ' #  + VCS_TAG_ICON $'\uF217 ' #  + VCS_BOOKMARK_ICON $'\uF27B' #  + VCS_COMMIT_ICON $'\uF221 ' #  + VCS_BRANCH_ICON $'\uF126 ' #  + VCS_REMOTE_BRANCH_ICON $'\u2192' # → + VCS_GIT_ICON $'\uF1D3 ' #  + VCS_GIT_GITHUB_ICON $'\uF113 ' #  + VCS_GIT_BITBUCKET_ICON $'\uF171 ' #  + VCS_GIT_GITLAB_ICON $'\uF296 ' #  + VCS_HG_ICON $'\uF0C3 ' #  + VCS_SVN_ICON '(svn) ' + RUST_ICON $'\uE6A8' #  + PYTHON_ICON $'\ue63c' #  + SWIFT_ICON '' + GO_ICON '' + PUBLIC_IP_ICON '' + LOCK_ICON $'\UF023' #  + EXECUTION_TIME_ICON $'\uF253' + SSH_ICON '(ssh)' + VPN_ICON $'\uF023' + KUBERNETES_ICON $'\U2388' # ⎈ + DROPBOX_ICON $'\UF16B' #  + DATE_ICON $'\uF073 ' #  + TIME_ICON $'\uF017 ' #  + JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' + ) + ;; + 'awesome-mapped-fontconfig') + # mapped fontconfig with awesome-font required! See + # https://github.com/gabrielelana/awesome-terminal-fonts + # don't forget to source the font maps in your startup script + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" -# Override the above icon settings with any user-defined variables. -case $POWERLEVEL9K_MODE in - 'flat') - # Set the right locale to protect special characters - local LC_ALL="" LC_CTYPE="en_US.UTF-8" - icons[LEFT_SEGMENT_SEPARATOR]='' - icons[RIGHT_SEGMENT_SEPARATOR]='' - icons[LEFT_SUBSEGMENT_SEPARATOR]='|' - icons[RIGHT_SUBSEGMENT_SEPARATOR]='|' - ;; - 'compatible') - # Set the right locale to protect special characters - local LC_ALL="" LC_CTYPE="en_US.UTF-8" - icons[LEFT_SEGMENT_SEPARATOR]=$'\u2B80' # ⮀ - icons[RIGHT_SEGMENT_SEPARATOR]=$'\u2B82' # ⮂ - icons[VCS_BRANCH_ICON]='@' - ;; -esac + if [ -z "$AWESOME_GLYPHS_LOADED" ]; then + echo "Powerlevel9k warning: Awesome-Font mappings have not been loaded. + Source a font mapping in your shell config, per the Awesome-Font docs + (https://github.com/gabrielelana/awesome-terminal-fonts), + Or use a different Powerlevel9k font configuration."; + fi -if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then - icons[VCS_BRANCH_ICON]='' -fi + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace + LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  + 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 ' # 🌱 + BACKGROUND_JOBS_ICON '\u'$CODEPOINT_OF_AWESOME_COG' ' #  + TEST_ICON '\u'$CODEPOINT_OF_AWESOME_BUG #  + TODO_ICON '\u'$CODEPOINT_OF_AWESOME_CHECK_SQUARE_O #  + BATTERY_ICON '\U'$CODEPOINT_OF_AWESOME_BATTERY_FULL #  + DISK_ICON '\u'$CODEPOINT_OF_AWESOME_HDD_O' ' #  + OK_ICON '\u'$CODEPOINT_OF_AWESOME_CHECK #  + FAIL_ICON '\u'$CODEPOINT_OF_AWESOME_TIMES #  + SYMFONY_ICON 'SF' + NODE_ICON $'\u2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + APPLE_ICON '\u'$CODEPOINT_OF_AWESOME_APPLE #  + FREEBSD_ICON $'\U1F608 ' # 😈 + LINUX_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_ARCH_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_DEBIAN_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_UBUNTU_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_CENTOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_COREOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_ELEMENTARY_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_MINT_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_FEDORA_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_GENTOO_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_MAGEIA_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_NIXOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_MANJARO_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_DEVUAN_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_ALPINE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_AOSC_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_OPENSUSE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_SABAYON_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_SLACKWARE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + SUNOS_ICON '\u'$CODEPOINT_OF_AWESOME_SUN_O' ' #  + HOME_ICON '\u'$CODEPOINT_OF_AWESOME_HOME #  + HOME_SUB_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_OPEN #  + FOLDER_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_O #  + ETC_ICON '\u'$CODEPOINT_OF_AWESOME_COG' ' #  + NETWORK_ICON '\u'$CODEPOINT_OF_AWESOME_RSS #  + LOAD_ICON '\u'$CODEPOINT_OF_AWESOME_BAR_CHART' ' #  + SWAP_ICON '\u'$CODEPOINT_OF_AWESOME_DASHBOARD #  + RAM_ICON '\u'$CODEPOINT_OF_AWESOME_DASHBOARD #  + SERVER_ICON '\u'$CODEPOINT_OF_AWESOME_SERVER #  + VCS_UNTRACKED_ICON '\u'$CODEPOINT_OF_AWESOME_QUESTION_CIRCLE #  + VCS_UNSTAGED_ICON '\u'$CODEPOINT_OF_AWESOME_EXCLAMATION_CIRCLE #  + VCS_STAGED_ICON '\u'$CODEPOINT_OF_AWESOME_PLUS_CIRCLE #  + VCS_STASH_ICON '\u'$CODEPOINT_OF_AWESOME_INBOX' ' #  + VCS_INCOMING_CHANGES_ICON '\u'$CODEPOINT_OF_AWESOME_ARROW_CIRCLE_DOWN' ' #  + VCS_OUTGOING_CHANGES_ICON '\u'$CODEPOINT_OF_AWESOME_ARROW_CIRCLE_UP' ' #  + VCS_TAG_ICON '\u'$CODEPOINT_OF_AWESOME_TAG' ' #  + VCS_BOOKMARK_ICON '\u'$CODEPOINT_OF_OCTICONS_BOOKMARK #  + VCS_COMMIT_ICON '\u'$CODEPOINT_OF_OCTICONS_GIT_COMMIT' ' #  + VCS_BRANCH_ICON '\u'$CODEPOINT_OF_OCTICONS_GIT_BRANCH' ' #  + VCS_REMOTE_BRANCH_ICON '\u'$CODEPOINT_OF_OCTICONS_REPO_PUSH #  + VCS_GIT_ICON '\u'$CODEPOINT_OF_AWESOME_GIT' ' #  + VCS_GIT_GITHUB_ICON '\u'$CODEPOINT_OF_AWESOME_GITHUB_ALT' ' #  + VCS_GIT_BITBUCKET_ICON '\u'$CODEPOINT_OF_AWESOME_BITBUCKET' ' #  + VCS_GIT_GITLAB_ICON '\u'$CODEPOINT_OF_AWESOME_GITLAB' ' #  + VCS_HG_ICON '\u'$CODEPOINT_OF_AWESOME_FLASK' ' #  + VCS_SVN_ICON '(svn) ' + RUST_ICON $'\uE6A8' #  + PYTHON_ICON $'\U1F40D' # 🐍 + SWIFT_ICON $'\uE655' #  + PUBLIC_IP_ICON '\u'$CODEPOINT_OF_AWESOME_GLOBE #  + LOCK_ICON '\u'$CODEPOINT_OF_AWESOME_LOCK #  + EXECUTION_TIME_ICON '\u'$CODEPOINT_OF_AWESOME_HOURGLASS_END #  + SSH_ICON '(ssh)' + VPN_ICON '\u'$CODEPOINT_OF_AWESOME_LOCK + KUBERNETES_ICON $'\U2388' # ⎈ + DROPBOX_ICON '\u'$CODEPOINT_OF_AWESOME_DROPBOX #  + DATE_ICON $'\uF073 ' #  + TIME_ICON $'\uF017 ' #  + JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' + ) + ;; + 'nerdfont-complete'|'nerdfont-fontconfig') + # nerd-font patched (complete) font required! See + # https://github.com/ryanoasis/nerd-fonts + # http://nerdfonts.com/#cheat-sheet + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace + LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  + CARRIAGE_RETURN_ICON $'\u21B5' # ↵ + ROOT_ICON $'\uE614 ' #  + SUDO_ICON $'\uF09C' #  + RUBY_ICON $'\uF219 ' #  + AWS_ICON $'\uF270' #  + AWS_EB_ICON $'\UF1BD ' #  + BACKGROUND_JOBS_ICON $'\uF013 ' #  + TEST_ICON $'\uF188' #  + TODO_ICON $'\uF133' #  + BATTERY_ICON $'\UF240 ' #  + DISK_ICON $'\uF0A0' #  + OK_ICON $'\uF00C' #  + FAIL_ICON $'\uF00D' #  + SYMFONY_ICON $'\uE757' #  + NODE_ICON $'\uE617 ' #  + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + APPLE_ICON $'\uF179' #  + WINDOWS_ICON $'\uF17A' #  + FREEBSD_ICON $'\UF30C ' #  + ANDROID_ICON $'\uF17B' #  + LINUX_ARCH_ICON $'\uF303' #  + LINUX_CENTOS_ICON $'\uF304' #  + LINUX_COREOS_ICON $'\uF305' #  + LINUX_DEBIAN_ICON $'\uF306' #  + LINUX_ELEMENTARY_ICON $'\uF309' #  + LINUX_FEDORA_ICON $'\uF30a' #  + LINUX_GENTOO_ICON $'\uF30d' #  + LINUX_MAGEIA_ICON $'\uF310' #  + LINUX_MINT_ICON $'\uF30e' #  + LINUX_NIXOS_ICON $'\uF313' #  + LINUX_MANJARO_ICON $'\uF312' #  + LINUX_DEVUAN_ICON $'\uF307' #  + LINUX_ALPINE_ICON $'\uF300' #  + LINUX_AOSC_ICON $'\uF301' #  + LINUX_OPENSUSE_ICON $'\uF314' #  + LINUX_SABAYON_ICON $'\uF317' #  + LINUX_SLACKWARE_ICON $'\uF319' #  + LINUX_UBUNTU_ICON $'\uF31b' #  + LINUX_ICON $'\uF17C' #  + SUNOS_ICON $'\uF185 ' #  + HOME_ICON $'\uF015' #  + HOME_SUB_ICON $'\uF07C' #  + FOLDER_ICON $'\uF115' #  + ETC_ICON $'\uF013' #  + NETWORK_ICON $'\uF1EB' #  + LOAD_ICON $'\uF080 ' #  + SWAP_ICON $'\uF464' #  + RAM_ICON $'\uF0E4' #  + SERVER_ICON $'\uF0AE' #  + VCS_UNTRACKED_ICON $'\uF059' #  + VCS_UNSTAGED_ICON $'\uF06A' #  + VCS_STAGED_ICON $'\uF055' #  + VCS_STASH_ICON $'\uF01C ' #  + VCS_INCOMING_CHANGES_ICON $'\uF01A ' #  + VCS_OUTGOING_CHANGES_ICON $'\uF01B ' #  + VCS_TAG_ICON $'\uF02B ' #  + VCS_BOOKMARK_ICON $'\uF461 ' #  + VCS_COMMIT_ICON $'\uE729 ' #  + VCS_BRANCH_ICON $'\uF126 ' #  + VCS_REMOTE_BRANCH_ICON $'\uE728 ' #  + VCS_GIT_ICON $'\uF1D3 ' #  + VCS_GIT_GITHUB_ICON $'\uF113 ' #  + VCS_GIT_BITBUCKET_ICON $'\uE703 ' #  + VCS_GIT_GITLAB_ICON $'\uF296 ' #  + VCS_HG_ICON $'\uF0C3 ' #  + VCS_SVN_ICON $'\uE72D ' #  + RUST_ICON $'\uE7A8 ' #  + PYTHON_ICON $'\UE73C ' #  + SWIFT_ICON $'\uE755' #  + GO_ICON $'\uE626' #  + PUBLIC_IP_ICON $'\UF0AC' #  + LOCK_ICON $'\UF023' #  + EXECUTION_TIME_ICON $'\uF252' #  + SSH_ICON $'\uF489' #  + VPN_ICON '(vpn)' + KUBERNETES_ICON $'\U2388' # ⎈ + DROPBOX_ICON $'\UF16B' #  + DATE_ICON $'\uF073 ' #  + TIME_ICON $'\uF017 ' #  + JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON $'\ue73f ' #  + ) + ;; + *) + # Powerline-Patched Font required! + # See https://github.com/Lokaltog/powerline-fonts + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace + LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  + CARRIAGE_RETURN_ICON $'\u21B5' # ↵ + ROOT_ICON $'\u26A1' # ⚡ + SUDO_ICON $'\uE0A2' #  + RUBY_ICON '' + AWS_ICON 'AWS:' + AWS_EB_ICON $'\U1F331 ' # 🌱 + BACKGROUND_JOBS_ICON $'\u2699' # ⚙ + TEST_ICON '' + TODO_ICON $'\u2611' # ☑ + BATTERY_ICON $'\U1F50B' # 🔋 + DISK_ICON $'hdd ' + OK_ICON $'\u2714' # ✔ + FAIL_ICON $'\u2718' # ✘ + SYMFONY_ICON 'SF' + NODE_ICON $'\u2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + APPLE_ICON 'OSX' + WINDOWS_ICON 'WIN' + 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_NIXOS_ICON 'Nix' + LINUX_MANJARO_ICON 'Man' + LINUX_DEVUAN_ICON 'Dev' + LINUX_ALPINE_ICON 'Alp' + LINUX_AOSC_ICON 'Aos' + LINUX_OPENSUSE_ICON 'OSu' + LINUX_SABAYON_ICON 'Sab' + LINUX_SLACKWARE_ICON 'Sla' + SUNOS_ICON 'Sun' + HOME_ICON '' + HOME_SUB_ICON '' + FOLDER_ICON '' + ETC_ICON $'\u2699' # ⚙ + NETWORK_ICON 'IP' + LOAD_ICON 'L' + SWAP_ICON 'SWP' + RAM_ICON 'RAM' + SERVER_ICON '' + VCS_UNTRACKED_ICON '?' + VCS_UNSTAGED_ICON $'\u25CF' # ● + VCS_STAGED_ICON $'\u271A' # ✚ + VCS_STASH_ICON $'\u235F' # ⍟ + VCS_INCOMING_CHANGES_ICON $'\u2193' # ↓ + VCS_OUTGOING_CHANGES_ICON $'\u2191' # ↑ + VCS_TAG_ICON '' + VCS_BOOKMARK_ICON $'\u263F' # ☿ + VCS_COMMIT_ICON '' + VCS_BRANCH_ICON $'\uE0A0 ' #  + VCS_REMOTE_BRANCH_ICON $'\u2192' # → + VCS_GIT_ICON '' + VCS_GIT_GITHUB_ICON '' + VCS_GIT_BITBUCKET_ICON '' + VCS_GIT_GITLAB_ICON '' + VCS_HG_ICON '' + VCS_SVN_ICON '' + RUST_ICON 'Rust' + PYTHON_ICON '' + SWIFT_ICON 'Swift' + GO_ICON 'Go' + PUBLIC_IP_ICON '' + LOCK_ICON $'\UE0A2' + EXECUTION_TIME_ICON 'Dur' + SSH_ICON '(ssh)' + VPN_ICON '(vpn)' + KUBERNETES_ICON $'\U2388' # ⎈ + DROPBOX_ICON 'Dropbox' + DATE_ICON '' + TIME_ICON '' + JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' + ) + ;; + esac + + # Override the above icon settings with any user-defined variables. + case $POWERLEVEL9K_MODE in + 'flat') + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons[LEFT_SEGMENT_SEPARATOR]='' + icons[RIGHT_SEGMENT_SEPARATOR]='' + icons[LEFT_SUBSEGMENT_SEPARATOR]='|' + icons[RIGHT_SUBSEGMENT_SEPARATOR]='|' + ;; + 'compatible') + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons[LEFT_SEGMENT_SEPARATOR]=$'\u2B80' # ⮀ + icons[RIGHT_SEGMENT_SEPARATOR]=$'\u2B82' # ⮂ + icons[VCS_BRANCH_ICON]='@' + ;; + esac + + if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then + icons[VCS_BRANCH_ICON]='' + fi } # Safety function for printing icons # Prints the named icon, or if that icon is undefined, the string name. function print_icon() { local icon_name=$1 - local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} - if defined "$ICON_USER_VARIABLE"; then + local var_name=POWERLEVEL9K_${icon_name} + if [[ -v "$var_name" ]]; then echo -n "${(P)ICON_USER_VARIABLE}" else echo -n "${icons[$icon_name]}" @@ -547,7 +551,7 @@ function print_icon() { # * $1 string - If "original", then the original icons are printed, # otherwise "print_icon" is used, which takes the users # overrides into account. -get_icon_names() { +function get_icon_names() { # Iterate over a ordered list of keys of the icons array for key in ${(@kon)icons}; do echo -n "POWERLEVEL9K_$key: " diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 8c18bb44..3a77eaca 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -6,22 +6,28 @@ # https://github.com/bhilburn/powerlevel9k ################################################################ -# Exits with 0 if a variable has been previously defined (even if empty) -# Takes the name of a variable that should be checked. -function defined() { - [[ ! -z "${(tP)1}" ]] -} - -# Given the name of a variable and a default value, sets the variable -# value to the default only if it has not been defined. +# Usage: set_default [OPTION]... NAME [VALUE]... # -# Typeset cannot set the value for an array, so this will only work -# for scalar values. +# Options are the same as in `typeset`. function set_default() { - local varname="$1" - local default_value="$2" + local -a flags=(-g) + while true; do + case $1 in + --) shift; break;; + -*) flags+=$1; shift;; + *) break; + esac + done - defined "$varname" || typeset -g "$varname"="$default_value" + local varname=$1 + shift + if [[ -v $varname ]]; then + typeset $flags $varname + elif [[ "$flags" == *[aA]* ]]; then + eval "typeset ${(@q)flags} ${(q)varname}=(${(qq)@})" + else + typeset $flags $varname="$*" + fi } # Converts large memory values into a human-readable unit (e.g., bytes --> GB) @@ -54,224 +60,15 @@ printSizeHumanReadable() { echo "$size${extension[$index]}" } -# Gets the first value out of a list of items that is not empty. -# The items are examined by a callback-function. -# Takes two arguments: -# * $list - A list of items -# * $callback - A callback function to examine if the item is -# worthy. The callback function has access to -# the inner variable $item. -function getRelevantItem() { - local -a list - local callback - # Explicitly split the elements by whitespace. - list=(${=1}) - callback=$2 - - for item in $list; do - # The first non-empty item wins - try=$(eval "$callback") - if [[ -n "$try" ]]; then - echo "$try" - break; - fi - done -} - -# OS detection -case $(uname) in - Darwin) - OS='OSX' - OS_ICON=$(print_icon 'APPLE_ICON') - ;; - CYGWIN_NT-* | MSYS_NT-*) - OS='Windows' - OS_ICON=$(print_icon 'WINDOWS_ICON') - ;; - FreeBSD) - OS='BSD' - OS_ICON=$(print_icon 'FREEBSD_ICON') - ;; - OpenBSD) - OS='BSD' - OS_ICON=$(print_icon 'FREEBSD_ICON') - ;; - DragonFly) - OS='BSD' - OS_ICON=$(print_icon 'FREEBSD_ICON') - ;; - Linux) - OS='Linux' - if [ -f /etc/os-release ]; then - [[ ${(f)"$((/dev/null)"} =~ "ID=([A-Za-z]+)" ]] && os_release_id="${match[1]}" - fi - 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') - ;; - *alpine*) - OS_ICON=$(print_icon 'LINUX_ALPINE_ICON') - ;; - *aosc*) - OS_ICON=$(print_icon 'LINUX_AOSC_ICON') - ;; - *nixos*) - OS_ICON=$(print_icon 'LINUX_NIXOS_ICON') - ;; - *devuan*) - OS_ICON=$(print_icon 'LINUX_DEVUAN_ICON') - ;; - *manjaro*) - OS_ICON=$(print_icon 'LINUX_MANJARO_ICON') - ;; - *) - OS='Linux' - OS_ICON=$(print_icon 'LINUX_ICON') - ;; - esac - - # Check if we're running on Android - case $(uname -o 2>/dev/null) in - Android) - OS='Android' - OS_ICON=$(print_icon 'ANDROID_ICON') - ;; - esac - ;; - SunOS) - OS='Solaris' - OS_ICON=$(print_icon 'SUNOS_ICON') - ;; - *) - OS='' - OS_ICON='' - ;; -esac - -# Determine the correct sed parameter. -# -# `sed` is unfortunately not consistent across OSes when it comes to flags. -SED_EXTENDED_REGEX_PARAMETER="-r" -if [[ "$OS" == 'OSX' ]]; then - local IS_BSD_SED="$(sed --version &>> /dev/null || echo "BSD sed")" - if [[ -n "$IS_BSD_SED" ]]; then - SED_EXTENDED_REGEX_PARAMETER="-E" - fi -fi - # Determine if the passed segment is used in the prompt # # Pass the name of the segment to this function to test for its presence in # either the LEFT or RIGHT prompt arrays. # * $1: The segment to be tested. segment_in_use() { - local key=$1 - if [[ -n "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[(r)$key]}" ]] || [[ -n "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[(r)$key]}" ]]; then - return 0 - else - return 1 - fi -} - -# Print a deprecation warning if an old segment is in use. -# Takes the name of an associative array that contains the -# deprecated segments as keys, the values contain the new -# segment names. -print_deprecation_warning() { - typeset -AH raw_deprecated_segments - raw_deprecated_segments=(${(kvP@)1}) - - for key in ${(@k)raw_deprecated_segments}; do - if segment_in_use $key; then - # segment is deprecated - print -P "%F{yellow}Warning!%f The '$key' segment is deprecated. Use '%F{blue}${raw_deprecated_segments[$key]}%f' instead. For more informations, have a look at the CHANGELOG.md." - fi - done -} - -# A helper function to determine if a segment should be -# joined or promoted to a full one. -# Takes three arguments: -# * $1: The array index of the current segment -# * $2: The array index of the last printed segment -# * $3: The array of segments of the left or right prompt -function segmentShouldBeJoined() { - local current_index=$1 - local last_segment_index=$2 - # Explicitly split the elements by whitespace. - local -a elements - elements=(${=3}) - - local current_segment=${elements[$current_index]} - local joined=false - if [[ ${current_segment[-7,-1]} == '_joined' ]]; then - joined=true - # promote segment to a full one, if the predecessing full segment - # was conditional. So this can only be the case for segments that - # are not our direct predecessor. - if (( $(($current_index - $last_segment_index)) > 1)); then - # Now we have to examine every previous segment, until we reach - # the last printed one (found by its index). This is relevant if - # all previous segments are joined. Then we want to join our - # segment as well. - local examined_index=$((current_index - 1)) - while (( $examined_index > $last_segment_index )); do - local previous_segment=${elements[$examined_index]} - # If one of the examined segments is not joined, then we know - # that the current segment should not be joined, as the target - # segment is the wrong one. - if [[ ${previous_segment[-7,-1]} != '_joined' ]]; then - joined=false - break - fi - examined_index=$((examined_index - 1)) - done - fi - fi - - # Return 1 means error; return 0 means no error. So we have - # to invert $joined - if [[ "$joined" == "true" ]]; then - return 0 - else - return 1 - fi + local key=$1 + [[ -n "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[(r)$key]}" || + -n "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[(r)$key]}" ]] } ################################################################ @@ -350,14 +147,6 @@ function truncatePath() { fi } -# Given a directory path, truncate it according to the settings for -# `truncate_from_right` -function truncatePathFromRight() { - local delim_len=${#POWERLEVEL9K_SHORTEN_DELIMITER:-1} - echo $1 | sed $SED_EXTENDED_REGEX_PARAMETER \ - "s@(([^/]{$((POWERLEVEL9K_SHORTEN_DIR_LENGTH))})([^/]{$delim_len}))[^/]+/@\2$POWERLEVEL9K_SHORTEN_DELIMITER/@g" -} - # Search recursively in parent folders for given file. function upsearch () { if [[ "$PWD" == "$HOME" || "$PWD" == "/" ]]; then diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c022984f..a5ccd467 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -20,15 +20,17 @@ #zstyle ':vcs_info:*+*:*' debug true #set -o xtrace +typeset -g _P9K_INSTALLATION_DIR + # Try to set the installation path if [[ -n "$POWERLEVEL9K_INSTALLATION_DIR" ]]; then - p9k_directory=${POWERLEVEL9K_INSTALLATION_DIR:A} + _P9K_INSTALLATION_DIR=${POWERLEVEL9K_INSTALLATION_DIR:A} else if [[ "${(%):-%N}" == '(eval)' ]]; then if [[ "$0" == '-antigen-load' ]] && [[ -r "${PWD}/powerlevel9k.zsh-theme" ]]; then # Antigen uses eval to load things so it can change the plugin (!!) # https://github.com/zsh-users/antigen/issues/581 - p9k_directory=$PWD + _P9K_INSTALLATION_DIR=$PWD else print -P "%F{red}You must set POWERLEVEL9K_INSTALLATION_DIR work from within an (eval).%f" return 1 @@ -37,77 +39,24 @@ else # Get the path to file this code is executing in; then # get the absolute path and strip the filename. # See https://stackoverflow.com/a/28336473/108857 - p9k_directory=${${(%):-%x}:A:h} + _P9K_INSTALLATION_DIR=${${(%):-%x}:A:h} fi fi -################################################################ -# Source icon functions -################################################################ +source "${_P9K_INSTALLATION_DIR}/functions/utilities.zsh" +source "${_P9K_INSTALLATION_DIR}/functions/icons.zsh" +source "${_P9K_INSTALLATION_DIR}/functions/colors.zsh" +source "${_P9K_INSTALLATION_DIR}/functions/vcs.zsh" -source "${p9k_directory}/functions/icons.zsh" - -################################################################ -# Source utility functions -################################################################ - -source "${p9k_directory}/functions/utilities.zsh" - -################################################################ -# Source color functions -################################################################ - -source "${p9k_directory}/functions/colors.zsh" - -################################################################ -# Source VCS_INFO hooks / helper functions -################################################################ - -source "${p9k_directory}/functions/vcs.zsh" - -if [[ $POWERLEVEL9K_DISABLE_GITSTATUS != true ]]; then - source ${POWERLEVEL9K_GITSTATUS_DIR:-${p9k_directory}/gitstatus}/gitstatus.plugin.zsh -fi - -# cleanup temporary variables. -unset p9k_directory - -[[ -v POWERLEVEL9K_LEFT_PROMPT_ELEMENTS ]] || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs) -[[ -v POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS ]] || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time) - -################################################################ -# Color Scheme -################################################################ - -if [[ "$POWERLEVEL9K_COLOR_SCHEME" == "light" ]]; then - DEFAULT_COLOR=white - DEFAULT_COLOR_INVERTED=black -else - DEFAULT_COLOR=black - DEFAULT_COLOR_INVERTED=white -fi - -################################################################ -# Prompt Segment Constructors -# -# Methodology behind user-defined variables overwriting colors: -# The first parameter to the segment constructors is the calling function's -# name. From this function name, we strip the "prompt_"-prefix and -# uppercase it. This is then prefixed with "POWERLEVEL9K_" and suffixed -# with either "_BACKGROUND" or "_FOREGROUND", thus giving us the variable -# name. So each new segment is user-overwritten by a variable following -# this naming convention. -################################################################ +typeset -g _P9K_RETVAL +typeset -g _P9K_CACHE_KEY +typeset -ga _P9K_CACHE_VAL +typeset -gA _P9K_CACHE # Specifies the maximum number of elements in the cache. When the cache grows over this limit, # it gets cleared. This is meant to avoid memory leaks when a rogue prompt is filling the cache # with data. -[ -v POWERLEVEL9K_MAX_CACHE_SIZE ] || typeset -gi POWERLEVEL9K_MAX_CACHE_SIZE=10000 - -typeset -gH _P9K_RETVAL -typeset -gH _P9K_CACHE_KEY -typeset -gaH _P9K_CACHE_VAL -typeset -gAH _P9K_CACHE=() +set_default -i POWERLEVEL9K_MAX_CACHE_SIZE 10000 # Note: Several performance-critical functions return results to the caller via global # variabls rather than stdout. This is faster. @@ -146,28 +95,11 @@ _p9k_get_icon() { _P9K_RETVAL=${(g::)${${(P)var_name}-$icons[$1]}} } -typeset -gaH _P9K_LEFT_JOIN=(1) -() { - local i - for ((i = 2; i <= $#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS; ++i)); do - local elem=$POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[$i] - if [[ ${elem[-7,-1]} == '_joined' ]]; then - _P9K_LEFT_JOIN+=$_P9K_LEFT_JOIN[((i-1))] - else - _P9K_LEFT_JOIN+=$i - fi - done +typeset -ga _P9K_LEFT_JOIN=(1) +typeset -ga _P9K_RIGHT_JOIN=(1) - typeset -gaH _P9K_RIGHT_JOIN=(1) - for ((i = 2; i <= $#POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS; ++i)); do - local elem=$POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[$i] - if [[ ${elem[-7,-1]} == '_joined' ]]; then - _P9K_RIGHT_JOIN+=$_P9K_RIGHT_JOIN[((i-1))] - else - _P9K_RIGHT_JOIN+=$i - fi - done -} +typeset -g _P9K_CURRENT_BG +typeset -gi _P9K_LAST_SEGMENT_INDEX _p9k_should_join_left() [[ $_P9K_LAST_SEGMENT_INDEX -ge ${_P9K_LEFT_JOIN[$1]:-$1} ]] _p9k_should_join_right() [[ $_P9K_LAST_SEGMENT_INDEX -ge ${_P9K_RIGHT_JOIN[$1]:-$1} ]] @@ -206,8 +138,9 @@ _p9k_foreground() { # The latter three can be omitted, set_default POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS " " left_prompt_segment() { - _p9k_should_join_left $2 && local join=true || local join=false - if ! _p9k_cache_get "$0" "$1" "$3" "$4" "${5:+1}" "$6" "$_P9K_CURRENT_BG" "$join"; then + _p9k_should_join_left $2 + local -i separate=$? + if ! _p9k_cache_get "$0" "$1" "$3" "$4" "${5:+1}" "$6" "$_P9K_CURRENT_BG" "$separate"; then _p9k_color $3 $1 BACKGROUND local background_color=$_P9K_RETVAL @@ -222,7 +155,7 @@ left_prompt_segment() { if [[ $_P9K_CURRENT_BG == NONE ]]; then # The first segment on the line. output+=$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS - elif [[ $join == false ]]; then + elif (( separate )); then if [[ $background_color == $_P9K_CURRENT_BG ]]; then # Middle segment with same color as previous segment # We take the current foreground color as color for our @@ -264,23 +197,6 @@ left_prompt_segment() { _P9K_CURRENT_BG=$_P9K_CACHE_VAL[2] } -# End the left prompt, closes the final segment. -left_prompt_end() { - if ! _p9k_cache_get "$0" "$_P9K_CURRENT_BG"; then - local output="%k" - if [[ $_P9K_CURRENT_BG != NONE ]]; then - _p9k_foreground $_P9K_CURRENT_BG - output+=$_P9K_RETVAL - _p9k_get_icon LEFT_SEGMENT_SEPARATOR - output+="${_P9K_RETVAL}" - fi - _p9k_get_icon LEFT_SEGMENT_END_SEPARATOR - output+="%f${_P9K_RETVAL}" - _p9k_cache_set "$output" - fi - _P9K_PROMPT+="${_P9K_CACHE_VAL[1]}" -} - # Begin a right prompt segment # Takes four arguments: # * $1: Name of the function that was originally invoked (mandatory). @@ -293,8 +209,9 @@ left_prompt_end() { # No ending for the right prompt segment is needed (unlike the left prompt, above). set_default POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS " " right_prompt_segment() { - _p9k_should_join_right $2 && local join=true || local join=false - if ! _p9k_cache_get "$0" "$1" "$3" "$4" "$6" "$_P9K_CURRENT_BG" "$join"; then + _p9k_should_join_right $2 + local -i separate=$? + if ! _p9k_cache_get "$0" "$1" "$3" "$4" "$6" "$_P9K_CURRENT_BG" "$separate"; then _p9k_color $3 $1 BACKGROUND local background_color=$_P9K_RETVAL _p9k_background $background_color @@ -307,7 +224,7 @@ right_prompt_segment() { local output='' - if [[ $_P9K_CURRENT_BG == NONE || $join == false ]]; then + if [[ $_P9K_CURRENT_BG == NONE || $separate != 0 ]]; then if [[ $background_color == $_P9K_CURRENT_BG ]]; then # Middle segment with same color as previous segment # We take the current foreground color as color for our @@ -361,14 +278,13 @@ right_prompt_segment() { ################################################################ # Anaconda Environment +set_default POWERLEVEL9K_ANACONDA_LEFT_DELIMITER "(" +set_default POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER ")" prompt_anaconda() { # Depending on the conda version, either might be set. This # variant works even if both are set. local _path=$CONDA_ENV_PATH$CONDA_PREFIX if ! [ -z "$_path" ]; then - # config - can be overwritten in users' zshrc file. - set_default POWERLEVEL9K_ANACONDA_LEFT_DELIMITER "(" - set_default POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER ")" "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$POWERLEVEL9K_ANACONDA_LEFT_DELIMITER$(basename $_path)$POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER" 'PYTHON_ICON' fi } @@ -377,7 +293,6 @@ prompt_anaconda() { # AWS Profile prompt_aws() { local aws_profile="${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}" - if [[ -n "$aws_profile" ]]; then "$1_prompt_segment" "$0" "$2" red white "$aws_profile" 'AWS_ICON' fi @@ -386,8 +301,8 @@ prompt_aws() { ################################################################ # Current Elastic Beanstalk environment prompt_aws_eb_env() { + # TODO(roman): This is clearly broken. Fix it. local eb_env=$(grep environment .elasticbeanstalk/config.yml 2> /dev/null | awk '{print $2}') - if [[ -n "$eb_env" ]]; then "$1_prompt_segment" "$0" "$2" black green "$eb_env" 'AWS_EB_ICON' fi @@ -411,20 +326,17 @@ prompt_background_jobs() { ################################################################ # A newline in your prompt, so you can segments on multiple lines. +set_default POWERLEVEL9K_PROMPT_ON_NEWLINE false prompt_newline() { - local lws newline [[ "$1" == "right" ]] && return - newline=$'\n' - lws=$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS + local newline=$'\n' + local lws=$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then _p9k_get_icon MULTILINE_NEWLINE_PROMPT_PREFIX newline="${newline}${_P9K_RETVAL}" fi POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS= - "$1_prompt_segment" \ - "$0" \ - "$2" \ - "" "" "${newline}" + "$1_prompt_segment" "$0" "$2" "" "" "${newline}" _P9K_CURRENT_BG=NONE POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws } @@ -432,8 +344,8 @@ prompt_newline() { ################################################################ # Segment that indicates usage level of current partition. set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false -set_default POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90 -set_default POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL 95 +set_default -i POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90 +set_default -i POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL 95 prompt_disk_usage() { local current_state="unknown" typeset -AH hdd_usage_forecolors @@ -474,6 +386,12 @@ prompt_disk_usage() { ################################################################ # Segment that displays the battery status in levels and colors +set_default -i POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10 +set_default -i POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD 999 +set_default -a POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND +set_default POWERLEVEL9K_BATTERY_VERBOSE true +typeset -g POWERLEVEL9K_BATTERY_STAGES + prompt_battery() { # The battery can have four different states - default to 'unknown'. local current_state='unknown' @@ -485,8 +403,6 @@ prompt_battery() { 'disconnected' "$DEFAULT_COLOR_INVERTED" ) local ROOT_PREFIX="${4}" - # Set default values if the user did not configure them - set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10 if [[ $OS =~ OSX && -f "${ROOT_PREFIX}"/usr/bin/pmset && -x "${ROOT_PREFIX}"/usr/bin/pmset ]]; then # obtain battery information from system @@ -556,8 +472,6 @@ prompt_battery() { fi local message - # Default behavior: Be verbose! - set_default POWERLEVEL9K_BATTERY_VERBOSE true if [[ "$POWERLEVEL9K_BATTERY_VERBOSE" == true ]]; then message="$bat_percent%%$remain" else @@ -574,19 +488,19 @@ prompt_battery() { fi fi # return if POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD is set and the battery percentage is greater or equal - if defined POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD && [[ "${bat_percent}" -ge $POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD ]]; then + if (( bat_percent >= POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD )); then return fi - # override the default color if we are using a color level array - if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then - local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) - local offset=$(( ($bat_percent / $segment) + 1 )) - "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" - else - # Draw the prompt_segment - "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" - fi + # override the default color if we are using a color level array + if (( #POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND )); then + local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) + local offset=$(( ($bat_percent / $segment) + 1 )) + "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + else + # Draw the prompt_segment + "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + fi } ################################################################ @@ -596,14 +510,15 @@ prompt_battery() { # * $2 Index: integer # * $3 Joined: bool - If the segment should be joined # * $4 Root Prefix: string - Root prefix for testing purposes +set_default -i POWERLEVEL9K_PUBLIC_IP_TIMEOUT 300 +set_default -a POWERLEVEL9K_PUBLIC_IP_METHODS dig curl wget +set_default POWERLEVEL9K_PUBLIC_IP_NONE "" +set_default POWERLEVEL9K_PUBLIC_IP_FILE "/tmp/p9k_public_ip" +set_default POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me" +set_default POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE "" + prompt_public_ip() { local ROOT_PREFIX="${4}" - # set default values for segment - set_default POWERLEVEL9K_PUBLIC_IP_TIMEOUT "300" - set_default POWERLEVEL9K_PUBLIC_IP_NONE "" - set_default POWERLEVEL9K_PUBLIC_IP_FILE "/tmp/p9k_public_ip" - set_default POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me" - defined POWERLEVEL9K_PUBLIC_IP_METHODS || POWERLEVEL9K_PUBLIC_IP_METHODS=(dig curl wget) # Do we need a fresh IP? local refresh_ip=false @@ -615,7 +530,7 @@ prompt_public_ip() { else timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s))) fi - [[ $timediff -gt $POWERLEVEL9K_PUBLIC_IP_TIMEOUT ]] && refresh_ip=true + (( timediff > POWERLEVEL9K_PUBLIC_IP_TIMEOUT )) && refresh_ip=true # If tmp file is empty get a fresh IP [[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=true [[ -n $POWERLEVEL9K_PUBLIC_IP_NONE ]] && [[ $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) =~ "$POWERLEVEL9K_PUBLIC_IP_NONE" ]] && refresh_ip=true @@ -680,7 +595,7 @@ prompt_context() { local current_state="DEFAULT" local content="" - if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true || "$(whoami)" != "$DEFAULT_USER" || -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then content="${POWERLEVEL9K_CONTEXT_TEMPLATE}" elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then content="$(whoami)" @@ -688,7 +603,7 @@ prompt_context() { return fi - if [[ $(print -P "%#") == '#' ]]; then + if [[ "${(%):-%#}" == '#' ]]; then current_state="ROOT" elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then if [[ -n "$SUDO_COMMAND" ]]; then @@ -708,35 +623,13 @@ prompt_context() { # 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 ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]]; then - if [[ $(print -P "%#") == '#' ]]; then - user_state=( - "STATE" "ROOT" - "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" - "BACKGROUND_COLOR" "${DEFAULT_COLOR}" - "FOREGROUND_COLOR" "yellow" - "VISUAL_IDENTIFIER" "ROOT_ICON" - ) - elif [[ -n "$SUDO_COMMAND" ]]; 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" - "CONTENT" "$(whoami)" - "BACKGROUND_COLOR" "${DEFAULT_COLOR}" - "FOREGROUND_COLOR" "yellow" - "VISUAL_IDENTIFIER" "USER_ICON" - ) - fi - "$1_prompt_segment" "${0}_${user_state[STATE]}" "$2" "${user_state[BACKGROUND_COLOR]}" "${user_state[FOREGROUND_COLOR]}" "${user_state[CONTENT]}" "${user_state[VISUAL_IDENTIFIER]}" + [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" != true && "$(whoami)" == "$DEFAULT_USER" ]] && return + if [[ "${(%):-%#}" == '#' ]]; then + "$1_prompt_segment" "${0}_ROOT" "$2" "${DEFAULT_COLOR}" yellow "${POWERLEVEL9K_USER_TEMPLATE}" ROOT_ICON + elif [[ -n "$SUDO_COMMAND" ]]; then + "$1_prompt_segment" "${0}_SUDO" "$2" "${DEFAULT_COLOR}" yellow "${POWERLEVEL9K_USER_TEMPLATE}" SUDO_ICON + else + "$1_prompt_segment" "${0}_DEFAULT" "$2" "${DEFAULT_COLOR}" yellow "$(whoami)" USER_ICON fi } @@ -744,26 +637,11 @@ prompt_user() { # 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" - ) + if [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + "$1_prompt_segment" "$0_REMOTE" "$2" "${DEFAULT_COLOR}" yellow "${POWERLEVEL9K_HOST_TEMPLATE}" SSH_ICON else - host_state=( - "STATE" "LOCAL" - "CONTENT" "${POWERLEVEL9K_HOST_TEMPLATE}" - "BACKGROUND_COLOR" "${DEFAULT_COLOR}" - "FOREGROUND_COLOR" "yellow" - "VISUAL_IDENTIFIER" "HOST_ICON" - ) + "$1_prompt_segment" "$0_LOCAL" "$2" "${DEFAULT_COLOR}" yellow "${POWERLEVEL9K_HOST_TEMPLATE}" 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]}" } ################################################################ @@ -785,10 +663,11 @@ prompt_custom() { ################################################################ # Display the duration the command needed to run. +typeset -gF _P9K_COMMAND_DURATION +set_default -i POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD 3 +set_default -i POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION 2 prompt_command_execution_time() { - set_default POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD 3 - set_default POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION 2 - + (( _P9K_COMMAND_DURATION < POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )) && return # Print time in human readable format # For that use `strftime` and convert # the duration (float) to an seconds @@ -812,9 +691,7 @@ prompt_command_execution_time() { humanReadableDuration=$_P9K_COMMAND_DURATION fi - if (( _P9K_COMMAND_DURATION >= POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )); then - "$1_prompt_segment" "$0" "$2" "red" "yellow1" "${humanReadableDuration}" 'EXECUTION_TIME_ICON' - fi + "$1_prompt_segment" "$0" "$2" "red" "yellow1" "${humanReadableDuration}" 'EXECUTION_TIME_ICON' } ################################################################ @@ -850,12 +727,23 @@ function getUniqueFolder() { set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false +set_default POWERLEVEL9K_DIR_PATH_ABSOLUTE false +set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false +set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false +set_default POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER false +set_default POWERLEVEL9K_SHORTEN_STRATEGY "" +set_default POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND "" +set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" +set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" +set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD "" +set_default -i POWERLEVEL9K_SHORTEN_DIR_LENGTH -1 +set_default -a POWERLEVEL9K_DIR_PACKAGE_FILES package.json composer.json prompt_dir() { # using $PWD instead of "$(print -P '%~')" to allow use of POWERLEVEL9K_DIR_PATH_ABSOLUTE local current_path=$PWD # WAS: local current_path="$(print -P '%~')" - [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]] && - local -i not_writable=1 || local -i not_writable=0 - if ! _p9k_cache_get "$0" "$2" "$current_path" "$not_writable"; then + [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]] + local -i writable=$? + if ! _p9k_cache_get "$0" "$2" "$current_path" "$writable"; then # check if the user wants to use absolute paths or "~" paths [[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path/#$HOME/"~"} # declare all local variables @@ -863,8 +751,10 @@ prompt_dir() { # if we are not in "~" or "/", split the paths into an array and exclude "~" (( ${#current_path} > 1 )) && paths=(${(s:/:)${current_path//"~\/"/}}) || paths=() # only run the code if SHORTEN_DIR_LENGTH is set, or we are using the two strategies that don't rely on it. - if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_to_last" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_package_name" ]]; then - set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" + if [[ "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" -ge 0 || + "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" || + "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_to_last" || + "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_package_name" ]]; then # convert delimiter from unicode to literal character, so that we can get the correct length later local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) @@ -921,7 +811,6 @@ prompt_dir() { truncate_with_folder_marker) if (( ${#paths} > 0 )); then # root and home are exceptions and won't have paths, so skip this local last_marked_folder marked_folder - set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" # Search for the folder marker in the parent directories and # buildup a pattern that is removed from the current path @@ -978,7 +867,6 @@ prompt_dir() { subdirectory_path=$(truncatePath "${trunc_path:${#${(S%%)package_path//$~zero/}}}" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) # Parse the 'name' from the package.json; if there are any problems, just # print the file path - defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json) local pkgFile="unknown" for file in "${POWERLEVEL9K_DIR_PACKAGE_FILES[@]}"; do @@ -1000,7 +888,8 @@ prompt_dir() { ;; *) if [[ $current_path != "~" ]]; then - current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" + current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" + current_path="${(%)current_path}" fi ;; esac @@ -1008,13 +897,13 @@ prompt_dir() { # save state of path for highlighting and bold options local path_opt=$current_path - local state_path="$(print -P '%~')" + local state_path="${(%):-%~}" local current_state="DEFAULT" local icon="FOLDER_ICON" if [[ $state_path == '/etc'* ]]; then current_state='ETC' icon='ETC_ICON' - elif (( not_writable )); then + elif (( ! writable )); then current_state="NOT_WRITABLE" icon='LOCK_ICON' elif [[ $state_path == '~' ]]; then @@ -1103,21 +992,16 @@ prompt_dir() { ################################################################ # Docker machine prompt_docker_machine() { - local docker_machine="$DOCKER_MACHINE_NAME" - - if [[ -n "$docker_machine" ]]; then - "$1_prompt_segment" "$0" "$2" "magenta" "$DEFAULT_COLOR" "$docker_machine" 'SERVER_ICON' + if [[ -n "$DOCKER_MACHINE_NAME" ]]; then + "$1_prompt_segment" "$0" "$2" "magenta" "$DEFAULT_COLOR" "$DOCKER_MACHINE_NAME" 'SERVER_ICON' fi } ################################################################ # GO prompt prompt_go_version() { - local go_version - local go_path - go_version=$(go version 2>/dev/null | sed -E "s/.*(go[0-9.]*).*/\1/") - go_path=$(go env GOPATH 2>/dev/null) - + local go_version=$(go version 2>/dev/null | sed -E "s/.*(go[0-9.]*).*/\1/") + local go_path=$(go env GOPATH 2>/dev/null) if [[ -n "$go_version" && "${PWD##$go_path}" != "$PWD" ]]; then "$1_prompt_segment" "$0" "$2" "green" "grey93" "$go_version" "GO_ICON" fi @@ -1158,6 +1042,7 @@ prompt_icons_test() { ################################################################ # Segment to display the current IP address +set_default POWERLEVEL9K_IP_INTERFACE "^[^ ]+" prompt_ip() { local ROOT_PREFIX="${4}" local ip=$(p9k::parseIp "${POWERLEVEL9K_IP_INTERFACE}" "${ROOT_PREFIX}") @@ -1193,7 +1078,7 @@ prompt_laravel_version() { ################################################################ # Segment to display load -set_default POWERLEVEL9K_LOAD_WHICH 5 +set_default -i POWERLEVEL9K_LOAD_WHICH 5 prompt_load() { local ROOT_PREFIX="${4}" # The load segment can have three different states @@ -1344,10 +1229,10 @@ prompt_rbenv() { ################################################################ # Segment to display chruby information # see https://github.com/postmodern/chruby/issues/245 for chruby_auto issue with ZSH +set_default POWERLEVEL9K_CHRUBY_SHOW_VERSION true +set_default POWERLEVEL9K_CHRUBY_SHOW_ENGINE true prompt_chruby() { # Uses $RUBY_VERSION and $RUBY_ENGINE set by chruby - set_default POWERLEVEL9K_CHRUBY_SHOW_VERSION true - set_default POWERLEVEL9K_CHRUBY_SHOW_ENGINE true local chruby_label="" if [[ "$POWERLEVEL9K_CHRUBY_SHOW_ENGINE" == true ]]; then @@ -1415,7 +1300,7 @@ prompt_rvm() { ################################################################ # Segment to display SSH icon when connected prompt_ssh() { - if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then + if [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'SSH_ICON' fi } @@ -1441,32 +1326,35 @@ exit_code_or_status() { fi } +typeset -gi _P9K_EXIT_CODE +typeset -ga _P9K_PIPE_EXIT_CODES + prompt_status() { - if ! _p9k_cache_get "$0" "$2" "$RETVAL" "${(@)RETVALS}"; then + if ! _p9k_cache_get "$0" "$2" "$_P9K_EXIT_CODE" "${(@)_P9K_PIPE_EXIT_CODES}"; then local ec_text local ec_sum local ec if [[ $POWERLEVEL9K_STATUS_SHOW_PIPESTATUS == true ]]; then - if (( $#RETVALS > 1 )); then - ec_sum=${RETVALS[1]} - exit_code_or_status "${RETVALS[1]}" + if (( $#_P9K_PIPE_EXIT_CODES > 1 )); then + ec_sum=${_P9K_PIPE_EXIT_CODES[1]} + exit_code_or_status "${_P9K_PIPE_EXIT_CODES[1]}" else - ec_sum=${RETVAL} - exit_code_or_status "${RETVAL}" + ec_sum=${_P9K_EXIT_CODE} + exit_code_or_status "${_P9K_EXIT_CODE}" fi ec_text=$_P9K_RETVAL - for ec in "${(@)RETVALS[2,-1]}"; do + for ec in "${(@)_P9K_PIPE_EXIT_CODES[2,-1]}"; do (( ec_sum += ec )) exit_code_or_status "$ec" ec_text+="|$_P9K_RETVAL" done else - ec_sum=${RETVAL} - # We use RETVAL instead of the right-most RETVALS item because + ec_sum=${_P9K_EXIT_CODE} + # We use _P9K_EXIT_CODE instead of the right-most _P9K_PIPE_EXIT_CODES item because # PIPE_FAIL may be set. - exit_code_or_status "${RETVAL}" + exit_code_or_status "${_P9K_EXIT_CODE}" ec_text=$_P9K_RETVAL fi @@ -1481,7 +1369,7 @@ prompt_status() { else return fi - if (( $#RETVALS < 3 )); then + if (( $#_P9K_PIPE_EXIT_CODES < 3 )); then _p9k_cache_set "${(@)_P9K_CACHE_VAL}" fi fi @@ -1518,7 +1406,7 @@ prompt_swap() { ################################################################ # Symfony2-PHPUnit test ratio prompt_symfony2_tests() { - if [[ (-d src && -d app && -f app/AppKernel.php) ]]; then + if [[ -d src && -d app && -f app/AppKernel.php ]]; then local code_amount tests_amount code_amount=$(ls -1 src/**/*.php | grep -vc Tests) tests_amount=$(ls -1 src/**/*.php | grep -c Tests) @@ -1545,8 +1433,7 @@ build_test_stats() { local headline="$6" # Set float precision to 2 digits: - typeset -F 2 ratio - local ratio=$(( (tests_amount/code_amount) * 100 )) + local -F 2 ratio=$(( (tests_amount/code_amount) * 100 )) (( ratio >= 75 )) && "$1_prompt_segment" "${2}_GOOD" "$3" "cyan" "$DEFAULT_COLOR" "$headline: $ratio%%" "$6" (( ratio >= 50 && ratio < 75 )) && "$1_prompt_segment" "$2_AVG" "$3" "yellow" "$DEFAULT_COLOR" "$headline: $ratio%%" "$6" @@ -1598,30 +1485,34 @@ prompt_todo() { ################################################################ # VCS segment: shows the state of your repository, if you are in a folder under # version control -set_default POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND "red" -# Default: Just display the first 8 characters of our changeset-ID. -set_default POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH "8" + +# The vcs segment can have 4 different states - defaults to 'clean'. +typeset -gA vcs_states=( + 'clean' 'green' + 'modified' 'yellow' + 'untracked' 'green' + 'loading' 'grey' +) + +set_default POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND red +set_default POWERLEVEL9K_SHOW_CHANGESET false +set_default -i POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH 8 +set_default -a POWERLEVEL9K_VCS_GIT_HOOKS vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname +set_default -a POWERLEVEL9K_VCS_HG_HOOKS vcs-detect-changes +set_default -a POWERLEVEL9K_VCS_SVN_HOOKS vcs-detect-changes svn-detect-changes + +# If it takes longer than this to fetch git repo status, display the prompt with a greyed out +# vcs segment and fix it asynchronously when the results come it. +set_default -F POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS 0.05 +set_default -a POWERLEVEL9K_VCS_BACKENDS git powerlevel9k_vcs_init() { if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH" fi - # Load VCS_INFO autoload -Uz vcs_info - VCS_WORKDIR_DIRTY=false - VCS_WORKDIR_HALF_DIRTY=false - - # The vcs segment can have three different states - defaults to 'clean'. - typeset -gAH vcs_states - vcs_states=( - 'clean' 'green' - 'modified' 'yellow' - 'untracked' 'green' - 'loading' 'grey' - ) - VCS_CHANGESET_PREFIX='' if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then VCS_CHANGESET_PREFIX="$(print_icon 'VCS_COMMIT_ICON')%0.$POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH""i " @@ -1631,17 +1522,11 @@ powerlevel9k_vcs_init() { VCS_DEFAULT_FORMAT="$VCS_CHANGESET_PREFIX%b%c%u%m" zstyle ':vcs_info:*' formats "$VCS_DEFAULT_FORMAT" - zstyle ':vcs_info:*' actionformats "%b %F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| %a%f" - zstyle ':vcs_info:*' stagedstr " $(print_icon 'VCS_STAGED_ICON')" zstyle ':vcs_info:*' unstagedstr " $(print_icon 'VCS_UNSTAGED_ICON')" - - defined POWERLEVEL9K_VCS_GIT_HOOKS || POWERLEVEL9K_VCS_GIT_HOOKS=(vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname) zstyle ':vcs_info:git*+set-message:*' hooks $POWERLEVEL9K_VCS_GIT_HOOKS - defined POWERLEVEL9K_VCS_HG_HOOKS || POWERLEVEL9K_VCS_HG_HOOKS=(vcs-detect-changes) zstyle ':vcs_info:hg*+set-message:*' hooks $POWERLEVEL9K_VCS_HG_HOOKS - defined POWERLEVEL9K_VCS_SVN_HOOKS || POWERLEVEL9K_VCS_SVN_HOOKS=(vcs-detect-changes svn-detect-changes) zstyle ':vcs_info:svn*+set-message:*' hooks $POWERLEVEL9K_VCS_SVN_HOOKS # For Hg, only show the branch name @@ -1651,9 +1536,8 @@ powerlevel9k_vcs_init() { zstyle ':vcs_info:hg*:*' get-bookmarks true zstyle ':vcs_info:hg*+gen-hg-bookmark-string:*' hooks hg-bookmarks - # For svn, only - # TODO fix the %b (branch) format for svn. Using %b breaks - # color-encoding of the foreground for the rest of the powerline. + # TODO: fix the %b (branch) format for svn. Using %b breaks color-encoding of the foreground + # for the rest of the powerline. zstyle ':vcs_info:svn*:*' formats "$VCS_CHANGESET_PREFIX%c%u" zstyle ':vcs_info:svn*:*' actionformats "$VCS_CHANGESET_PREFIX%c%u %F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| %a%f" @@ -1767,6 +1651,8 @@ typeset -fH _p9k_vcs_render() { } typeset -fH _p9k_vcs_resume() { + emulate -L zsh + if [[ $VCS_STATUS_RESULT == ok-async ]]; then local latency=$((EPOCHREALTIME - _P9K_GITSTATUS_START_TIME)) if (( latency > POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS )); then @@ -1823,13 +1709,8 @@ typeset -fH _p9k_vcs_gitstatus() { ################################################################ # Segment to show VCS information -# If it takes longer than this to fetch git repo status, display the prompt with a greyed out -# vcs segment and fix it asynchronously when the results come it. -[ -v POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS ] || typeset -gF POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS=0.05 - prompt_vcs() { - local -a backends - [[ -v POWERLEVEL9K_VCS_BACKENDS ]] && backends=($POWERLEVEL9K_VCS_BACKENDS) || backends=(git) + local -a backends=($POWERLEVEL9K_VCS_BACKENDS) if (( ${backends[(I)git]} )) && _p9k_vcs_gitstatus; then _p9k_vcs_render $0 $1 $2 && return backends=(${backends:#git}) @@ -1880,12 +1761,9 @@ prompt_vi_mode() { # More information on virtualenv (Python): # https://virtualenv.pypa.io/en/latest/ prompt_virtualenv() { - local virtualenv_path="$VIRTUAL_ENV" - - # Early exit; $virtualenv_path must always be set. - [[ -z "$virtualenv_path" ]] && return - - "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${virtualenv_path:t}" 'PYTHON_ICON' + if [[ -n "$VIRTUAL_ENV" ]]; then + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${virtualenv_path:t}" 'PYTHON_ICON' + fi } ################################################################ @@ -2001,11 +1879,12 @@ prompt_java_version() { # Prompt processing and drawing ################################################################ # Main prompt +set_default -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS context dir vcs build_left_prompt() { - typeset -gH _P9K_CURRENT_BG=NONE - typeset -gH _P9K_LAST_SEGMENT_INDEX=0 + _P9K_CURRENT_BG=NONE + _P9K_LAST_SEGMENT_INDEX=0 - local index=1 + local -i index=1 local element for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do # Remove joined information in direct calls @@ -2019,20 +1898,31 @@ build_left_prompt() { "prompt_$element" "left" "$index" fi - index=$((index + 1)) + ((++index)) done - left_prompt_end - - unset _P9K_CURRENT_BG _P9K_LAST_SEGMENT_INDEX + if ! _p9k_cache_get "$0" "$_P9K_CURRENT_BG"; then + local output="%k" + if [[ $_P9K_CURRENT_BG != NONE ]]; then + _p9k_foreground $_P9K_CURRENT_BG + output+=$_P9K_RETVAL + _p9k_get_icon LEFT_SEGMENT_SEPARATOR + output+="${_P9K_RETVAL}" + fi + _p9k_get_icon LEFT_SEGMENT_END_SEPARATOR + output+="%f${_P9K_RETVAL}" + _p9k_cache_set "$output" + fi + _P9K_PROMPT+="${_P9K_CACHE_VAL[1]}" } # Right prompt +set_default -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS status root_indicator background_jobs history time build_right_prompt() { - typeset -gH _P9K_CURRENT_BG=NONE - typeset -gH _P9K_LAST_SEGMENT_INDEX=0 + _P9K_CURRENT_BG=NONE + _P9K_LAST_SEGMENT_INDEX=0 - local index=1 + local -i index=1 local element for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do @@ -2047,27 +1937,25 @@ build_right_prompt() { "prompt_$element" "right" "$index" fi - index=$((index + 1)) + ((++index)) done # Clear to the end of the line _P9K_PROMPT+="%E" - - unset _P9K_CURRENT_BG _P9K_LAST_SEGMENT_INDEX } -powerlevel9k_preexec() { - _P9K_TIMER_START=$EPOCHREALTIME -} +typeset -gF _P9K_TIMER_START +powerlevel9k_preexec() { _P9K_TIMER_START=$EPOCHREALTIME } + +typeset -g _P9K_PROMPT typeset -fH _p9k_set_prompts() { - typeset -gH _P9K_PROMPT='' + _P9K_PROMPT='' build_left_prompt local left=$_P9K_PROMPT _P9K_PROMPT='' build_right_prompt local right=$_P9K_PROMPT - unset _P9K_PROMPT local NEWLINE=$'\n' local RPROMPT_SUFFIX RPROMPT_PREFIX @@ -2110,7 +1998,7 @@ typeset -fH _p9k_set_prompts() { } typeset -fH _p9k_update_prompts() { - [[ $_P9K_LOADED == true ]] || return + (( _P9K_ENABLED )) || return typeset -gH _P9K_REFRESH_PROMPT='' _p9k_set_prompts unset _P9K_REFRESH_PROMPT @@ -2119,16 +2007,15 @@ typeset -fH _p9k_update_prompts() { set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false powerlevel9k_prepare_prompts() { - # Return values. These need to be global, because - # they are used in prompt_status. Also, we need - # to get the return value of the last command at - # very first in this function. Do not move the - # lines down, otherwise the last command is not - # what you expected it to be. - RETVAL=$? - RETVALS=( "$pipestatus[@]" ) + # Do not move these lines down, otherwise the last command is not what you expected it to be. + _P9K_EXIT_CODE=$? + _P9K_PIPE_EXIT_CODES=( "$pipestatus[@]" ) _P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START)) - _P9K_TIMER_START=0x7FFFFFFF + + emulate -L zsh + + _p9k_init + _P9K_TIMER_START=1e10 _p9k_set_prompts } @@ -2139,73 +2026,129 @@ zle-keymap-select () { set_default POWERLEVEL9K_IGNORE_TERM_COLORS false set_default POWERLEVEL9K_IGNORE_TERM_LANG false +set_default POWERLEVEL9K_DISABLE_GITSTATUS false +set_default -i POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY -1 -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. - # Please don't change it until 19 January of 2038. ;) +typeset -g DEFAULT_COLOR +typeset -g DEFAULT_COLOR_INVERTED +typeset -gi _P9K_INITIALIZED=0 - # Disable false display of command execution time - _P9K_TIMER_START=0x7FFFFFFF +typeset -g OS +typeset -g OS_ICON +typeset -g SED_EXTENDED_REGEX_PARAMETER - # The prompt function will set these prompt_* options after the setup function - # returns. We need prompt_subst so we can safely run commands in the prompt - # without them being double expanded and we need prompt_percent to expand the - # common percent escape sequences. - prompt_opts=(cr percent sp subst) +_p9k_init() { + (( _P9K_INITIALIZED )) && return - # Borrowed from promptinit, sets the prompt options in case the theme was - # not initialized via promptinit. - setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" + _p9k_init_icons - # Display a warning if the terminal does not support 256 colors - termColors + local function set_os() { + OS=$1 + _p9k_get_icon $2 + OS_ICON=$_P9K_RETVAL + } + + if [[ $(uname -o 2>/dev/null) == Android ]]; then + set_os Android ANDROID_ICON + else + case $(uname) in + SunOS) set_os Solaris SUNOS_ICON;; + Darwin) set_os OSX APPLE_ICON;; + CYGWIN_NT-* | MSYS_NT-*) set_os Windows WINDOWS_ICON;; + FreeBSD|OpenBSD|DragonFly) set_os BSD FREEBSD_ICON;; + Linux) + OS='Linux' + local os_release_id + [[ -f /etc/os-release && + "${(f)$((/dev/null)}" =~ "ID=([A-Za-z]+)" && + os_release_id="${match[1]}" ]] + case "$os_release_id" in + *arch*) set_os Linux LINUX_ARCH_ICON;; + *debian*) set_os Linux LINUX_DEBIAN_ICON;; + *ubuntu*) set_os Linux LINUX_UBUNTU_ICON;; + *elementary*) set_os Linux LINUX_ELEMENTARY_ICON;; + *fedora*) set_os Linux LINUX_FEDORA_ICON;; + *coreos*) set_os Linux LINUX_COREOS_ICON;; + *gentoo*) set_os Linux LINUX_GENTOO_ICON;; + *mageia*) set_os Linux LINUX_MAGEIA_ICON;; + *centos*) set_os Linux LINUX_CENTOS_ICON;; + *opensuse*|*tumbleweed*) set_os Linux LINUX_OPENSUSE_ICON;; + *sabayon*) set_os Linux LINUX_SABAYON_ICON;; + *slackware*) set_os Linux LINUX_SLACKWARE_ICON;; + *linuxmint*) set_os Linux LINUX_MINT_ICON;; + *alpine*) set_os Linux LINUX_ALPINE_ICON;; + *aosc*) set_os Linux LINUX_AOSC_ICON;; + *nixos*) set_os Linux LINUX_NIXOS_ICON;; + *devuan*) set_os Linux LINUX_DEVUAN_ICON;; + *manjaro*) set_os Linux LINUX_MANJARO_ICON;; + *) set_os Linux LINUX_ICON;; + esac + ;; + esac + fi + + if [[ $POWERLEVEL9K_COLOR_SCHEME == light ]]; then + DEFAULT_COLOR=white + DEFAULT_COLOR_INVERTED=black + else + DEFAULT_COLOR=black + DEFAULT_COLOR_INVERTED=white + fi + + local i + for ((i = 2; i <= $#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS; ++i)); do + local elem=$POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[$i] + if [[ $elem == *_joined ]]; then + _P9K_LEFT_JOIN+=$_P9K_LEFT_JOIN[((i-1))] + else + _P9K_LEFT_JOIN+=$i + fi + done + + for ((i = 2; i <= $#POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS; ++i)); do + local elem=$POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[$i] + if [[ $elem == *_joined ]]; then + _P9K_RIGHT_JOIN+=$_P9K_RIGHT_JOIN[((i-1))] + else + _P9K_RIGHT_JOIN+=$i + fi + done # If the terminal `LANG` is set to `C`, this theme will not work at all. - if [[ $POWERLEVEL9K_IGNORE_TERM_LANG == false ]]; then - local term_lang - term_lang=$(echo $LANG) - if [[ $term_lang == 'C' ]]; then - print -P "\t%F{red}WARNING!%f Your terminal's 'LANG' is set to 'C', which breaks this theme!" - print -P "\t%F{red}WARNING!%f Please set your 'LANG' to a UTF-8 language, like 'en_US.UTF-8'" - print -P "\t%F{red}WARNING!%f _before_ loading this theme in your \~\.zshrc. Putting" - print -P "\t%F{red}WARNING!%f %F{blue}export LANG=\"en_US.UTF-8\"%f at the top of your \~\/.zshrc is sufficient." + if [[ $LANG == C && $POWERLEVEL9K_IGNORE_TERM_LANG == false ]]; then + print -P "\t%F{red}WARNING!%f Your terminal's 'LANG' is set to 'C', which breaks this theme!" + print -P "\t%F{red}WARNING!%f Please set your 'LANG' to a UTF-8 language, like 'en_US.UTF-8'" + print -P "\t%F{red}WARNING!%f _before_ loading this theme in your \~\.zshrc. Putting" + print -P "\t%F{red}WARNING!%f %F{blue}export LANG=\"en_US.UTF-8\"%f at the top of your \~\/.zshrc is sufficient." + print -P 'Set POWERLEVEL9K_IGNORE_TERM_LANG=true to suppress this warning.' + fi + + # Display a warning if the terminal does not support 256 colors. + if [[ $POWERLEVEL9K_IGNORE_TERM_COLORS == false ]]; then + local n + if { hash tput && n=$(tput colors) || n=$(echotc Co) } && (( n < 256 )); then + if [[ -n $n && $n -lt 256 ]]; then + print -P '%F{red}WARNING!%f Your terminal appears to support fewer than 256 colors!' + print -P 'If your terminal supports 256 colors, please export the appropriate environment variable.' + print -P 'In most terminal emulators, putting %F{blue}export TERM=xterm-256color%f at the top of your ~/.zshrc is sufficient.' + print -P 'Set POWERLEVEL9K_IGNORE_TERM_COLORS=true to suppress this warning.' fi + fi fi - # Display a warning if deprecated segments are in use. - typeset -AH deprecated_segments - # old => new - deprecated_segments=( - 'longstatus' 'status' - ) - print_deprecation_warning deprecated_segments + if segment_in_use longstatus; then + print -P '%F{yellow}Warning!%f The "longstatus" segment is deprecated. Use "%F{blue}status%f" instead.' + print -P 'For more informations, have a look at https://github.com/bhilburn/powerlevel9k/blob/master/CHANGELOG.md.' + fi - # initialize colors - autoload -U colors && colors - - if segment_in_use "vcs"; then + if segment_in_use vcs; then powerlevel9k_vcs_init + if [[ $POWERLEVEL9K_DISABLE_GITSTATUS != true ]] && (( ${POWERLEVEL9K_VCS_BACKENDS[(I)git]} )); then + source ${POWERLEVEL9K_GITSTATUS_DIR:-${_P9K_INSTALLATION_DIR}/gitstatus}/gitstatus.plugin.zsh + gitstatus_start -m $POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY POWERLEVEL9K + fi fi - # initialize timing functions - zmodload zsh/datetime - - # Initialize math functions - zmodload zsh/mathfunc - - # initialize hooks - autoload -Uz add-zsh-hook - - # prepare prompts - add-zsh-hook precmd powerlevel9k_prepare_prompts - add-zsh-hook preexec powerlevel9k_preexec - - zle -N zle-keymap-select - - local -i max_dirty=${POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY:--1} - [[ $POWERLEVEL9K_DISABLE_GITSTATUS == true ]] || gitstatus_start -m $max_dirty POWERLEVEL9K - if [[ $POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME == true ]]; then local fifo && fifo=$(mktemp -u "${TMPDIR:-/tmp}"/p10k.$$.pipe.time.XXXXXXXXXX) typeset -giH _P9K_TIMER_FD=0 @@ -2216,6 +2159,7 @@ prompt_powerlevel9k_setup() { mkfifo $fifo exec {_P9K_TIMER_FD}<>$fifo typeset -gfH _p9k_on_timer() { + emulate -L zsh local _ && IFS='' read -u $_P9K_TIMER_FD _ && zle && zle .reset-prompt } zle -F $_P9K_TIMER_FD _p9k_on_timer @@ -2223,23 +2167,48 @@ prompt_powerlevel9k_setup() { } if ! _p9k_start_timer ; then echo "powerlevel10k: failed to initialize realtime clock" >&2 - zle -F $_P9K_TIMER_FD - (( _P9K_TIMER_FD )) && exec {_P9K_TIMER_FD}>&- + if (( _P9K_TIMER_FD )); then + zle -F $_P9K_TIMER_FD + exec {_P9K_TIMER_FD}>&- + fi unset _P9K_TIMER_FD unset -f _p9k_on_timer fi rm -f "$fifo" fi - _P9K_LOADED=true + _P9K_INITIALIZED=1 +} + +typeset -gi _P9K_ENABLED=0 + +prompt_powerlevel9k_setup() { + emulate -L zsh + + prompt_powerlevel9k_teardown + + autoload -U colors && colors + autoload -Uz add-zsh-hook + zmodload zsh/datetime + zmodload zsh/mathfunc + + add-zsh-hook precmd powerlevel9k_prepare_prompts + add-zsh-hook preexec powerlevel9k_preexec + + zle -N zle-keymap-select + + _P9K_TIMER_START=1e10 + _P9K_ENABLED=1 } prompt_powerlevel9k_teardown() { + emulate -L zsh add-zsh-hook -D precmd powerlevel9k_\* add-zsh-hook -D preexec powerlevel9k_\* PROMPT='%m%# ' RPROMPT= - _P9K_LOADED=false + _P9K_ENABLED=0 } +setopt noprompt{bang,subst} prompt{cr,percent,sp} prompt_powerlevel9k_setup "$@"