Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nodejs prompt #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions agnoster.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typeset -aHg AGNOSTER_PROMPT_SEGMENTS=(
prompt_virtualenv
prompt_dir
prompt_git
prompt_node_version
prompt_end
)

Expand Down Expand Up @@ -142,6 +143,35 @@ prompt_virtualenv() {
fi
}

# Helper fucntion to check if a command exists
exists() {
command -v $1 > /dev/null 2>&1
}

# Show NODE JS status only for JS/TS specific folders(based on spaceship-prompt)
function prompt_node_version {
[[ -f package.json || -d node_modules || -n *.js(#qN^/) || *.ts(#qN^/) ]] || return

local 'node_version'

if exists fnm; then
node_version=$(fnm current 2>/dev/null)
[[ $node_version == "system" || $node_version == "node" ]] && return
elif exists nvm; then
node_version=$(nvm current 2>/dev/null)
[[ $node_version == "system" || $node_version == "node" ]] && return
elif exists nodenv; then
node_version=$(nodenv version-name)
[[ $node_version == "system" || $node_version == "node" ]] && return
elif exists node; then
node_version=$(node -v 2>/dev/null)
else
return
fi

prompt_segment black default "%{%F{green}%} ⬢ ${node_version} "
}

## Main prompt
prompt_agnoster_main() {
RETVAL=$?
Expand Down