Game controler battery status script added. This works with PS4 controlers by default, and probably other batteries if you set the path in the script itself.
This commit is contained in:
parent
176bb60292
commit
93b7a1d835
2
i38.sh
2
i38.sh
@ -373,6 +373,7 @@ bindsym e exec $textEditor, mode "default"
|
|||||||
bindsym f exec $fileBrowser, mode "default"
|
bindsym f exec $fileBrowser, mode "default"
|
||||||
# Web browser bound to w
|
# Web browser bound to w
|
||||||
bindsym w exec $webBrowser, mode "default"
|
bindsym w exec $webBrowser, mode "default"
|
||||||
|
bindsym g exec ${i3Path}/scripts/game_controler.sh -s, mode "default"
|
||||||
$(if command -v mumble &> /dev/null ; then
|
$(if command -v mumble &> /dev/null ; then
|
||||||
echo "bindsym m exec $(command -v mumble), mode \"default\""
|
echo "bindsym m exec $(command -v mumble), mode \"default\""
|
||||||
fi)
|
fi)
|
||||||
@ -425,6 +426,7 @@ bindsym \$mod+e exec $textEditor
|
|||||||
bindsym \$mod+f exec $fileBrowser
|
bindsym \$mod+f exec $fileBrowser
|
||||||
# Web browser bound to $mod+w
|
# Web browser bound to $mod+w
|
||||||
bindsym \$mod+w exec $webBrowser
|
bindsym \$mod+w exec $webBrowser
|
||||||
|
bindsym \$mod+g exec ${i3Path}/scripts/game_controler.sh -s, mode "default"
|
||||||
$(if command -v mumble &> /dev/null ; then
|
$(if command -v mumble &> /dev/null ; then
|
||||||
echo "bindsym \$mod+m exec $(command -v mumble)"
|
echo "bindsym \$mod+m exec $(command -v mumble)"
|
||||||
fi)
|
fi)
|
||||||
|
53
scripts/game_controler.sh
Executable file
53
scripts/game_controler.sh
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Add this to your crontab to have battery status automatically reported when it starts getting low
|
||||||
|
# */10 * * * * XDG_RUNTIME_DIR=/run/user/1000 /home/user/.config/i3/scripts/game_controler.sh
|
||||||
|
|
||||||
|
# Set the name to your battery here.
|
||||||
|
# If not set, it will be automatically detected.
|
||||||
|
batteryName=""
|
||||||
|
|
||||||
|
if [[ "$batteryName" == "" ]]; then
|
||||||
|
batteryName="$(find /sys/class/power_supply -name 'sony_controller_battery_*' | cut -d/ -f5)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If there's no file, we don't check it.
|
||||||
|
if [[ ! -f "/sys/class/power_supply/${batteryName}/capacity" ]]; then
|
||||||
|
spd-say -P important -Cw "Battery not found."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
oldPercent="$(tail -1 "$0" | tr -cd '[:digit:]')"
|
||||||
|
oldPercent="${oldPercent:-0}"
|
||||||
|
|
||||||
|
percent=$(cat "/sys/class/power_supply/${batteryName}/capacity" | tr -cd '[:digit:]')
|
||||||
|
status="$(cat "/sys/class/power_supply/${batteryName}/status")"
|
||||||
|
|
||||||
|
# If status is requested, give it and exit.
|
||||||
|
if [[ "$1" == "-s" || "$1" == "--status" ]]; then
|
||||||
|
spd-say -P important -Cw "Battery ${percent} percent, ${status,,}."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $percent -ne $oldPercent && $percent -gt 10 ]]; then
|
||||||
|
spd-say "Battery $(</sys/class/power_supply/${batteryName}/capacity) percent."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $percent -le 10 ]]; then
|
||||||
|
spd-say "Battery $(</sys/class/power_supply/${batteryName}/capacity) percent."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$status" == "Full" ]]; then
|
||||||
|
spd-say "Battery $(</sys/class/power_supply/${batteryName}/capacity) percent, ${status,,}."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# remove the last line of the file and update it with the new percentage.
|
||||||
|
lastLine="$(grep -n '^exit 0' $0)"
|
||||||
|
# Convert lastLine to a number andd increment it by 1.
|
||||||
|
lastLine=${lastLine%%:*}
|
||||||
|
lastLine=$((lastLine + 1))
|
||||||
|
sed -i "${lastLine}"',$d' $0
|
||||||
|
echo "$percent" >> "$0"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
50
|
Loading…
Reference in New Issue
Block a user