Closed HokieGeek closed 10 years ago
ip link show up
will display all of the known interfaces, but that includes loopback
For reference, within conky I will probably do something along the lines of:
${execpi 3600 $HOME/.bin/current-ip-interface.sh}
Ok, this should take care of it:
#!/bin/sh
ip link show up | egrep '^[0-9]*:' | awk -F: '$2 !~ /lo/ { sub("^ *", "", $2); print $2 }'
Known problem: What if multiple interfaces match?
You know what, what if we make this a conky-specific script that returns all of the config values necessary for the given interface?
#!/usr/bin/python
import tempfile
import os
# Retrieve interfaces
tempFile = tempfile.NamedTemporaryFile()
os.system("ip link show up | egrep '^[0-9]*:' | awk -F: '$2 !~ /lo/ { sub("^ *", "", $2); print $2 }' > %s", tempFile.name)
interfaces = [line.strip() for line in tempFile]
tempFile.close()
# For each interface, generate conky output
if len(interfaces) == 0
#^fg(\#FF0000)No connection^fg(\#FFFFFF)
else
for interface in interfaces
# if is wireless
# TODO
# else
#TODO
Remember not to print with newlines (print(______, end="")
) and the very last thing sent out should be a \
Kinda bored at work, so:
Fixing this line:
os.system("ip link show up | egrep '^[0-9]*:' | awk -F: '$2 !~ /lo/ { sub(\"^ *\", \"\", $2); print $2 }' > %s", tempFile.name)
And fleshing this out:
# For each interface, generate conky output
for interface in interfaces
print("${if_up %s}\\", interface, end="")
if interface[0] == "w"
print("${wireless_essid %s} \\", interface, end="")
print("^fg(\\#9F0AC4)\\", end="")
print("${if_match ${wireless_link_qual_perc %s} >= 95}^i($HOME/.conky/imgs/wifi_100.xbm)${else}\\", interface, end="")
print("${if_match ${wireless_link_qual_perc %s} >= 75}^i($HOME/.conky/imgs/wifi_75.xbm)${else}\\", interface, end="")
print("${if_match ${wireless_link_qual_perc %s} >= 50}^i($HOME/.conky/imgs/wifi_50.xbm)${else}\\", interface, end="")
print("^i($HOME/.conky/imgs/wifi_25.xbm)\\", end="")
print("${endif}${endif}${endif}\\", end="")
print("^fg(\\#FFFFFF) \\", end="")
elif interface[0] == "e"
#TODO: print("^i($HOME/.conky/imgs/ethernet.xbm)\\", end="")
#TODO: print("^fg(\\#006400)^i(DOWN) ${downspeed %s}^fg(\\#FFFFFF) \\", interface, end="")
#TODO: print("^fg(\\#FF0000)^i(UP) ${upspeed %s}^fg(\\#FFFFFF) \\", interface, end="")
print("^fg(\\#606060)${addr %s}^fg(\\#FFFFFF) \\", interface, end="")
print("${endif}\\", end="")
# Lastly, output the external IP
print("^fg(\\#606060) (${exec wget -q -O /dev/stdout http://checkip.dyndns.org/ | cut -d : -f 2- | cut -d \\< -f -1 | awk '{ print $1 }'})^fg(\\#FFFFFF)\\", end="")
Research these guys (http://conky.sourceforge.net/variables.html):
${gw_iface}
${gw_ip}
${if_gw}
You idiot. If you're printing all of this in a single line, you don't need all of those backslashes!
This will be very useful for displaying info on conky