dotfiles/.config/i3/py3status/net_status.py
2021-08-28 20:15:49 +03:00

25 lines
770 B
Python

# -*- coding: utf-8 -*-
"""
This module produces list of enabled network interfaces
"""
import sys
import subprocess
from subprocess import check_output
class Py3status:
format = 'NET: {status}'
def net_status(self):
# Retrieve active connections, Ignore bridges
command = 'nmcli --mode multiline --colors no con show --active | rg DEVICE | awk -F":" \'{ gsub(/ /, ""); print $2}\' | rg \'^[^br-]\''
return_value = check_output(command, shell=True)
value = return_value.decode("utf-8")
value = value.replace('\n', ', ').strip(', ')
full_text = self.py3.safe_format(self.format, { 'status': value})
return {
'full_text': full_text,
'cached_until': self.py3.time_in(15)
}