dotfiles/config/powerline-shell/segments/npm_version.py

18 lines
512 B
Python
Raw Normal View History

2021-04-20 11:12:35 +00:00
import subprocess
from ..utils import ThreadedSegment
class Segment(ThreadedSegment):
def run(self):
try:
p1 = subprocess.Popen(["npm", "--version"], stdout=subprocess.PIPE)
self.version = p1.communicate()[0].decode("utf-8").rstrip()
except OSError:
self.version = None
def add_to_powerline(self):
self.join()
if self.version:
# FIXME no hard-coded colors
self.powerline.append("npm " + self.version, 15, 18)