New Setup 📦

This commit is contained in:
Luca 2023-02-05 05:02:49 +01:00
parent d16174b447
commit 415dbd08a1
10194 changed files with 1368647 additions and 4 deletions

View file

@ -0,0 +1,33 @@
-- emits airplane status (with nmcli)
-- well, it works for me. so yeah
---------------------------------
-- ("signal::airplane"), function(net_status(bool))
-- rquirements
local awful = require("awful")
-- interval (in seconds)
local update_interval = 1
-- import network info
local net_cmd = [[
bash -c "
nmcli r wifi | awk 'FNR = 2 {print $1}'
"
]]
awful.widget.watch(net_cmd, update_interval, function(_, stdout)
local net_ssid = stdout
net_ssid = string.gsub(net_ssid, '^%s*(.-)%s*$', '%1')
local net_status = true
-- update networks status
if net_ssid == "disabled" then
net_status = false
end
-- emit (true or false)
awesome.emit_signal("signal::airplane", net_status)
end)

View file

@ -0,0 +1,40 @@
-- ## Battery ##
-- ~~~~~~~~~~~~~
-- requirements
-- ~~~~~~~~~~~~
local awful = require("awful")
local gears = require("gears")
local beautiful = require ("beautiful")
local have_battery = [[
bash -c '
cat /sys/class/power_supply/BAT?/capacity 2>/dev/null | head -1
'
]]
local bat_value
local bat_desc
local function get_bat()
awful.spawn.easy_async(have_battery, function(stdout)
if not stdout:match("%d+") then
bat_value = 0
bat_desc = "No Battery"
awesome.emit_signal("signal::bat", bat_value, bat_desc)
else
bat_value = tonumber(stdout)
bat_desc = bat_value.." %"
awesome.emit_signal("signal::bat", bat_value, bat_desc)
end
end)
end
gears.timer {
timeout = 5,
call_now = true,
autostart = true,
callback = function()
get_bat()
end
}

View file

@ -0,0 +1,43 @@
-- emits bluetooth status
-- listen, i know this is dumb but.. yeah.
------------------------------------------
-- ("signal::bluetooth"), function(status(bool), service_status(bool))
-- requirements
local awful = require("awful")
-- update interval
local update_interval = 1
-- import bluetooth info
local cmd = [[
bash -c "
bluetoothctl show | grep "Powered:" | awk '{ print $2 }'
"
]]
awful.widget.watch(cmd, update_interval, function(_, stdout)
local output = string.gsub(stdout, '^%s*(.-)%s*$', '%1')
local bluetooth_active = true
local bluetooth_runnding_service
-- lets see if bluetooth.service is enabled
awful.spawn.easy_async_with_shell("bash -c 'pgrep bluetooth'", function (lets_see)
if lets_see == "" then
bluetooth_runnding_service = false
else
bluetooth_runnding_service = true
end
end)
-- set output as above info
if output == "no" then
bluetooth_active = bluetooth_runnding_service
end
-- emit (powered on?) , (is the proceess running?)
awesome.emit_signal("signal::bluetooth", bluetooth_active, bluetooth_runnding_service)
end)

View file

