mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-11 00:00:06 +00:00
add package
prompt segment
This commit is contained in:
parent
95008fc871
commit
db1e12bce3
8 changed files with 116 additions and 3 deletions
|
@ -291,6 +291,7 @@ enable as many segments as you like. It won't slow down your prompt or Zsh start
|
|||
| `dotnet_version` | [dotnet](https://dotnet.microsoft.com) version |
|
||||
| `php_version` | [php](https://www.php.net/) version |
|
||||
| `laravel_version` | [laravel php framework](https://laravel.com/) version |
|
||||
| `package` | `name@version` from [package.json](https://docs.npmjs.com/files/package.json) |
|
||||
| `kubecontext` | current [kubernetes](https://kubernetes.io/) context |
|
||||
| `terraform` | [terraform](https://www.terraform.io) workspace |
|
||||
| `aws` | [aws profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) |
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
# php_version # php version (https://www.php.net/)
|
||||
# laravel_version # laravel php framework version (https://laravel.com/)
|
||||
# java_version # java version (https://www.java.com/)
|
||||
# package # name@version from package.json (https://docs.npmjs.com/files/package.json)
|
||||
rbenv # ruby version from rbenv (https://github.com/rbenv/rbenv)
|
||||
rvm # ruby version from rvm (https://rvm.io)
|
||||
fvm # flutter version management (https://github.com/leoafarias/fvm)
|
||||
|
@ -1006,6 +1007,18 @@
|
|||
# Custom icon.
|
||||
# typeset -g POWERLEVEL9K_JAVA_VERSION_VISUAL_IDENTIFIER_EXPANSION='⭐'
|
||||
|
||||
###[ package: name@version from package.json (https://docs.npmjs.com/files/package.json) ]####
|
||||
# Package color.
|
||||
typeset -g POWERLEVEL9K_PACKAGE_FOREGROUND=117
|
||||
# Package format. The following parameters are available within the expansion.
|
||||
#
|
||||
# - P9K_PACKAGE_NAME The value of `name` field in package.json.
|
||||
# - P9K_PACKAGE_VERSION The value of `version` field in package.json.
|
||||
#
|
||||
# typeset -g POWERLEVEL9K_PACKAGE_CONTENT_EXPANSION='${P9K_PACKAGE_NAME//\%/%%}@${P9K_PACKAGE_VERSION//\%/%%}'
|
||||
# Custom icon.
|
||||
# typeset -g POWERLEVEL9K_PACKAGE_VISUAL_IDENTIFIER_EXPANSION='⭐'
|
||||
|
||||
#############[ rbenv: ruby version from rbenv (https://github.com/rbenv/rbenv) ]##############
|
||||
# Rbenv color.
|
||||
typeset -g POWERLEVEL9K_RBENV_FOREGROUND=168
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
# php_version # php version (https://www.php.net/)
|
||||
# laravel_version # laravel php framework version (https://laravel.com/)
|
||||
# java_version # java version (https://www.java.com/)
|
||||
# package # name@version from package.json (https://docs.npmjs.com/files/package.json)
|
||||
rbenv # ruby version from rbenv (https://github.com/rbenv/rbenv)
|
||||
rvm # ruby version from rvm (https://rvm.io)
|
||||
fvm # flutter version management (https://github.com/leoafarias/fvm)
|
||||
|
@ -985,6 +986,18 @@
|
|||
# Custom icon.
|
||||
# typeset -g POWERLEVEL9K_JAVA_VERSION_VISUAL_IDENTIFIER_EXPANSION='⭐'
|
||||
|
||||
###[ package: name@version from package.json (https://docs.npmjs.com/files/package.json) ]####
|
||||
# Package color.
|
||||
typeset -g POWERLEVEL9K_PACKAGE_FOREGROUND=6
|
||||
# Package format. The following parameters are available within the expansion.
|
||||
#
|
||||
# - P9K_PACKAGE_NAME The value of `name` field in package.json.
|
||||
# - P9K_PACKAGE_VERSION The value of `version` field in package.json.
|
||||
#
|
||||
# typeset -g POWERLEVEL9K_PACKAGE_CONTENT_EXPANSION='${P9K_PACKAGE_NAME//\%/%%}@${P9K_PACKAGE_VERSION//\%/%%}'
|
||||
# Custom icon.
|
||||
# typeset -g POWERLEVEL9K_PACKAGE_VISUAL_IDENTIFIER_EXPANSION='⭐'
|
||||
|
||||
#############[ rbenv: ruby version from rbenv (https://github.com/rbenv/rbenv) ]##############
|
||||
# Rbenv color.
|
||||
typeset -g POWERLEVEL9K_RBENV_FOREGROUND=1
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
# php_version # php version (https://www.php.net/)
|
||||
# laravel_version # laravel php framework version (https://laravel.com/)
|
||||
# java_version # java version (https://www.java.com/)
|
||||
# package # name@version from package.json (https://docs.npmjs.com/files/package.json)
|
||||
rbenv # ruby version from rbenv (https://github.com/rbenv/rbenv)
|
||||
rvm # ruby version from rvm (https://rvm.io)
|
||||
fvm # flutter version management (https://github.com/leoafarias/fvm)
|
||||
|
@ -985,6 +986,18 @@
|
|||
# Custom icon.
|
||||
# typeset -g POWERLEVEL9K_JAVA_VERSION_VISUAL_IDENTIFIER_EXPANSION='⭐'
|
||||
|
||||
###[ package: name@version from package.json (https://docs.npmjs.com/files/package.json) ]####
|
||||
# Package color.
|
||||
typeset -g POWERLEVEL9K_PACKAGE_FOREGROUND=117
|
||||
# Package format. The following parameters are available within the expansion.
|
||||
#
|
||||
# - P9K_PACKAGE_NAME The value of `name` field in package.json.
|
||||
# - P9K_PACKAGE_VERSION The value of `version` field in package.json.
|
||||
#
|
||||
# typeset -g POWERLEVEL9K_PACKAGE_CONTENT_EXPANSION='${P9K_PACKAGE_NAME//\%/%%}@${P9K_PACKAGE_VERSION//\%/%%}'
|
||||
# Custom icon.
|
||||
# typeset -g POWERLEVEL9K_PACKAGE_VISUAL_IDENTIFIER_EXPANSION='⭐'
|
||||
|
||||
#############[ rbenv: ruby version from rbenv (https://github.com/rbenv/rbenv) ]##############
|
||||
# Rbenv color.
|
||||
typeset -g POWERLEVEL9K_RBENV_FOREGROUND=168
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
# php_version # php version (https://www.php.net/)
|
||||
# laravel_version # laravel php framework version (https://laravel.com/)
|
||||
# java_version # java version (https://www.java.com/)
|
||||
# package # name@version from package.json (https://docs.npmjs.com/files/package.json)
|
||||
rbenv # ruby version from rbenv (https://github.com/rbenv/rbenv)
|
||||
rvm # ruby version from rvm (https://rvm.io)
|
||||
fvm # flutter version management (https://github.com/leoafarias/fvm)
|
||||
|
@ -1067,6 +1068,21 @@
|
|||
# Custom icon.
|
||||
# typeset -g POWERLEVEL9K_JAVA_VERSION_VISUAL_IDENTIFIER_EXPANSION='⭐'
|
||||
|
||||
###[ package: name@version from package.json (https://docs.npmjs.com/files/package.json) ]####
|
||||
# Package color.
|
||||
# typeset -g POWERLEVEL9K_PACKAGE_FOREGROUND=0
|
||||
# typeset -g POWERLEVEL9K_PACKAGE_BACKGROUND=6
|
||||
|
||||
# Package format. The following parameters are available within the expansion.
|
||||
#
|
||||
# - P9K_PACKAGE_NAME The value of `name` field in package.json.
|
||||
# - P9K_PACKAGE_VERSION The value of `version` field in package.json.
|
||||
#
|
||||
# typeset -g POWERLEVEL9K_PACKAGE_CONTENT_EXPANSION='${P9K_PACKAGE_NAME//\%/%%}@${P9K_PACKAGE_VERSION//\%/%%}'
|
||||
|
||||
# Custom icon.
|
||||
# typeset -g POWERLEVEL9K_PACKAGE_VISUAL_IDENTIFIER_EXPANSION='⭐'
|
||||
|
||||
#######################[ rvm: ruby version from rvm (https://rvm.io) ]########################
|
||||
# Rvm color.
|
||||
# typeset -g POWERLEVEL9K_RVM_FOREGROUND=0
|
||||
|
|
|
@ -139,6 +139,7 @@ function _p9k_init_icons() {
|
|||
POSTGRES_ICON 'postgres'
|
||||
PHP_ICON 'php'
|
||||
HASKELL_ICON 'hs'
|
||||
PACKAGE_ICON 'pkg'
|
||||
)
|
||||
;;
|
||||
'awesome-fontconfig')
|
||||
|
@ -263,6 +264,7 @@ function _p9k_init_icons() {
|
|||
POSTGRES_ICON 'postgres'
|
||||
PHP_ICON 'php'
|
||||
HASKELL_ICON 'hs'
|
||||
PACKAGE_ICON 'pkg'
|
||||
)
|
||||
;;
|
||||
'awesome-mapped-fontconfig')
|
||||
|
@ -390,6 +392,7 @@ function _p9k_init_icons() {
|
|||
POSTGRES_ICON 'postgres'
|
||||
PHP_ICON 'php'
|
||||
HASKELL_ICON 'hs'
|
||||
PACKAGE_ICON 'pkg'
|
||||
)
|
||||
;;
|
||||
'nerdfont-complete'|'nerdfont-fontconfig')
|
||||
|
@ -515,6 +518,7 @@ function _p9k_init_icons() {
|
|||
POSTGRES_ICON '\uE76E' #
|
||||
PHP_ICON '\uE608' #
|
||||
HASKELL_ICON '\uE61F' #
|
||||
PACKAGE_ICON '\uF8D6' #
|
||||
)
|
||||
;;
|
||||
ascii)
|
||||
|
@ -637,6 +641,7 @@ function _p9k_init_icons() {
|
|||
POSTGRES_ICON 'postgres'
|
||||
PHP_ICON 'php'
|
||||
HASKELL_ICON 'hs'
|
||||
PACKAGE_ICON 'pkg'
|
||||
)
|
||||
;;
|
||||
*)
|
||||
|
@ -761,6 +766,7 @@ function _p9k_init_icons() {
|
|||
POSTGRES_ICON 'postgres'
|
||||
PHP_ICON 'php'
|
||||
HASKELL_ICON 'hs'
|
||||
PACKAGE_ICON 'pkg'
|
||||
)
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -40,5 +40,3 @@
|
|||
segments would have "unknown" icons by default (yellow and not bold); can allow them to
|
||||
participate by defining `explainprompt_foo` that populates array `reply` with strings like this:
|
||||
'-s STATE -i LOCK_ICON +r'; the first element must be segment description.
|
||||
- add `package` segment that displays name@version where name is `.name` and version is `.version`
|
||||
from package.json. Expose them as P9K_PACKAGE_NAME and P9K_PACKAGE_VERSION.
|
||||
|
|
|
@ -2053,6 +2053,59 @@ prompt_history() {
|
|||
(( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
|
||||
}
|
||||
|
||||
prompt_package() {
|
||||
unset P9K_PACKAGE_NAME P9K_PACKAGE_VERSION
|
||||
_p9k_upglob package.json && return
|
||||
|
||||
local file=$_p9k__parent_dirs[$?]/package.json
|
||||
if ! _p9k_cache_stat_get $0 $file; then
|
||||
() {
|
||||
local data field
|
||||
local -A found
|
||||
{ data="$(<$file)" || return } 2>/dev/null
|
||||
data=${data##[[:space:]]#}
|
||||
[[ $data == '{'* ]] || return
|
||||
data[1]=
|
||||
local -i depth=1
|
||||
while true; do
|
||||
data=${data##[[:space:]]#}
|
||||
[[ -n $data ]] || return
|
||||
case $data[1] in
|
||||
'{'|'[') data[1]=; (( ++depth ));;
|
||||
'}'|']') data[1]=; (( --depth > 0 )) || return;;
|
||||
':') data[1]=;;
|
||||
',') data[1]=; field=;;
|
||||
[[:alnum:].]) data=${data##[[:alnum:].]#};;
|
||||
'"')
|
||||
local tail=${data##\"([^\"\\]|\\?)#}
|
||||
[[ $tail == '"'* ]] || return
|
||||
local s=${data:1:-$#tail}
|
||||
data=${tail:1}
|
||||
(( depth == 1 )) || continue
|
||||
if [[ -z $field ]]; then
|
||||
field=${s:-x}
|
||||
elif [[ $field == (name|version) ]]; then
|
||||
(( ! $+found[$field] )) || return
|
||||
[[ -n $s ]] || return
|
||||
print -v 'found[$field]' -- $s # this isn't quite right but close enough
|
||||
(( $#found == 2 )) && break
|
||||
fi
|
||||
;;
|
||||
*) return 1;;
|
||||
esac
|
||||
done
|
||||
_p9k_cache_stat_set 1 $found[name] $found[version]
|
||||
return 0
|
||||
} || _p9k_cache_stat_set 0
|
||||
fi
|
||||
(( _p9k__cache_val[1] )) || return
|
||||
|
||||
P9K_PACKAGE_NAME=$_p9k__cache_val[2]
|
||||
P9K_PACKAGE_VERSION=$_p9k__cache_val[3]
|
||||
local text="${${P9K_PACKAGE_NAME##*/}//\%/%%}@${P9K_PACKAGE_VERSION//\%/%%}"
|
||||
_p9k_prompt_segment "$0" "cyan" "$_p9k_color1" PACKAGE_ICON 0 '' $text
|
||||
}
|
||||
|
||||
################################################################
|
||||
# Detection for virtualization (systemd based systems only)
|
||||
prompt_detect_virt() {
|
||||
|
@ -7442,7 +7495,7 @@ _p9k_must_init() {
|
|||
[[ $sig == $_p9k__param_sig ]] && return 1
|
||||
_p9k_deinit
|
||||
fi
|
||||
_p9k__param_pat=$'v70\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1'
|
||||
_p9k__param_pat=$'v71\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1'
|
||||
_p9k__param_pat+=$'${#parameters[(I)POWERLEVEL9K_*]}\1${(%):-%n%#}\1$GITSTATUS_LOG_LEVEL\1'
|
||||
_p9k__param_pat+=$'$GITSTATUS_ENABLE_LOGGING\1$GITSTATUS_DAEMON\1$GITSTATUS_NUM_THREADS\1'
|
||||
_p9k__param_pat+=$'$DEFAULT_USER\1${ZLE_RPROMPT_INDENT:-1}\1$P9K_SSH\1$__p9k_ksh_arrays\1'
|
||||
|
|
Loading…
Reference in a new issue