This commit is contained in:
Adam 2024-12-26 22:46:57 -06:00 committed by GitHub
commit 971c5a9b0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 50 additions and 24 deletions

View File

@ -6,8 +6,6 @@
# Zeh Rizzatti <zehrizzatti@gmail.com> # Zeh Rizzatti <zehrizzatti@gmail.com>
# #
# function node-info {
local version local version
local version_format local version_format
local version_formatted local version_formatted
@ -15,18 +13,25 @@ local version_formatted
unset node_info unset node_info
typeset -gA node_info typeset -gA node_info
if (( $+commands[nodenv] )); then # Only proceed if we're in a Node.js project
version="${${$(nodenv version)#v}[(w)0]}" if [[ -f "package.json" || -f ".nvmrc" || -f ".node-version" ]]; then
elif (( $+functions[nvm_version] )); then # Get the format
version="${$(nvm_version)#v}"
elif (( $+commands[node] )) ; then
version="${$(node -v)#v}"
fi
if [[ "$version" != (none|system) ]]; then
zstyle -s ':prezto:module:node:info:version' format 'version_format' zstyle -s ':prezto:module:node:info:version' format 'version_format'
zformat -f version_formatted "$version_format" "v:$version"
node_info[version]="$version_formatted"
fi
# } if [[ -n "$version_format" ]]; then
if (( $+commands[nodenv] )); then
version="${${$(nodenv version)#v}[(w)0]}"
elif (( $+commands[volta] )); then
version="${${$(volta list node | grep 'default')#*@}%% *}"
elif (( $+functions[nvm_version] )); then
version="${$(nvm_version)#v}"
elif (( $+commands[node] )) ; then
version="${$(node -v)#v}"
fi
if [[ -n "$version" && "$version" != "system" ]]; then
zformat -f version_formatted "$version_format" "v:$version"
node_info[version]="$version_formatted"
fi
fi
fi

View File

