dotfiles/.config/i3/py3status/net_status.py

24 lines
699 B
Python
Raw Normal View History

2021-04-27 23:25:21 +03:00
# -*- 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):
command = 'nmcli --mode multiline --colors no con show --active | rg DEVICE | awk -F":" \'{ gsub(/ /, ""); print $2}\''
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)
}