#!/usr/bin/python import subprocess import argparse parser = argparse.ArgumentParser() parser.add_argument('--color-enabled', default='#32bbc2') # parser.add_argument('--color-disabled', default='#d64937') parser.add_argument('--color-disabled', default='#777777') args = parser.parse_args() def is_enabled(): try: subprocess.check_output( 'systemctl is-active openpyn', shell=True) l = subprocess.check_output( 'cat /etc/resolv.conf | wc -l', shell=True) if int(l) != 3: return False except subprocess.CalledProcessError: # when openpyn is inactive, pgrep return exit status 1 return False else: return True if is_enabled(): # openpyn is running print('%{F' + args.color_enabled + '}' + '') else: # openpyn is NOT running print('%{F' + args.color_disabled + '}' + '') # print('%{F' + args.color_disabled + '}' + '')