Skip to content
This repository was archived by the owner on Apr 24, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ The segments that are currently available are:
* **GoLang Segments:**
* `go_version` - Show the current GO version.
* **Javascript / Node.js Segments:**
* `node_version` - Show the version number of the installed Node.js.
* [`node_version`](#node_version) - Show the version number of the installed Node.js.
* `nodeenv` - [nodeenv](https://github.com/ekalinin/nodeenv) prompt for displaying node version and environment name.
* `nvm` - Show the version of Node that is currently active, if it differs from the version used by NVM
* **PHP Segments:**
Expand Down Expand Up @@ -643,6 +643,14 @@ you are using the [ZSH Line Editor](http://zsh.sourceforge.net/Doc/Release/Zsh-L

To hide the segment entirely when in `INSERT` mode, set `POWERLEVEL9K_VI_INSERT_MODE_STRING=''`

##### node_version

This segment shows the _NodeJS_ version, that is currently active.

| Variable | Default Value | Description |
|----------|---------------|-------------|
|`POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY`|`false`|If `true` this segment only appears inside _NodeJS_ projects described by a `package.json`.|

#### Unit Test Ratios

The `symfony2_tests` and `rspec_stats` segments both show a ratio of "real"
Expand Down
35 changes: 29 additions & 6 deletions powerlevel9k.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,6 @@ prompt_load() {

# Replace comma
load_avg=${load_avg//,/.}

if [[ "$load_avg" -gt $((${cores} * 0.7)) ]]; then
current_state="critical"
elif [[ "$load_avg" -gt $((${cores} * 0.5)) ]]; then
Expand All @@ -1055,13 +1054,37 @@ prompt_load() {
"$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg" 'LOAD_ICON'
}

################################################################
# Segment to diplay Node version
# Node version
set_default POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY=false

prompt_node_version() {
local node_version=$(node -v 2>/dev/null)
[[ -z "${node_version}" ]] && return
if [ "$POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY" = true ] ; then
local foundProject=false # Variable to stop searching if a project has been found.
local currentDir=$(pwd) # Variable to iterate trough the path reverse.

# Search as long as no project could been found or the root directory has been reached.
while [ "$foundProject" = false -a ! "$currentDir" = "/" ] ; do
# Check if directory contain a project description.
if [[ -a "$currentDir/package.json" ]] ; then
foundProject=true
fi

# Go to the parent directory.
currentDir="$(dirname "$currentDir")"
done
fi

# Show version if it should been shown always or if a project has been found.
if [ "$POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY" = false -o "$foundProject" = true ] ; then
# Get the node version.
local node_version=$(node -v 2>/dev/null)

"$1_prompt_segment" "$0" "$2" "green" "white" "${node_version:1}" 'NODE_ICON'
# Return if node is not installed (version output empty).
[[ -z "${node_version}" ]] && return

# Define the segments itself.
"$1_prompt_segment" "$0" "$2" "green" "white" "${node_version:1}" 'NODE_ICON'
fi
}

################################################################
Expand Down