@ -0,0 +1,51 @@
-- ## Brightness ##
-- ~~~~~~~~~~~~~~~~
-- requirements
-- ~~~~~~~~~~~~
local awful = require("awful")
-- Provides:
-- signal::brightness
-- percentage (integer)
local brightness_subscribe_script = [[
bash -c "
while (inotifywait -e modify /sys/class/backlight/?**/brightness -qq) do echo; done
"]]
local brightness_script = [[
sh -c "
brightnessctl g
"]]
local brightness_max = [[
sh -c "
brightnessctl m
"]]
local emit_brightness_info = function()
awful.spawn.with_line_callback(brightness_script, {
stdout = function(value)
awful.spawn.with_line_callback(brightness_max, {
stdout = function(max)
percentage = tonumber(value)/tonumber(max) * 100
percentage = tonumber(percentage) or 0
awesome.emit_signal("signal::brightness", percentage)
end})
end
})
end
-- Run once to initialize widgets
emit_brightness_info()
-- Kill old inotifywait process
awful.spawn.easy_async_with_shell("ps x | grep \"inotifywait -e modify /sys/class/backlight\" | grep -v grep | awk '{print $1}' | xargs kill", function ()
-- Update brightness status with each line printed
awful.spawn.with_line_callback(brightness_subscribe_script, {
stdout = function(_)
emit_brightness_info()
end
})
end)

View file

@ -0,0 +1,29 @@
-- ## Disk ##
-- ~~~~~~~~~~
-- requirements
-- ~~~~~~~~~~~~
local awful = require("awful")
local gears = require("gears")
local which_disk = "/dev/sda2"
local function get_disk()
local script = [[
df -kH -B 1MB ]]..which_disk..[[ | tail -1 | awk '{printf $5}'
]]
awful.spawn.easy_async_with_shell(script, function(disk_perc)
disk_perc = disk_perc:match("%d+")
awesome.emit_signal("signal::disk", disk_perc)
end)
end
gears.timer {
timeout = 2000,
call_now = true,
autostart = true,
callback = function()
get_disk()
end
}

View file

@ -0,0 +1,15 @@
req = {
"volume",
"brightness",
"wifi",
"bluetooth",
"airplane",
"weather",
"battery",
"player",
"disk"
}
for _, x in pairs(req) do
require("signals."..x)
end

View file

@ -0,0 +1,43 @@
-- ## Player ##
-- ~~~~~~~~~~~~
-- requirements
-- ~~~~~~~~~~~~
local awful = require("awful")
local gears = require("gears")
-- Script
local title_sc = 'playerctl metadata --format {{title}}'
local artist_sc = 'playerctl metadata --format "{{artist}}"'
local length_sc = 'playerctl metadata --format "{{duration(position)}}/{{(mpris:length)}}"'
local art_sc = [[playerctl metadata --format "{{mpris:artUrl}}" | sed -e 's/^.......//g']]
local status_sc = 'playerctl metadata --format "{{status}}"'
-- function
local function get_player()
awful.spawn.easy_async_with_shell(title_sc, function(title)
awful.spawn.easy_async_with_shell(artist_sc, function(artist)
awful.spawn.easy_async_with_shell(art_sc, function(length)
awful.spawn.easy_async_with_shell(status_sc, function(status)
title = string.gsub(title, "\n", "")
artist = string.gsub(artist, "\n", "")
length_sc = string.gsub(art_sc, "\n", "")
--art = string.gsub(art_sc, "\n", "")
status = string.gsub(status, "\n", "")
awesome.emit_signal("signal::player", title, artist, length, status)
end)
end)
end)
end)
end
gears.timer {
timeout = 2,
call_now = true,
autostart = true,
callback = function()
get_player()
end
}

View file

@ -0,0 +1,36 @@
-- ## Volume ##
-- ~~~~~~~~~~~~
-- requirements
-- ~~~~~~~~~~~~
local awful = require("awful")
local gears = require("gears")
local wibox = require ("wibox")
local vol_sc = 'pamixer --get-volume'
local mute_sc = 'pamixer --get-mute'
local function get_vol()
awful.spawn.easy_async_with_shell(vol_sc, function(vol)
awful.spawn.easy_async_with_shell(mute_sc, function(mute)
if mute:match("false") then
muted = false
else
muted = true
end
awesome.emit_signal("signal::volume", vol, muted)
end)
end)
end
gears.timer {
timeout = 2,
call_now = true,
autostart = true,
callback = function()
get_vol()
end
}

View file

@ -0,0 +1,30 @@
-- ## Wearther ##
-- ~~~~~~~~~~~~~~
-- requirements
-- ~~~~~~~~~~~~
local awful = require("awful")
local gears = require("gears")
local city = "" -- Ex. London or Salt+Lake+City
local get_weather = function()
local script = [[
bash -c "$HOME/.config/awesome/signals/weather_script.sh ]] .. city.. [["
]]
awful.spawn.easy_async_with_shell(script, function(stdout)
local weather = stdout:match("(.+):")
local feels_like = stdout:match(".+[:](.+)")
awesome.emit_signal('signal::weather', weather, feels_like)
end)
end
gears.timer {
timeout = 1200,
call_now = true,
autostart = true,
callback = function()
get_weather()
end
}

View file

@ -0,0 +1,9 @@
#!/bin/sh
# This script is used to find weather
city=$1
weather=$(curl -sf "wttr.in/$city?format='%C:%f'")
if [[ ! -z $weather ]]; then
echo $weather
else
echo "Weather unavailable"
fi

View file

@ -0,0 +1,33 @@
-- emits wifi status (with nmcli)
-- well, it works for me. so yeah
---------------------------------
-- ("signal::wifi"), function(net_status(bool))
-- rquirements
local awful = require("awful")
-- interval (in seconds)
local update_interval = 1
-- import network info
local net_cmd = [[
bash -c "
nmcli r wifi | awk 'FNR = 2 {print $1}'
"
]]
awful.widget.watch(net_cmd, update_interval, function(_, stdout)
local net_ssid = stdout
net_ssid = string.gsub(net_ssid, '^%s*(.-)%s*$', '%1')
local net_status = true
-- update networks status
if net_ssid == "disabled" then
net_status = false
end
-- emit (true or false)
awesome.emit_signal("signal::wifi", net_status)
end)

View file

@ -0,0 +1,46 @@
-- ## Wifi ##
-- ~~~~~~~~~~~
-- requirements
-- ~~~~~~~~~~~~
local awful = require("awful")
local gears = require("gears")
local old_net_ssid = "Reconnect"
local old_net_stat = false
local check_wifi = function()
local script = [[
nmcli -t connection show --active
]]
awful.spawn.easy_async_with_shell(
script,
function(stdout)
local net_ssid = stdout
local net_stat = true
if net_ssid == "" then
net_stat = false
net_ssid = "Not Connected"
end
if net_ssid ~= old_net_ssid then -- Emit signal if there was a change
awesome.emit_signal("signal::wifi", net_stat, net_ssid)
old_net_ssid = net_ssid
old_net_stat = net_stat
end
end
)
end
check_wifi()
gears.timer {
timeout = 3,
autostart = true,
call_now = true,
callback = function()
check_wifi()
end,
}