#!/usr/bin/python import subprocess import argparse parser = argparse.ArgumentParser() parser.add_argument('--color-enabled', default='#ffffff') # 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: res1 = subprocess.check_output( 'ip address show dev enp34s0 | rg inet6 | wc -l', shell=True) return int(res1) != 0 except subprocess.CalledProcessError: # when openpyn is inactive, pgrep return exit status 1 return False else: return True if is_enabled(): print('%{F' + args.color_enabled + '}' + 'IPv6') else: print('%{F' + args.color_disabled + '}' + 'IPv6') # print('%{F' + args.color_disabled + '}' + '')