diff options
author | Mohammed Abdel Ra'ouf <raouf@devsquads.com> | 2019-03-22 15:45:52 +0300 |
---|---|---|
committer | Mohammed Abdel Ra'ouf <raouf@devsquads.com> | 2019-03-22 15:45:52 +0300 |
commit | b0e48cbdc892816e0a5ef976e731283a5f73ccfa (patch) | |
tree | d5a418ca89fa8f4a0d41ef8ff8d0b65685aa6563 /powerlevel9k.zsh-theme | |
parent | 27b415f7f5822b0611e1fa167b6f4c335060d57a (diff) |
add node_version only inside project folder option
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index faa3c156..8d00f448 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1171,11 +1171,35 @@ prompt_load() { ################################################################ # Segment to diplay Node version +set_default P9K_NODE_VERSION_PROJECT_ONLY false prompt_node_version() { - local node_version=$(node -v 2>/dev/null) - [[ -z "${node_version}" ]] && return + if [ "$P9K_NODE_VERSION_PROJECT_ONLY" = true ] ; then + local foundProject=false # Variable to stop searching if a project is found + local currentDir=$(pwd) # Variable to iterate through the path ancestry tree + + # Search as long as no project could been found or until the root directory + # has been reached + while [ "$foundProject" = false -a ! "$currentDir" = "/" ] ; do + + # Check if directory contains a project description + if [[ -e "$currentDir/package.json" ]] ; then + foundProject=true + break + fi + # Go to the parent directory + currentDir="$(dirname "$currentDir")" + done + fi - "$1_prompt_segment" "$0" "$2" "green" "white" 'NODE_ICON' 0 '' "${${node_version:1}//\%/%%}" + # Show version if a project has been found, or set to always show + if [ "$P9K_NODE_VERSION_PROJECT_ONLY" != true -o "$foundProject" = true ] ; then + # Get the node version + local node_version=$(node -v 2>/dev/null) + + # Return if node is not installed + [[ -z "${node_version}" ]] && return + "$1_prompt_segment" "$0" "$2" "green" "white" 'NODE_ICON' 0 '' "${${node_version:1}//\%/%%}" + fi } ################################################################ |