File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 1
1
import subprocess
2
- from ..utils import ThreadedSegment
2
+ from ..utils import ThreadedSegment , find_upwards
3
3
4
4
5
5
class Segment (ThreadedSegment ):
@@ -12,7 +12,14 @@ def run(self):
12
12
13
13
def add_to_powerline (self ):
14
14
self .join ()
15
+
16
+ require_package = self .powerline .segment_conf ("node_version" , "require_package" , False )
17
+ chars = int (self .powerline .segment_conf ("node_version" , "chars" , 10 ))
18
+ has_node = find_upwards ("package.json" ) != None
19
+
20
+ if require_package and not has_node :
21
+ return
15
22
if not self .version :
16
23
return
17
24
# FIXME no hard-coded colors
18
- self .powerline .append ("node " + self .version , 15 , 18 )
25
+ self .powerline .append (" node " + self .version [: chars ] , 15 , 18 )
Original file line number Diff line number Diff line change 1
1
import sys
2
2
import os
3
3
import threading
4
+ from pathlib import Path
4
5
5
6
py3 = sys .version_info [0 ] == 3
6
7
@@ -150,3 +151,9 @@ def get_git_subprocess_env():
150
151
# Otherwise we may be unable to parse the output.
151
152
return get_subprocess_env (LANG = "C" )
152
153
154
+
155
+ def find_upwards (filename : str , cwd : Path = Path .cwd ()) -> Path | None :
156
+ if cwd == Path (cwd .root ) or cwd == cwd .parent :
157
+ return None
158
+ fullpath = cwd / filename
159
+ return fullpath if fullpath .exists () else find_upwards (filename , cwd .parent )
You can’t perform that action at this time.
0 commit comments