Further polybar customization
This commit is contained in:
59
config/.config/polybar/scripts/bluetooth.sh
Executable file
59
config/.config/polybar/scripts/bluetooth.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
|
||||
bluetooth_print() {
|
||||
if bluetoothctl show | grep -q "Powered: yes"; then
|
||||
printf ''
|
||||
|
||||
devices_paired=$(bluetoothctl paired-devices | grep Device | cut -d ' ' -f 2)
|
||||
counter=0
|
||||
|
||||
for device in $devices_paired; do
|
||||
device_info=$(bluetoothctl info "$device")
|
||||
|
||||
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
|
||||
|
||||
printf '\n'
|
||||
else
|
||||
# ""
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
bluetooth_toggle() {
|
||||
if bluetoothctl show | grep -q "Powered: no"; then
|
||||
bluetoothctl power on >> /dev/null
|
||||
sleep 1
|
||||
|
||||
devices_paired=$(bluetoothctl paired-devices | grep Device | cut -d ' ' -f 2)
|
||||
echo "$devices_paired" | while read -r line; do
|
||||
bluetoothctl connect "$line" >> /dev/null
|
||||
done
|
||||
else
|
||||
devices_paired=$(bluetoothctl devices Paired | grep Device | cut -d ' ' -f 2)
|
||||
echo "$devices_paired" | while read -r line; do
|
||||
bluetoothctl disconnect "$line" >> /dev/null
|
||||
done
|
||||
|
||||
bluetoothctl power off >> /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
--toggle)
|
||||
bluetooth_toggle
|
||||
;;
|
||||
*)
|
||||
bluetooth_print
|
||||
;;
|
||||
esac
|
||||
20
config/.config/polybar/scripts/spotify.sh
Executable file
20
config/.config/polybar/scripts/spotify.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
main() {
|
||||
pgrep spotify -l | grep -v spotify.sh > /dev/null || return
|
||||
|
||||
cmd="org.freedesktop.DBus.Properties.Get"
|
||||
domain="org.mpris.MediaPlayer2"
|
||||
path="/org/mpris/MediaPlayer2"
|
||||
|
||||
meta=$(dbus-send --print-reply --dest=${domain}.spotify /org/mpris/MediaPlayer2 ${cmd} string:${domain}.Player string:Metadata)
|
||||
|
||||
# Normal track
|
||||
artist=$(echo "$meta" | sed -nr '/xesam:artist"/,+2s/^ +string "(.*)"$/\1/p' | tail -1 | sed 's/\&/\\&/g' | sed 's#\/#\\/#g')
|
||||
album=$(echo "$meta" | sed -nr '/xesam:album"/,+2s/^ +variant +string "(.*)"$/\1/p' | tail -1| sed 's/\&/\\&/g'| sed 's#\/#\\/#g')
|
||||
title=$(echo "$meta" | sed -nr '/xesam:title"/,+2s/^ +variant +string "(.*)"$/\1/p' | tail -1 | sed 's/\&/\\&/g'| sed 's#\/#\\/#g')
|
||||
|
||||
echo "阮 ${*:-%artist% - %title%}" | sed "s/%artist%/$artist/g;s/%title%/$title/g;s/%album%/$album/g"i | sed "s/\&/\&/g" | sed "s#\/#\/#g"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user