@ -8,19 +8,23 @@
# Indrajit Raychaudhuri <irc@indrajit.com> # Indrajit Raychaudhuri <irc@indrajit.com>
# #
# Possible lookup locations for manually installed nodenv and nvm. # Possible lookup locations for manually installed version managers
local_nodenv_paths=({$NODENV_ROOT,{$XDG_CONFIG_HOME/,$HOME/.}nodenv}/bin/nodenv(N)) local_nodenv_paths=({$NODENV_ROOT,{$XDG_CONFIG_HOME/,$HOME/.}nodenv}/bin/nodenv(N))
local_nvm_paths=({$NVM_DIR,{$XDG_CONFIG_HOME/,$HOME/.}nvm}/nvm.sh(N)) local_nvm_paths=({$NVM_DIR,{$XDG_CONFIG_HOME/,$HOME/.}nvm}/nvm.sh(N))
local_volta_paths=({$VOLTA_HOME,$HOME/.volta}/bin/volta(N))
# Load manually installed or package manager installed nodenv into the shell # Load manually installed or package manager installed nodenv into the shell
# session. # session.
if (( $#local_nodenv_paths || $+commands[nodenv] )); then if (( $#local_nodenv_paths || $+commands[nodenv] )); then
# Ensure manually installed nodenv is added to path when present. # Ensure manually installed nodenv is added to path when present.
[[ -s $local_nodenv_paths[1] ]] && path=($local_nodenv_paths[1]:h $path) [[ -s $local_nodenv_paths[1] ]] && path=($local_nodenv_paths[1]:h $path)
eval "$(nodenv init - zsh)" eval "$(nodenv init - zsh)"
# Use volta if it's installed
elif (( $#local_volta_paths || $+commands[volta] )); then
export VOLTA_HOME="${VOLTA_HOME:-$HOME/.volta}"
path=("$VOLTA_HOME/bin" $path)
# Load manually installed nvm into the shell session. # Load manually installed nvm into the shell session.
elif (( $#local_nvm_paths )); then elif (( $#local_nvm_paths )); then
source "$local_nvm_paths[1]" --no-use source "$local_nvm_paths[1]" --no-use
@ -31,10 +35,10 @@ elif (( $+commands[brew] )) \
source "$nvm_path/nvm.sh" --no-use source "$nvm_path/nvm.sh" --no-use
fi fi
unset local_n{odenv,vm}_paths nvm_path unset local_{nodenv,nvm,volta}_paths nvm_path
# Return if requirements are not found. # Return if requirements are not found.
if (( ! $+commands[node] && ! $#functions[(i)n(odenv|vm)] )); then if (( ! $+commands[node] && ! $#functions[(i)n(odenv|vm)] && ! $+commands[volta] )); then
return 1 return 1
fi fi
@ -64,4 +68,12 @@ if ! zstyle -t ':prezto:module:node:alias' skip; then
alias npmci='npm ci' alias npmci='npm ci'
alias npmcit='npm cit' alias npmcit='npm cit'
alias npmit='npm it' alias npmit='npm it'
# Add Volta-specific aliases if Volta is installed
if (( $+commands[volta] )); then
alias vl='volta list'
alias vla='volta list all'
alias vi='volta install'
alias vp='volta pin'
fi
fi fi

View File

@ -31,6 +31,7 @@
# Load dependencies. # Load dependencies.
pmodload 'helper' pmodload 'helper'
pmodload 'node'
function prompt_sorin_async_callback { function prompt_sorin_async_callback {
case $1 in case $1 in
@ -57,7 +58,7 @@ function prompt_sorin_async_callback {
"[async]") "[async]")
# Code is 1 for corrupted worker output and 2 for dead worker. # Code is 1 for corrupted worker output and 2 for dead worker.
if [[ $2 -eq 2 ]]; then if [[ $2 -eq 2 ]]; then
# Our worker died unexpectedly. # Our worker died unexpectedly.
typeset -g prompt_prezto_async_init=0 typeset -g prompt_prezto_async_init=0
fi fi
;; ;;
@ -110,6 +111,11 @@ function prompt_sorin_precmd {
python-info python-info
fi fi
# Run node info
if (( $+functions[node-info] )); then
node-info
fi
prompt_sorin_async_tasks prompt_sorin_async_tasks
} }
@ -155,6 +161,9 @@ function prompt_sorin_setup {
# Set python-info parameters. # Set python-info parameters.
zstyle ':prezto:module:python:info:virtualenv' format '%f%F{3}(%v)%F{7} ' zstyle ':prezto:module:python:info:virtualenv' format '%f%F{3}(%v)%F{7} '
# Set node-info parameters
zstyle ':prezto:module:node:info:version' format ' %F{2}⬡ %v%f'
# Set up non-zero return value display # Set up non-zero return value display
local show_return="✘ " local show_return="✘ "
# Default is to show the return value # Default is to show the return value
@ -170,7 +179,7 @@ function prompt_sorin_setup {
# Define prompts. # Define prompts.
PROMPT='${SSH_TTY:+"%F{9}%n%f%F{7}@%f%F{3}%m%f "}%F{4}${_prompt_sorin_pwd}%(!. %B%F{1}#%f%b.)${editor_info[keymap]} ' PROMPT='${SSH_TTY:+"%F{9}%n%f%F{7}@%f%F{3}%m%f "}%F{4}${_prompt_sorin_pwd}%(!. %B%F{1}#%f%b.)${editor_info[keymap]} '
RPROMPT='$python_info[virtualenv]${editor_info[overwrite]}%(?:: %F{1}' RPROMPT='$python_info[virtualenv]${node_info[version]} ${editor_info[overwrite]}%(?:: %F{1}'
RPROMPT+=${show_return} RPROMPT+=${show_return}
RPROMPT+='%f)${VIM:+" %B%F{6}V%f%b"}${_prompt_sorin_git}' RPROMPT+='%f)${VIM:+" %B%F{6}V%f%b"}${_prompt_sorin_git}'
SPROMPT='zsh: correct %F{1}%R%f to %F{2}%r%f [nyae]? ' SPROMPT='zsh: correct %F{1}%R%f to %F{2}%r%f [nyae]? '