mirror of
https://github.com/b-ryan/powerline-shell.git
synced 2026-09-10 07:26:28 -04:00
feat: require package.json for node_version
This commit is contained in:
parent
4b19aa47f1
commit
0f20578bfd
|
|
@ -1,5 +1,5 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
from ..utils import ThreadedSegment
|
from ..utils import ThreadedSegment, find_upwards
|
||||||
|
|
||||||
|
|
||||||
class Segment(ThreadedSegment):
|
class Segment(ThreadedSegment):
|
||||||
|
|
@ -12,7 +12,14 @@ class Segment(ThreadedSegment):
|
||||||
|
|
||||||
def add_to_powerline(self):
|
def add_to_powerline(self):
|
||||||
self.join()
|
self.join()
|
||||||
|
|
||||||
|
require_package = self.powerline.segment_conf("node_version", "require_package", False)
|
||||||
|
chars = int(self.powerline.segment_conf("node_version", "chars", 10))
|
||||||
|
has_package = find_upwards("package.json") != None
|
||||||
|
|
||||||
|
if require_package and not has_package:
|
||||||
|
return
|
||||||
if not self.version:
|
if not self.version:
|
||||||
return
|
return
|
||||||
# FIXME no hard-coded colors
|
# FIXME no hard-coded colors
|
||||||
self.powerline.append("node " + self.version, 15, 18)
|
self.powerline.append(" node " + self.version[:chars], 15, 18)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
py3 = sys.version_info[0] == 3
|
py3 = sys.version_info[0] == 3
|
||||||
|
|
||||||
|
|
@ -150,3 +151,9 @@ def get_git_subprocess_env():
|
||||||
# Otherwise we may be unable to parse the output.
|
# Otherwise we may be unable to parse the output.
|
||||||
return get_subprocess_env(LANG="C")
|
return get_subprocess_env(LANG="C")
|
||||||
|
|
||||||
|
|
||||||
|
def find_upwards(filename: str, cwd: Path = Path.cwd()) -> Path | None:
|
||||||
|
if cwd == Path(cwd.root) or cwd == cwd.parent:
|
||||||
|
return None
|
||||||
|
fullpath = cwd / filename
|
||||||
|
return fullpath if fullpath.exists() else find_upwards(filename, cwd.parent)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue