From f04f9113d7a5d1f8a97ce1f685a37cc3c0a0bdca Mon Sep 17 00:00:00 2001 From: Rene Date: Sun, 30 Jun 2024 10:10:17 +0200 Subject: [PATCH] fix whitespaces --- battery.sh | 104 ++++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/battery.sh b/battery.sh index 1972865..21da5bd 100755 --- a/battery.sh +++ b/battery.sh @@ -469,7 +469,7 @@ if [[ "$action" == "charge" ]]; then if [[ "$battery_percentage" -ge "$((setting - 3))" ]]; then sleep 20 else - caffeinate -is sleep 60 + caffeinate -is sleep 60 fi done @@ -565,7 +565,7 @@ if [[ "$action" == "maintain_synchronous" ]]; then log "Charge above $setting" if [[ "$is_charging" == "enabled" ]]; then - disable_charging + disable_charging fi change_magsafe_led_color "green" @@ -590,22 +590,22 @@ fi # Maintain at voltage if [[ "$action" == "maintain_voltage_synchronous" ]]; then - # Recover old maintain status if old setting is found - if [[ "$setting" == "recover" ]]; then + # Recover old maintain status if old setting is found + if [[ "$setting" == "recover" ]]; then - # Before doing anything, log out environment details as a debugging trail - log "Debug trail. User: $USER, config folder: $configfolder, logfile: $logfile, file called with 1: $1, 2: $2" + # Before doing anything, log out environment details as a debugging trail + log "Debug trail. User: $USER, config folder: $configfolder, logfile: $logfile, file called with 1: $1, 2: $2" - maintain_voltage=$(cat $maintain_voltage_tracker_file 2>/dev/null) - if [[ $maintain_voltage ]]; then - log "Recovering maintenance voltage $maintain_voltage" - setting=$(echo $maintain_voltage | awk '{print $1}') - subsetting=$(echo $maintain_voltage | awk '{print $2}') - else - log "No setting to recover, exiting" - exit 0 - fi - fi + maintain_voltage=$(cat $maintain_voltage_tracker_file 2>/dev/null) + if [[ $maintain_voltage ]]; then + log "Recovering maintenance voltage $maintain_voltage" + setting=$(echo $maintain_voltage | awk '{print $1}') + subsetting=$(echo $maintain_voltage | awk '{print $2}') + else + log "No setting to recover, exiting" + exit 0 + fi + fi voltage=$(get_voltage) lower_voltage=$(echo "$setting - $subsetting" | bc -l) @@ -617,11 +617,11 @@ if [[ "$action" == "maintain_voltage_synchronous" ]]; then is_charging=$(get_smc_charging_status) if (($(echo "$voltage < $lower_voltage" | bc -l))) && [[ "$is_charging" == "disabled" ]]; then - log "Battery at ${voltage}V" + log "Battery at ${voltage}V" enable_charging fi if (($(echo "$voltage >= $upper_voltage" | bc -l))) && [[ "$is_charging" == "enabled" ]]; then - log "Battery at ${voltage}V" + log "Battery at ${voltage}V" disable_charging fi @@ -658,27 +658,27 @@ if [[ "$action" == "maintain" ]]; then exit 0 fi - # Check if setting is a voltage - is_voltage=false - if valid_voltage "$setting"; then + # Check if setting is a voltage + is_voltage=false + if valid_voltage "$setting"; then setting="${setting//V/}" - if valid_voltage "$subsetting"; then + if valid_voltage "$subsetting"; then subsetting="${subsetting//V/}" - else - subsetting="0.1" - fi + else + subsetting="0.1" + fi if (($(echo "$setting < $voltage_min" | bc -l) || $(echo "$setting > $voltage_max" | bc -l))); then - log "Error: ${setting}V is not a valid setting. Please use a value between ${voltage_min}V and ${voltage_max}V" - exit 1 - fi + log "Error: ${setting}V is not a valid setting. Please use a value between ${voltage_min}V and ${voltage_max}V" + exit 1 + fi if (($(echo "$subsetting < $voltage_hyst_min" | bc -l) || $(echo "$subsetting > $voltage_max" | bc -l))); then - log "Error: ${subsetting}V is not a valid setting. Please use a value between ${voltage_hyst_min}V and ${voltage_hyst_max}V" - exit 1 - fi + log "Error: ${subsetting}V is not a valid setting. Please use a value between ${voltage_hyst_min}V and ${voltage_hyst_max}V" + exit 1 + fi - is_voltage=true + is_voltage=true # Check if setting is value between 0 and 100 elif ! valid_percentage "$setting"; then @@ -693,11 +693,11 @@ if [[ "$action" == "maintain" ]]; then # Start maintenance script if [ "$is_voltage" = true ]; then - log "Starting battery maintenance at ${setting}V ±${subsetting}V" - nohup $battery_binary maintain_voltage_synchronous $setting $subsetting >>$logfile & + log "Starting battery maintenance at ${setting}V ±${subsetting}V" + nohup $battery_binary maintain_voltage_synchronous $setting $subsetting >>$logfile & else - log "Starting battery maintenance at $setting% $subsetting" - nohup $battery_binary maintain_synchronous $setting $subsetting >>$logfile & + log "Starting battery maintenance at $setting% $subsetting" + nohup $battery_binary maintain_synchronous $setting $subsetting >>$logfile & fi # Store pid of maintenance process and setting @@ -708,16 +708,16 @@ if [[ "$action" == "maintain" ]]; then rm "$maintain_percentage_tracker_file" "$maintain_voltage_tracker_file" 2>/dev/null - if [[ "$is_voltage" = true ]]; then - log "Writing new setting $setting $subsetting to $maintain_voltage_tracker_file" - echo "$setting $subsetting" >$maintain_voltage_tracker_file - log "Maintaining battery at ${setting}V ±${subsetting}V" + if [[ "$is_voltage" = true ]]; then + log "Writing new setting $setting $subsetting to $maintain_voltage_tracker_file" + echo "$setting $subsetting" >$maintain_voltage_tracker_file + log "Maintaining battery at ${setting}V ±${subsetting}V" - else - log "Writing new setting $setting to $maintain_percentage_tracker_file" - echo $setting >$maintain_percentage_tracker_file - log "Maintaining battery at $setting%" - fi + else + log "Writing new setting $setting to $maintain_percentage_tracker_file" + echo $setting >$maintain_percentage_tracker_file + log "Maintaining battery at $setting%" + fi fi @@ -793,10 +793,10 @@ if [[ "$action" == "status" ]]; then if test -f $pidfile; then maintain_percentage=$(cat $maintain_percentage_tracker_file 2>/dev/null) if [[ $maintain_percentage ]]; then - maintain_level="$maintain_percentage%" + maintain_level="$maintain_percentage%" else - maintain_level=$(cat $maintain_voltage_tracker_file 2>/dev/null) - maintain_level=$(echo "$maintain_level" | awk '{print $1 "V ±" $2 "V"}') + maintain_level=$(cat $maintain_voltage_tracker_file 2>/dev/null) + maintain_level=$(echo "$maintain_level" | awk '{print $1 "V ±" $2 "V"}') fi log "Your battery is currently being maintained at $maintain_level" fi @@ -814,10 +814,10 @@ fi # launchd daemon creator, inspiration: https://www.launchd.info/ if [[ "$action" == "create_daemon" ]]; then - call_action="maintain_synchronous" - if test -f "$maintain_voltage_tracker_file"; then - call_action="maintain_voltage_synchronous" - fi + call_action="maintain_synchronous" + if test -f "$maintain_voltage_tracker_file"; then + call_action="maintain_voltage_synchronous" + fi daemon_definition="