Files
dotfiles/.config/waybar/scripts/wireguard.py
2024-11-11 02:30:59 +01:00

24 lines
652 B
Python

from argparse import ArgumentParser
from json import dumps
from subprocess import run
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("interfaces", nargs="+", help="one or more names of interfaces to watch")
args = parser.parse_args()
watch = set(args.interfaces)
ifconfig = run(["ifconfig", "-s"], capture_output=True, text=True).stdout
interfaces = {line.split()[0] for line in ifconfig.splitlines()[1:]}
active = interfaces.intersection(watch)
result = {
"text": "active" if len(active) > 0 else "inactive",
"tooltip": "\n".join(active),
}
print(dumps(result))