dotfiles/config/powerline-shell/segments/npm_version.py
2021-04-20 13:12:35 +02:00

17 lines
512 B
Python

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)