From 9096451d73aa7cebed2c57e3c6e744609d6e84c8 Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 12 Sep 2019 02:17:12 +0200 Subject: Improove ESSID print --- rc.lua | 68 +++++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/rc.lua b/rc.lua index 8dd1478..d5b3e0f 100644 --- a/rc.lua +++ b/rc.lua @@ -10,6 +10,7 @@ local beautiful = require("beautiful") local naughty = require("naughty") local vicious = require("vicious") local menubar = require("menubar") +local lfs = require'lfs' awful.screen = require("awful.screen") local hotkeys = require("awful.hotkeys_popup") @@ -35,6 +36,19 @@ awesome.quit = function() _awesome_quit() end +function guess_wifi(d) + for file in lfs.dir(d) do + if lfs.attributes(d .. file,"mode") == "directory" then + local ok = "" + for l in lfs.dir("/sys/class/net/" .. file) do + if l == "wireless" then + return file + end + end + end + end +end + -- Handle runtime errors after startup @@ -210,6 +224,7 @@ notify_email = true local lastIp = '' local lastInt = '' +local lastEssid = '' function act() vicious.force({ mpdwidget, }) @@ -265,19 +280,19 @@ function act() --{{ Network awful.spawn.easy_async("bash -c \"ip r | grep default | head -n 1 | sed s/.*dev/sed/ | cut -d' ' -f 2\"", - function(interface, stderr, reason, exit_code) - if not ( interface == "" or interface == "\n") then - interface = string.gsub(interface, "\n", "") - if not (interface == lastInt) then + function(interface_default, stderr, reason, exit_code) + if not ( interface_default == "" or interface_default == "\n") then + interface_default = string.gsub(interface_default, "\n", "") + if not (interface_default == lastInt) then naughty.notify({ preset = naughty.config.presets.normal, title = "ip change", - text = "Changement d'interface " .. lastInt .. " to " - .. interface, + text = "Changement d'interface par defaut " .. lastInt .. " par " + .. interface_default, timeout=20}) - lastInt = interface + lastInt = interface_default end - awful.spawn.easy_async("bash -c \"ip r | grep 'dev " .. interface .. "' | grep src | head -n 1 | sed 's/.*src/src/' | cut -d' ' -f 2 | cut -z -f1\"", + awful.spawn.easy_async("bash -c \"ip r | grep 'dev " .. interface_default .. "' | grep src | head -n 1 | sed 's/.*src/src/' | cut -d' ' -f 2 | cut -z -f1\"", function(ip, stderr2, reason3, exit_code3) toShow = "" if not ( ip == "" or ip == "\n") then @@ -292,18 +307,33 @@ function act() lastIp = ip end end - awful.spawn.easy_async("bash -c \"iwconfig " .. interface .. " 2>&1 | grep -v 'no wireless' | grep " .. interface .. " | cut -d'\\\"' -f 2 \"", + toShow = toShow .. interface_default + interface_wifi = guess_wifi("/sys/class/net/") + awful.spawn.easy_async("bash -c \"printf '%b' $(iwconfig " .. interface_wifi .." 2>&1 | grep -v 'no wireless' | grep ESSID | grep -v 'off/any' | tail -n 1 | cut -d'\\\"' -f 2)\"", function(essid, stderr2, reason2, exit_code2) if not (essid == "" ) then essid = string.gsub(essid, "\n", "") - awful.spawn.easy_async("bash -c \"iwconfig " .. interface .. " 2>&1 | grep -v 'no wireless' | grep Signal | cut -d'=' -f 3 | cut -d' ' -f 1\"", + + if not (essid == lastEssid) then + naughty.notify({ preset = naughty.config.presets.normal, + title = "Connection Wifi", + text = "Connecté à " .. essid .. " !", + timeout=20}) + lastEssid = essid + end + + awful.spawn.easy_async("bash -c \"iwconfig 2>&1 | grep -v 'no wireless' | grep Signal | cut -d'=' -f 3 | cut -d' ' -f 1\"", function(signal, stderr3, reason3, exit_code3) - signal = string.gsub(signal, "\n", "") - mynetworkwidget:set_text ( ip .. "@" .. essid .. "#" .. signal) + signal = string.gsub(signal, "\n", "") + awful.spawn.easy_async("bash -c \"ip a s " .. interface_wifi .. " | grep 'inet ' | cut -d' ' -f 6\"", + function(ip_wifi, stderr, reason, exit_code) + ip_wifi = string.gsub(ip_wifi, "\n", "") + mynetworkwidget:set_text ( "" .. ip_wifi .. "@" .. interface_wifi .. " " .. essid .. "#" .. signal .. " / " .. toShow) + end) end ) else - mynetworkwidget:set_text ( toShow .. interface ) + mynetworkwidget:set_text ( toShow ) end end ) @@ -546,17 +576,17 @@ awful.key({ modkey, "Shift" }, "s", hotkeys_popup.show_help, {descriptio -- Raccourcis perso awful.key({ }, "XF86AudioRaiseVolume", function () - awful.util.spawn("amixer -D pulse sset Master 8%+") end), + awful.util.spawn("pamixer -i 8") end), awful.key({ }, "XF86AudioLowerVolume", function () - awful.util.spawn("amixer -D pulse sset Master 8%-") end), + awful.util.spawn("pamixer -d 8") end), awful.key({ }, "XF86AudioMute", function () - awful.util.spawn("amixer -D pulse sset Master toggle") end), + awful.util.spawn("pamixer -t") end), awful.key({ }, "F12", function () - awful.util.spawn("amixer -D pulse sset Master 8%+") end), + awful.util.spawn("pamixer -i 8") end), awful.key({ }, "F10", function () - awful.util.spawn("amixer -D pulse sset Master 8%-") end), + awful.util.spawn("pamixer -d 8") end), awful.key({ }, "F11", function () - awful.util.spawn("amixer -D pulse sset Master toggle") end), + awful.util.spawn("pamixer -t") end), awful.key({ }, "XF86AudioPlay", function () awful.util.spawn("mpc toggle") end), -- cgit v1.2.3