added bluetooth module; replaced bars with ramps
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
## config
|
||||
|
||||
@@ -10,18 +10,20 @@ low=20
|
||||
red='%{F#f00}'
|
||||
green='%{F#0f0}'
|
||||
end='%{F-}'
|
||||
# hack to put a little space between the lightning and the percentage
|
||||
smallspace='%{T4} %{T-}'
|
||||
|
||||
bat="$(cat /sys/class/power_supply/BAT0/capacity)"
|
||||
ac="$(cat /sys/class/power_supply/AC/online)"
|
||||
declare -a ramp
|
||||
ramp=( )
|
||||
|
||||
# display in red when under $low and no charger is connected
|
||||
[ "$bat" -gt "$low" ] || [ "$ac" -eq 1 ] || color="$red"
|
||||
# display in green when over $full and a charger is connected
|
||||
[ "$bat" -lt "$full" ] || [ "$ac" -eq 0 ] || color="$green"
|
||||
|
||||
prefix=" "
|
||||
[ "$ac" -eq 0 ] || prefix="⚡"
|
||||
let "icon_index = $bat / (${#ramp[@]} - 1)"
|
||||
[ $icon_index -lt ${#ramp[@]} ] || icond_index=10
|
||||
icon="${ramp[$icon_index]}"
|
||||
[ "$ac" -eq 0 ] || charge=""
|
||||
|
||||
echo "${color}${prefix}${smallspace}${bat}%"
|
||||
echo "${color}${icon}${charge} ${bat}%"
|
||||
|
||||
68
.config/polybar/scripts/bluetooth.sh
Executable file
68
.config/polybar/scripts/bluetooth.sh
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
# See https://github.com/polybar/polybar-scripts/pull/237
|
||||
|
||||
bluetooth_print() {
|
||||
bluetoothctl | while read -r; do
|
||||
if [ "$(systemctl is-active "bluetooth.service")" = "active" ]; then
|
||||
|
||||
devices_paired=$(echo paired-devices | bluetoothctl | sed -n '/paired-devices/,$p' | grep Device | cut -d ' ' -f 2)
|
||||
counter=0
|
||||
|
||||
echo "$devices_paired" | while read -r line; do
|
||||
device_info=$(echo "info $line" | bluetoothctl)
|
||||
|
||||
if echo "$device_info" | grep -q "Connected: yes"; then
|
||||
device_alias=$(echo "$device_info" | grep "Alias" | cut -d ' ' -f 2-)
|
||||
|
||||
if [ $counter -gt 0 ]; then
|
||||
printf ", %s" "$device_alias"
|
||||
else
|
||||
printf ": %s" "$device_alias"
|
||||
fi
|
||||
|
||||
counter=$((counter + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
if echo show | bluetoothctl | grep -q "Powered: no"; then
|
||||
printf ''
|
||||
fi
|
||||
printf '\n'
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
bluetooth_toggle() {
|
||||
if echo show | bluetoothctl | grep -q "Powered: no"; then
|
||||
echo "power on" | bluetoothctl >> /dev/null
|
||||
sleep 1
|
||||
|
||||
devices_paired=$(echo paired-devices | bluetoothctl | sed -n '/paired-devices/,$p' | grep Device | cut -d ' ' -f 2)
|
||||
echo "$devices_paired" | while read -r line; do
|
||||
echo "connect $line" | bluetoothctl >> /dev/null
|
||||
done
|
||||
else
|
||||
devices_paired=$(echo paired-devices | bluetoothctl | sed -n '/paired-devices/,$p' | grep Device | cut -d ' ' -f 2)
|
||||
echo "$devices_paired" | while read -r line; do
|
||||
device_info=$(echo "info $line" | bluetoothctl)
|
||||
|
||||
if echo "$device_info" | grep -q "Connected: yes"; then
|
||||
echo "disconnect $line" | bluetoothctl >> /dev/null
|
||||
fi
|
||||
done
|
||||
|
||||
echo "power off" | bluetoothctl >> /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
--toggle)
|
||||
bluetooth_toggle
|
||||
;;
|
||||
*)
|
||||
bluetooth_print
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user