From 622130980c0785df8f76b53074c6743456eebe53 Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Thu, 3 Sep 2020 10:53:19 +0200 Subject: [PATCH] add scalaenv prompt segment; see #991 --- config/p10k-classic.zsh | 14 ++++++++ config/p10k-lean-8colors.zsh | 14 ++++++++ config/p10k-lean.zsh | 14 ++++++++ config/p10k-rainbow.zsh | 15 ++++++++ internal/icons.zsh | 6 ++++ internal/p10k.zsh | 66 ++++++++++++++++++++++++++++++++++++ 6 files changed, 129 insertions(+) diff --git a/config/p10k-classic.zsh b/config/p10k-classic.zsh index 76c55969..1c6b5b7b 100644 --- a/config/p10k-classic.zsh +++ b/config/p10k-classic.zsh @@ -66,6 +66,7 @@ jenv # java version from jenv (https://github.com/jenv/jenv) plenv # perl version from plenv (https://github.com/tokuhirom/plenv) phpenv # php version from phpenv (https://github.com/phpenv/phpenv) + scalaenv # scala version from scalaenv (https://github.com/scalaenv/scalaenv) haskell_stack # haskell version from stack (https://haskellstack.org/) kubecontext # current kubernetes context (https://kubernetes.io/) terraform # terraform workspace (https://www.terraform.io) @@ -1115,6 +1116,19 @@ # Custom icon. # typeset -g POWERLEVEL9K_PHPENV_VISUAL_IDENTIFIER_EXPANSION='⭐' + #######[ scalaenv: scala version from scalaenv (https://github.com/scalaenv/scalaenv) ]####### + # Scala color. + typeset -g POWERLEVEL9K_SCALAENV_FOREGROUND=160 + # Hide scala version if it doesn't come from one of these sources. + typeset -g POWERLEVEL9K_SCALAENV_SOURCES=(shell local global) + # If set to false, hide scala version if it's the same as global: + # $(scalaenv version-name) == $(scalaenv global). + typeset -g POWERLEVEL9K_SCALAENV_PROMPT_ALWAYS_SHOW=false + # If set to false, hide scala version if it's equal to "system". + typeset -g POWERLEVEL9K_SCALAENV_SHOW_SYSTEM=true + # Custom icon. + # typeset -g POWERLEVEL9K_SCALAENV_VISUAL_IDENTIFIER_EXPANSION='⭐' + ##########[ haskell_stack: haskell version from stack (https://haskellstack.org/) ]########### # Haskell color. typeset -g POWERLEVEL9K_HASKELL_STACK_FOREGROUND=172 diff --git a/config/p10k-lean-8colors.zsh b/config/p10k-lean-8colors.zsh index 718e1aee..6c8cf2e5 100644 --- a/config/p10k-lean-8colors.zsh +++ b/config/p10k-lean-8colors.zsh @@ -66,6 +66,7 @@ jenv # java version from jenv (https://github.com/jenv/jenv) plenv # perl version from plenv (https://github.com/tokuhirom/plenv) phpenv # php version from phpenv (https://github.com/phpenv/phpenv) + scalaenv # scala version from scalaenv (https://github.com/scalaenv/scalaenv) haskell_stack # haskell version from stack (https://haskellstack.org/) kubecontext # current kubernetes context (https://kubernetes.io/) terraform # terraform workspace (https://www.terraform.io) @@ -1092,6 +1093,19 @@ # Custom icon. # typeset -g POWERLEVEL9K_PHPENV_VISUAL_IDENTIFIER_EXPANSION='⭐' + #######[ scalaenv: scala version from scalaenv (https://github.com/scalaenv/scalaenv) ]####### + # Scala color. + typeset -g POWERLEVEL9K_SCALAENV_FOREGROUND=1 + # Hide scala version if it doesn't come from one of these sources. + typeset -g POWERLEVEL9K_SCALAENV_SOURCES=(shell local global) + # If set to false, hide scala version if it's the same as global: + # $(scalaenv version-name) == $(scalaenv global). + typeset -g POWERLEVEL9K_SCALAENV_PROMPT_ALWAYS_SHOW=false + # If set to false, hide scala version if it's equal to "system". + typeset -g POWERLEVEL9K_SCALAENV_SHOW_SYSTEM=true + # Custom icon. + # typeset -g POWERLEVEL9K_SCALAENV_VISUAL_IDENTIFIER_EXPANSION='⭐' + ##########[ haskell_stack: haskell version from stack (https://haskellstack.org/) ]########### # Haskell color. typeset -g POWERLEVEL9K_HASKELL_STACK_FOREGROUND=3 diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index 71ead77f..19cea6e6 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -66,6 +66,7 @@ jenv # java version from jenv (https://github.com/jenv/jenv) plenv # perl version from plenv (https://github.com/tokuhirom/plenv) phpenv # php version from phpenv (https://github.com/phpenv/phpenv) + scalaenv # scala version from scalaenv (https://github.com/scalaenv/scalaenv) haskell_stack # haskell version from stack (https://haskellstack.org/) kubecontext # current kubernetes context (https://kubernetes.io/) terraform # terraform workspace (https://www.terraform.io) @@ -1092,6 +1093,19 @@ # Custom icon. # typeset -g POWERLEVEL9K_PHPENV_VISUAL_IDENTIFIER_EXPANSION='⭐' + #######[ scalaenv: scala version from scalaenv (https://github.com/scalaenv/scalaenv) ]####### + # Scala color. + typeset -g POWERLEVEL9K_SCALAENV_FOREGROUND=160 + # Hide scala version if it doesn't come from one of these sources. + typeset -g POWERLEVEL9K_SCALAENV_SOURCES=(shell local global) + # If set to false, hide scala version if it's the same as global: + # $(scalaenv version-name) == $(scalaenv global). + typeset -g POWERLEVEL9K_SCALAENV_PROMPT_ALWAYS_SHOW=false + # If set to false, hide scala version if it's equal to "system". + typeset -g POWERLEVEL9K_SCALAENV_SHOW_SYSTEM=true + # Custom icon. + # typeset -g POWERLEVEL9K_SCALAENV_VISUAL_IDENTIFIER_EXPANSION='⭐' + ##########[ haskell_stack: haskell version from stack (https://haskellstack.org/) ]########### # Haskell color. typeset -g POWERLEVEL9K_HASKELL_STACK_FOREGROUND=172 diff --git a/config/p10k-rainbow.zsh b/config/p10k-rainbow.zsh index dab4fbf3..39b4f50b 100644 --- a/config/p10k-rainbow.zsh +++ b/config/p10k-rainbow.zsh @@ -66,6 +66,7 @@ jenv # java version from jenv (https://github.com/jenv/jenv) plenv # perl version from plenv (https://github.com/tokuhirom/plenv) phpenv # php version from phpenv (https://github.com/phpenv/phpenv) + scalaenv # scala version from scalaenv (https://github.com/scalaenv/scalaenv) haskell_stack # haskell version from stack (https://haskellstack.org/) kubecontext # current kubernetes context (https://kubernetes.io/) terraform # terraform workspace (https://www.terraform.io) @@ -1175,6 +1176,20 @@ # Custom icon. # typeset -g POWERLEVEL9K_PHPENV_VISUAL_IDENTIFIER_EXPANSION='⭐' + #######[ scalaenv: scala version from scalaenv (https://github.com/scalaenv/scalaenv) ]####### + # Scala color. + # typeset -g POWERLEVEL9K_SCALAENV_FOREGROUND=0 + # typeset -g POWERLEVEL9K_SCALAENV_BACKGROUND=1 + # Hide scala version if it doesn't come from one of these sources. + typeset -g POWERLEVEL9K_SCALAENV_SOURCES=(shell local global) + # If set to false, hide scala version if it's the same as global: + # $(scalaenv version-name) == $(scalaenv global). + typeset -g POWERLEVEL9K_SCALAENV_PROMPT_ALWAYS_SHOW=false + # If set to false, hide scala version if it's equal to "system". + typeset -g POWERLEVEL9K_SCALAENV_SHOW_SYSTEM=true + # Custom icon. + # typeset -g POWERLEVEL9K_SCALAENV_VISUAL_IDENTIFIER_EXPANSION='⭐' + ##########[ haskell_stack: haskell version from stack (https://haskellstack.org/) ]########### # Haskell color. # typeset -g POWERLEVEL9K_HASKELL_STACK_FOREGROUND=0 diff --git a/internal/icons.zsh b/internal/icons.zsh index 9c989885..719c03c4 100644 --- a/internal/icons.zsh +++ b/internal/icons.zsh @@ -143,6 +143,7 @@ function _p9k_init_icons() { HASKELL_ICON 'hs' PACKAGE_ICON 'pkg' JULIA_ICON 'jl' + SCALA_ICON 'scala' ) ;; 'awesome-fontconfig') @@ -270,6 +271,7 @@ function _p9k_init_icons() { HASKELL_ICON 'hs' PACKAGE_ICON 'pkg' JULIA_ICON 'jl' + SCALA_ICON 'scala' ) ;; 'awesome-mapped-fontconfig') @@ -400,6 +402,7 @@ function _p9k_init_icons() { HASKELL_ICON 'hs' PACKAGE_ICON 'pkg' JULIA_ICON 'jl' + SCALA_ICON 'scala' ) ;; 'nerdfont-complete'|'nerdfont-fontconfig') @@ -528,6 +531,7 @@ function _p9k_init_icons() { HASKELL_ICON '\uE61F' #  PACKAGE_ICON '\uF8D6' #  JULIA_ICON '\uE624' #  + SCALA_ICON '\uE737' #  ) ;; ascii) @@ -653,6 +657,7 @@ function _p9k_init_icons() { HASKELL_ICON 'hs' PACKAGE_ICON 'pkg' JULIA_ICON 'jl' + SCALA_ICON 'scala' ) ;; *) @@ -780,6 +785,7 @@ function _p9k_init_icons() { HASKELL_ICON 'hs' PACKAGE_ICON 'pkg' JULIA_ICON 'jl' + SCALA_ICON 'scala' ) ;; esac diff --git a/internal/p10k.zsh b/internal/p10k.zsh index c91656d0..fc8f3f8b 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -2673,6 +2673,69 @@ function _p9k_phpenv_global_version() { _p9k_read_word ${PHPENV_ROOT:-$HOME/.phpenv}/version || _p9k__ret=system } +function _p9k_scalaenv_global_version() { + _p9k_read_word ${SCALAENV_ROOT:-$HOME/.scalaenv}/version || _p9k__ret=system +} + +# https://github.com/scalaenv/scalaenv +prompt_scalaenv() { + if [[ -n $SCALAENV_VERSION ]]; then + (( ${_POWERLEVEL9K_SCALAENV_SOURCES[(I)shell]} )) || return + local v=$SCALAENV_VERSION + else + (( ${_POWERLEVEL9K_SCALAENV_SOURCES[(I)local|global]} )) || return + _p9k__ret= + if [[ $SCALAENV_DIR != (|.) ]]; then + [[ $SCALAENV_DIR == /* ]] && local dir=$SCALAENV_DIR || local dir="$_p9k__cwd_a/$SCALAENV_DIR" + dir=${dir:A} + if [[ $dir != $_p9k__cwd_a ]]; then + while true; do + if _p9k_read_word $dir/.scala-version; then + (( ${_POWERLEVEL9K_SCALAENV_SOURCES[(I)local]} )) || return + break + fi + [[ $dir == (/|.) ]] && break + dir=${dir:h} + done + fi + fi + if [[ -z $_p9k__ret ]]; then + _p9k_upglob .scala-version + local -i idx=$? + if (( idx )) && _p9k_read_word $_p9k__parent_dirs[idx]/.scala-version; then + (( ${_POWERLEVEL9K_SCALAENV_SOURCES[(I)local]} )) || return + else + _p9k__ret= + fi + fi + if [[ -z $_p9k__ret ]]; then + (( _POWERLEVEL9K_SCALAENV_PROMPT_ALWAYS_SHOW )) || return + (( ${_POWERLEVEL9K_SCALAENV_SOURCES[(I)global]} )) || return + _p9k_scalaenv_global_version + fi + local v=$_p9k__ret + fi + + if (( !_POWERLEVEL9K_SCALAENV_PROMPT_ALWAYS_SHOW )); then + _p9k_scalaenv_global_version + [[ $v == $_p9k__ret ]] && return + fi + + if (( !_POWERLEVEL9K_SCALAENV_SHOW_SYSTEM )); then + [[ $v == system ]] && return + fi + + _p9k_prompt_segment "$0" "red" "$_p9k_color1" 'SCALA_ICON' 0 '' "${v//\%/%%}" +} + +_p9k_prompt_scalaenv_init() { + typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[scalaenv]:-${${+functions[scalaenv]}:#0}}' +} + +function _p9k_phpenv_global_version() { + _p9k_read_word ${PHPENV_ROOT:-$HOME/.phpenv}/version || _p9k__ret=system +} + prompt_phpenv() { if [[ -n $PHPENV_VERSION ]]; then (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)shell]} )) || return @@ -7057,6 +7120,9 @@ _p9k_init_params() { _p9k_declare -b POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW 0 _p9k_declare -a POWERLEVEL9K_RBENV_SOURCES -- shell local global _p9k_declare -b POWERLEVEL9K_RBENV_SHOW_SYSTEM 1 + _p9k_declare -b POWERLEVEL9K_SCALAENV_PROMPT_ALWAYS_SHOW 0 + _p9k_declare -a POWERLEVEL9K_SCALAENV_SOURCES -- shell local global + _p9k_declare -b POWERLEVEL9K_SCALAENV_SHOW_SYSTEM 1 _p9k_declare -b POWERLEVEL9K_PHPENV_PROMPT_ALWAYS_SHOW 0 _p9k_declare -a POWERLEVEL9K_PHPENV_SOURCES -- shell local global _p9k_declare -b POWERLEVEL9K_PHPENV_SHOW_SYSTEM 1