aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorRoman Perepelitsa <roman.perepelitsa@gmail.com>2020-09-03 11:53:19 +0300
committerRoman Perepelitsa <roman.perepelitsa@gmail.com>2020-09-03 11:53:19 +0300
commit622130980c0785df8f76b53074c6743456eebe53 (patch)
tree441e6e47074a648e5b7407cf8bc7f6084e257fad /internal
parent6c8c6eea1baa2cb0d27be30f06b4781a7f421507 (diff)
add scalaenv prompt segment; see #991
Diffstat (limited to 'internal')
-rw-r--r--internal/icons.zsh6
-rw-r--r--internal/p10k.zsh66
2 files changed, 72 insertions, 0 deletions
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