removing somethings
This commit is contained in:
1 parent
dc78c0c2de
commit
928303bc10
30 files changed
+113
-313
No files matched your search
@@ -1,8 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Prasanthrangan Work
|
||||
|
||||
trap resume_processes SIGINT
|
||||
in_range() { local num=$1 local min=$2 local max=$3 ; [[ $num =~ ^[0-9]+$ ]] && (( num >= min && num <= max )); }
|
||||
mnc=5 mxc=80 mnl=20 mxl=50 mnu=80 mxu=100 mnt=60 mxt=1000 mnf=80 mxf=100 mnn=1 mxn=60 mni=1 mxi=10 verbose=false undock=false #Defaults Ranges
|
||||
while (( "$#" )); do # Parse command-line arguments and defaults
|
||||
while (( "$#" )); do # Parse command-line arguments and defaults
|
||||
case "$1" in
|
||||
"--full"|"-f") if in_range "$2" $mnf $mxf; then battery_full_threshold=$2 ; shift 2 ; else echo "$1 Error: Full Threshold must be $mnf - $mxf." >&2 ; exit 1 ; fi;;
|
||||
"--critical"|"-c") if in_range "$2" $mnc $mxc; then battery_critical_threshold=$2 ; shift 2 ; else echo "$1 ERROR: Critical Threshold must be $mnc - $mxc." >&2 ; exit 1 ; fi;;
|
||||
@@ -42,11 +45,11 @@ is_laptop() { # Check if the system is a laptop
|
||||
fi
|
||||
}
|
||||
fn_verbose () {
|
||||
if $verbose; then
|
||||
if $verbose; then
|
||||
cat << VERBOSE
|
||||
=============================================
|
||||
Battery Status: $battery_status
|
||||
Battery Percentage: $battery_percentage
|
||||
Battery Status: $battery_status
|
||||
Battery Percentage: $battery_percentage
|
||||
=============================================
|
||||
|
||||
|
||||
@@ -57,7 +60,7 @@ fn_notify () { # Send notification
|
||||
|
||||
notify-send -a "Power" $1 -u $2 "$3" "$4" -p # Call the notify-send command with the provided arguments \$1 is the flags \$2 is the urgency \$3 is the title \$4 is the message
|
||||
}
|
||||
fn_percentage () {
|
||||
fn_percentage () {
|
||||
if [[ "$battery_percentage" -ge "$unplug_charger_threshold" ]] && [[ "$battery_status" != "Discharging" ]] && [[ "$battery_status" != "Full" ]] && (( (battery_percentage - last_notified_percentage) >= $interval )); then if $verbose; then echo "Prompt:UNPLUG: $battery_unplug_threshold $battery_status $battery_percentage" ; fi
|
||||
fn_notify "-t 5000 " "CRITICAL" "Battery Charged" "Battery is at $battery_percentage%. You can unplug the charger!"
|
||||
last_notified_percentage=$battery_percentage
|
||||
@@ -68,7 +71,7 @@ fn_percentage () {
|
||||
if [[ $battery_status != "Discharging" ]] ; then break ; fi
|
||||
fn_notify "-t 5000 -r 69 " "CRITICAL" "Battery Critically Low" "$battery_percentage% is critically low. Device will execute $execute in $((count/60)):$((count%60)) ."
|
||||
count=$((count-1))
|
||||
sleep 1
|
||||
sleep 1
|
||||
done
|
||||
[ $count -eq 0 ] && fn_action
|
||||
elif [[ "$battery_percentage" -le "$battery_low_threshold" ]] && [[ "$battery_status" == "Discharging" ]] && (( (last_notified_percentage - battery_percentage) >= $interval )); then if $verbose; then echo "Prompt:LOW: $battery_low_threshold $battery_status $battery_percentage" ; fi
|
||||
@@ -86,18 +89,18 @@ if [[ $battery_percentage -ge $battery_full_threshold ]] && [ "$battery_status"
|
||||
battery_status="Full" ;fi
|
||||
case "$battery_status" in # Handle the power supply status
|
||||
"Discharging") if $verbose; then echo "Case:$battery_status Level: $battery_percentage" ;fi
|
||||
if [[ "$prev_status" != "Discharging" ]] || [[ "$prev_status" == "Full" ]] ; then
|
||||
if [[ "$prev_status" != "Discharging" ]] || [[ "$prev_status" == "Full" ]] ; then
|
||||
prev_status=$battery_status
|
||||
urgency=$([[ $battery_percentage -le "$battery_low_threshold" ]] && echo "CRITICAL" || echo "NORMAL")
|
||||
fn_notify "-t 5000 -r 54321 " "$urgency" "Charger Plug OUT" "Battery is at $battery_percentage%."
|
||||
fi
|
||||
fn_percentage
|
||||
fn_percentage
|
||||
;;
|
||||
"Not"*|"Charging") if $verbose; then echo "Case:$battery_status Level: $battery_percentage" ;fi
|
||||
# Due to modifications of some devices Not Charging after reaching 99 or limits
|
||||
#if [[ ! -f "/tmp/hyprdots.batterynotify.status.$battery_status-$$" ]] && [[ "$battery_status" == "Not"* ]] ; then
|
||||
#if [[ ! -f "/tmp/hyprdots.batterynotify.status.$battery_status-$$" ]] && [[ "$battery_status" == "Not"* ]] ; then
|
||||
#touch "/tmp/hyprdots.batterynotify.status.$battery_status-$$"
|
||||
#count=$(( timer > $mnt ? timer : $mnt )) # reset count
|
||||
#count=$(( timer > $mnt ? timer : $mnt )) # reset count
|
||||
#echo "Status: '==>> "$battery_status" <<==' Device Reports Not Charging!,This may be device Specific errors."
|
||||
#fn_notify "-t 5000 " "CRITICAL" "Charger Plug In" "Battery is at $battery_percentage%."
|
||||
#fi
|
||||
@@ -107,24 +110,24 @@ case "$battery_status" in # Handle the power supply status
|
||||
urgency=$([[ "$battery_percentage" -ge $unplug_charger_threshold ]] && echo "CRITICAL" || echo "NORMAL")
|
||||
fn_notify "-t 5000 -r 54321 " "$urgency" "Charger Plug In" "Battery is at $battery_percentage%."
|
||||
fi
|
||||
fn_percentage
|
||||
fn_percentage
|
||||
;;
|
||||
"Full") if $verbose; then echo "Case:$battery_status Level: $battery_percentage" ;fi
|
||||
|
||||
if [[ $battery_status != "Discharging" ]]; then
|
||||
now=$(date +%s)
|
||||
now=$(date +%s)
|
||||
if [[ "$prev_status" == *"harging"* ]] || ((now - lt >= $((notify*60)) )); then
|
||||
fn_notify "-t 5000 -r 54321" "CRITICAL" "Battery Full" "Please unplug your Charger"
|
||||
prev_status=$battery_status lt=$now
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
;;
|
||||
*)
|
||||
if [[ ! -f "/tmp/hyprdots.batterynotify.status.fallback.$battery_status-$$" ]]; then
|
||||
if [[ ! -f "/tmp/hyprdots.batterynotify.status.fallback.$battery_status-$$" ]]; then
|
||||
echo "Status: '==>> "$battery_status" <<==' Script on Fallback mode,Unknown power supply status.Please copy this line and raise an issue to the Github Repo.Also run 'ls /tmp/hyprdots.batterynotify' to see the list of lock files.*"
|
||||
touch "/tmp/hyprdots.batterynotify.status.fallback.$battery_status-$$"
|
||||
fi
|
||||
fn_percentage
|
||||
fi
|
||||
fn_percentage
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -142,8 +145,8 @@ resume_processes() { for pid in $pids ; do if [ $pid -ne $current_pid ] ; then
|
||||
main() { # Main function
|
||||
if is_laptop; then
|
||||
rm -fr /tmp/hyprdots.batterynotify* # Cleaning the lock file
|
||||
battery_full_threshold=${battery_full_threshold:-100}
|
||||
battery_critical_threshold=${battery_critical_threshold:-10}
|
||||
battery_full_threshold=${battery_full_threshold:-100}
|
||||
battery_critical_threshold=${battery_critical_threshold:-10}
|
||||
unplug_charger_threshold=${unplug_charger_threshold:-80}
|
||||
battery_low_threshold=${battery_low_threshold:-20}
|
||||
timer=${timer:-120}
|
||||
@@ -152,11 +155,11 @@ interval=${interval:-5}
|
||||
|
||||
execute=${execute:-"systemctl suspend"}
|
||||
cat << EOF
|
||||
Script is running...
|
||||
Check $0 --help for options.
|
||||
Script is running...
|
||||
Check $0 --help for options.
|
||||
|
||||
STATUS THRESHOLD INTERVAL
|
||||
Full $battery_full_threshold $notify Minutes
|
||||
Full $battery_full_threshold $notify Minutes
|
||||
Critical $battery_critical_threshold $timer Seconds then "$execute"
|
||||
Low $battery_low_threshold $interval Percent
|
||||
Unplug $unplug_charger_threshold $interval Percent
|
||||
|
||||
Reference in new issue
Block a user