redone bluetooth widget
This commit is contained in:
23
awesome/theme/crylia/scripts/bt.sh
Executable file
23
awesome/theme/crylia/scripts/bt.sh
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
DEVICES=$(bluetoothctl paired-devices | cut -f2 -d' '|
|
||||||
|
while read -r uuid
|
||||||
|
do
|
||||||
|
info=`bluetoothctl info $uuid`
|
||||||
|
if echo "$info" | grep -q "Connected: yes"; then
|
||||||
|
echo "$info" | head -n 1 | grep "Device" | awk '{print $2}'
|
||||||
|
fi
|
||||||
|
done)
|
||||||
|
NAMES=$(bluetoothctl paired-devices | cut -f2 -d' '|
|
||||||
|
while read -r uuid
|
||||||
|
do
|
||||||
|
info=`bluetoothctl info $uuid`
|
||||||
|
if echo "$info" | grep -q "Connected: yes"; then
|
||||||
|
echo "$info" | grep "Name" | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}'
|
||||||
|
fi
|
||||||
|
done)
|
||||||
|
for device in $DEVICES; do
|
||||||
|
STRING=$(bluetoothctl info $device | grep 'Battery Percentage:' | awk '{print "\n Battery: " $4 "%"}')
|
||||||
|
echo " $(bluetoothctl info ${device} | grep Name: | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}') ${STRING}"
|
||||||
|
done
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ return function()
|
|||||||
awful.widget.watch(
|
awful.widget.watch(
|
||||||
"rfkill list bluetooth",
|
"rfkill list bluetooth",
|
||||||
5,
|
5,
|
||||||
function(stdout)
|
function(_, stdout)
|
||||||
local icon = icondir .. "bluetooth"
|
local icon = icondir .. "bluetooth"
|
||||||
if stdout:match('Soft blocked: yes') or stdout:gsub("\n", "") == '' then
|
if stdout:match('Soft blocked: yes') or stdout:gsub("\n", "") == '' then
|
||||||
icon = icon .. "-off"
|
icon = icon .. "-off"
|
||||||
@@ -65,13 +65,13 @@ return function()
|
|||||||
icon = icon .. "-on"
|
icon = icon .. "-on"
|
||||||
bluetooth_state = "on"
|
bluetooth_state = "on"
|
||||||
awful.spawn.easy_async_with_shell(
|
awful.spawn.easy_async_with_shell(
|
||||||
[[ bluetoothctl info | grep Name: | awk '{ first = $1; $1 = ""; print $0 }' ]],
|
'./.config/awesome/theme/crylia/scripts/bt.sh',
|
||||||
function(stdout2)
|
function(stdout2)
|
||||||
if stdout2 == nil or stdout2:gsub("\n", "") == "" then
|
if stdout2 == nil or stdout2:gsub("\n", "") == "" then
|
||||||
bluetooth_tooltip:set_text("Bluetooth is turned " .. bluetooth_state .. "\n" .. "You are currently not connected")
|
bluetooth_tooltip:set_text("Bluetooth is turned " .. bluetooth_state .. "\n" .. "You are currently not connected")
|
||||||
else
|
else
|
||||||
bluetooth_tooltip:set_text("Bluetooth is turned " .. bluetooth_state .. "\n" .. "You are currently connected to:" .. connected_device)
|
connected_device = stdout2:gsub("%(", ""):gsub("%)", "")
|
||||||
connected_device = stdout2
|
bluetooth_tooltip:set_text("Bluetooth is turned " .. bluetooth_state .. "\n" .. "You are currently connected to:\n" .. connected_device)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@@ -90,8 +90,8 @@ return function()
|
|||||||
awful.spawn.easy_async_with_shell(
|
awful.spawn.easy_async_with_shell(
|
||||||
"rfkill list bluetooth",
|
"rfkill list bluetooth",
|
||||||
function(stdout)
|
function(stdout)
|
||||||
if stdout:gsub("\n", "") == '' then
|
if stdout:gsub("\n", "") ~= '' then
|
||||||
if bluetooth_state == "on" then
|
if bluetooth_state == "off" then
|
||||||
awful.spawn.easy_async_with_shell(
|
awful.spawn.easy_async_with_shell(
|
||||||
[[
|
[[
|
||||||
rfkill unblock bluetooth
|
rfkill unblock bluetooth
|
||||||
@@ -100,7 +100,7 @@ return function()
|
|||||||
]],
|
]],
|
||||||
function()
|
function()
|
||||||
naughty.notify({
|
naughty.notify({
|
||||||
Title = "System Notification",
|
title = "System Notification",
|
||||||
app_name = "Bluetooth",
|
app_name = "Bluetooth",
|
||||||
message = "Bluetooth activated"
|
message = "Bluetooth activated"
|
||||||
})
|
})
|
||||||
@@ -114,7 +114,7 @@ return function()
|
|||||||
]],
|
]],
|
||||||
function()
|
function()
|
||||||
naughty.notify({
|
naughty.notify({
|
||||||
Title = "System Notification",
|
title = "System Notification",
|
||||||
app_name = "Bluetooth",
|
app_name = "Bluetooth",
|
||||||
message = "Bluetooth deactivated"
|
message = "Bluetooth deactivated"
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user