This repository was archived by the owner on Apr 24, 2020. It is now read-only.
File tree 1 file changed +27
-3
lines changed
1 file changed +27
-3
lines changed Original file line number Diff line number Diff line change 24
24
# $2 integer Segment index
25
25
# $3 boolean Whether the segment should be joined
26
26
# #
27
+ p9k::set_default P9K_NODE_VERSION_PROJECT_ONLY=false
27
28
prompt_node_version () {
28
- local node_version=$( node -v 2> /dev/null)
29
- [[ -z " ${node_version} " ]] && return
29
+ if [ " $P9K_NODE_VERSION_PROJECT_ONLY " = true ] ; then
30
+ local foundProject=false # Variable to stop searching if a project is found
31
+ local currentDir=$( pwd) # Variable to iterate through the path ancestry tree
30
32
31
- p9k::prepare_segment " $0 " " " $1 " $2 " $3 " ${node_version: 1} "
33
+ # Search as long as no project could been found or until the root directory
34
+ # has been reached
35
+ while [ " $foundProject " = false -a ! " $currentDir " = " /" ] ; do
36
+ # Check if directory contains a project description
37
+ if [[ -e " $currentDir /package.json" ]] ; then
38
+ foundProject=true
39
+ break
40
+ fi
41
+ # Go to the parent directory
42
+ currentDir=" $( dirname " $currentDir " ) "
43
+ done
44
+ fi
45
+
46
+ # Show version if a project has been found, or set to always show
47
+ if [ " $P9K_NODE_VERSION_PROJECT_ONLY " != true -o " $foundProject " = true ] ; then
48
+ # Get the node version
49
+ local node_version=$( node -v 2> /dev/null)
50
+
51
+ # Return if node is not installed
52
+ [[ -z " ${node_version} " ]] && return
53
+
54
+ p9k::prepare_segment " $0 " " " $1 " $2 " $3 " ${node_version: 1} "
55
+ fi
32
56
}
You can’t perform that action at this time.
0 commit comments