mirror of
https://github.com/sorin-ionescu/prezto.git
synced 2025-01-23 07:52:15 +08:00
Compare commits
8 Commits
3fb17b8e9b
...
971c5a9b0c
Author | SHA1 | Date | |
---|---|---|---|
|
971c5a9b0c | ||
|
0e24b6b606 | ||
|
0d64389d6d | ||
|
9d89a67162 | ||
|
5291eae55a | ||
|
c257740c53 | ||
|
b0ef5e14cf | ||
|
6f38c9ce36 |
@ -6,8 +6,6 @@
|
||||
# Zeh Rizzatti <zehrizzatti@gmail.com>
|
||||
#
|
||||
|
||||
# function node-info {
|
||||
|
||||
local version
|
||||
local version_format
|
||||
local version_formatted
|
||||
@ -15,18 +13,25 @@ local version_formatted
|
||||
unset node_info
|
||||
typeset -gA node_info
|
||||
|
||||
if (( $+commands[nodenv] )); then
|
||||
version="${${$(nodenv version)#v}[(w)0]}"
|
||||
elif (( $+functions[nvm_version] )); then
|
||||
version="${$(nvm_version)#v}"
|
||||
elif (( $+commands[node] )) ; then
|
||||
version="${$(node -v)#v}"
|
||||
fi
|
||||
|
||||
if [[ "$version" != (none|system) ]]; then
|
||||
# Only proceed if we're in a Node.js project
|
||||
if [[ -f "package.json" || -f ".nvmrc" || -f ".node-version" ]]; then
|
||||
# Get the 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
|
@ -8,19 +8,23 @@
|
||||
# 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_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
|
||||
# session.
|
||||
if (( $#local_nodenv_paths || $+commands[nodenv] )); then
|
||||
|
||||
# Ensure manually installed nodenv is added to path when present.
|
||||
[[ -s $local_nodenv_paths[1] ]] && path=($local_nodenv_paths[1]:h $path)
|
||||
|
||||
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.
|
||||
elif (( $#local_nvm_paths )); then
|
||||
source "$local_nvm_paths[1]" --no-use
|
||||
@ -31,10 +35,10 @@ elif (( $+commands[brew] )) \
|
||||
source "$nvm_path/nvm.sh" --no-use
|
||||
fi
|
||||
|
||||
unset local_n{odenv,vm}_paths nvm_path
|
||||
unset local_{nodenv,nvm,volta}_paths nvm_path
|
||||
|
||||
# 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
|
||||
fi
|
||||
|
||||
@ -64,4 +68,12 @@ if ! zstyle -t ':prezto:module:node:alias' skip; then
|
||||
alias npmci='npm ci'
|
||||
alias npmcit='npm cit'
|
||||
alias npmit='npm it'
|
||||
fi
|
||||
|
||||
# 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
|
@ -31,6 +31,7 @@
|
||||
|
||||
# Load dependencies.
|
||||
pmodload 'helper'
|
||||
pmodload 'node'
|
||||
|
||||
function prompt_sorin_async_callback {
|
||||
case $1 in
|
||||
@ -57,7 +58,7 @@ function prompt_sorin_async_callback {
|
||||
"[async]")
|
||||
# Code is 1 for corrupted worker output and 2 for dead worker.
|
||||
if [[ $2 -eq 2 ]]; then
|
||||
# Our worker died unexpectedly.
|
||||
# Our worker died unexpectedly.
|
||||
typeset -g prompt_prezto_async_init=0
|
||||
fi
|
||||
;;
|
||||
@ -110,6 +111,11 @@ function prompt_sorin_precmd {
|
||||
python-info
|
||||
fi
|
||||
|
||||
# Run node info
|
||||
if (( $+functions[node-info] )); then
|
||||
node-info
|
||||
fi
|
||||
|
||||
prompt_sorin_async_tasks
|
||||
}
|
||||
|
||||
@ -155,6 +161,9 @@ function prompt_sorin_setup {
|
||||
# Set python-info parameters.
|
||||
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
|
||||
local show_return="✘ "
|
||||
# Default is to show the return value
|
||||
@ -170,7 +179,7 @@ function prompt_sorin_setup {
|
||||
|
||||
# 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]} '
|
||||
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+='%f)${VIM:+" %B%F{6}V%f%b"}${_prompt_sorin_git}'
|
||||
SPROMPT='zsh: correct %F{1}%R%f to %F{2}%r%f [nyae]? '
|
||||
@ -186,4 +195,4 @@ function prompt_sorin_preview {
|
||||
}
|
||||
|
||||
prompt_sorin_setup "$@"
|
||||
# vim: ft=zsh
|
||||
# vim: ft=zsh
|
Loading…
Reference in New Issue
Block a user