Comments (3)
@xiaoshihou514 i think @ehula is referring to the battery percentage of connected bluetooth device not the laptop battery.
from rofi-bluetooth.
Here was my solution if any else is interested:
Updated device_menu
including battery percentage:
device_menu() {
device=$1
# Get device name, mac address, and battery percentage
device_name=$(echo "$device" | cut -d ' ' -f 3-)
mac=$(echo "$device" | cut -d ' ' -f 2)
# BATTERY % VARS
battery_info=$(bluetoothctl info "$mac" | grep "Battery" | cut -d ' ' -f 2-)
battery_percentage=$(echo "$battery_info" | grep -oP '\(\K[^)]+')
# Build options
if device_connected "$mac"; then
connected="Connected: yes"
else
connected="Connected: no"
fi
paired=$(device_paired "$mac")
trusted=$(device_trusted "$mac")
# UPDATED OPTIONS
options="$connected\n$paired\n$trusted\nBattery: $battery_percentage%\n$divider\n$goback\nExit"
# Open rofi menu, read chosen option
chosen="$(echo -e "$options" | $rofi_command "$device_name")"
# Match chosen option to command
case "$chosen" in
"" | "$divider")
echo "No option chosen."
;;
"$connected")
toggle_connection "$mac"
;;
"$paired")
toggle_paired "$mac"
;;
"$trusted")
toggle_trust "$mac"
;;
"$goback")
show_menu
;;
esac
}
Updated print_status
for polybar:
print_status() {
if power_on; then
printf ''
paired_devices_cmd="devices Paired"
# Check if an outdated version of bluetoothctl is used to preserve backwards compatibility
if (( $(echo "$(bluetoothctl version | cut -d ' ' -f 2) < 5.65" | bc -l) )); then
paired_devices_cmd="paired-devices"
fi
mapfile -t paired_devices < <(bluetoothctl $paired_devices_cmd | grep Device | cut -d ' ' -f 2)
counter=0
for device in "${paired_devices[@]}"; do
if device_connected "$device"; then
device_alias=$(bluetoothctl info "$device" | grep "Alias" | cut -d ' ' -f 2-)
# BATTERY % VARS
battery_info=$(bluetoothctl info "$device" | grep "Battery" | cut -d ' ' -f 2-)
battery_percentage=$(echo "$battery_info" | grep -oP '\(\K[^)]+')
# UPDATED PRINT
if [ $counter -gt 0 ]; then
printf ", %s" "$device_alias ($battery_percentage%)"
else
printf " %s" "$device_alias ($battery_percentage%)"
fi
((counter++))
fi
done
printf "\n"
else
echo ""
fi
}
from rofi-bluetooth.
Thanks for this, works a treat.
Perhaps this could be merged?
from rofi-bluetooth.
Related Issues (14)
- Arch Linux HOT 4
- Polybar module toggles continuously when one bluetooth device is connected HOT 1
- Unable to customize the font in "rofi_command" HOT 1
- '$1: unbound variable' in the line 'case "$1" in'
- Feature Request: Case Insensitivity HOT 3
- bluetooth label not printing in polybar
- Tagged Releases
- rofi-bluetooth doesn't work with Sway and Rofi (lbonn fork) HOT 2
- Unable to apply theme with config
- cannot install with `paru` from the AUR
- Menu exits after each state-change HOT 3
- Bluetooth menu constantly reopens at startup HOT 1
- Should rofi-bluetooth accept a -theme arg and set it on rofi_command? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rofi-bluetooth.