Skip to content

Commit

Permalink
Merge pull request #23 from stablestud/master
Browse files Browse the repository at this point in the history
Merging back my fork with improvements
  • Loading branch information
rjekker authored Aug 31, 2023
2 parents f4eee91 + 781cad7 commit da5bcef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ Specify `-n` to use those nice pretty desktop notifications in the top right cor

## Options

- `-L` sets the percentage at which the first popup shows. Default is 10
- `-l` : The percentage at which the second popup shows. Default: half of the percentage given by `-L`
- `-L` : Sets the percentage at which the first popup shows. Default is `10%`
- `-l` : The percentage at which the second popup shows. Default: half of the percentage given by `-L`, not compatible with `-I`
- `-I` : Specify on how many battery % change to re-send message,
Note: the check is run every `-t` (default `5m`) so at minimum we will wait `5m` before sending any new message, set `-t` lower for more precise interval notifications.
Disables the `-l` parameter
Example: `-I 2%` will send notfication every 2% battery change after `-L` was hit. Default: disabled

- `-m` : The message to show to the User
- `-m` : The message to show to the user
Default: `Warning: Battery is getting low`

- `-t` : The time interval the script waits before checking the battery again.
Give this a value in seconds: `10s`, or in minutes: `5m`.
Expand All @@ -51,6 +56,9 @@ Specify `-n` to use those nice pretty desktop notifications in the top right cor
- `-i` : Specify the icon to use with `-n`

- `-N` : Don't use Tcl/Tk dialog. Use i3-nagbar.
- `-f` : Font to use for i3-nagbar
Fonts are specified same as in i3 (https://i3wm.org/docs/userguide.html#fonts)
For example: `pango:DejaVu Sans Mono 10`

- `-s` : Play a sound with `paplay` when notifying.
Takes a path to a sound as argument. The file must exist.
Expand All @@ -59,3 +67,6 @@ Specify `-n` to use those nice pretty desktop notifications in the top right cor
- `-v` : Specifies the percentage of the volume of the sound played with `-s` option.
This value must be an integer greater than `0` and smaller than `100`.
Default: `100`

- `-D` : Enable debug output
- `-F` : Specifies the logfile to write to
33 changes: 22 additions & 11 deletions i3-battery-popup
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
# -l : The percentage at which the second popup shows #
# Default: half of the percentage given by -L #
# #
# -I : Interval that the notification will appear on every % battery change #
# i.E.: interval of 2 means on every 2% change send a notification #
# Disables the -l parameter #
# #
# -m : The message to show to the User #
# #
# -t : The time interval the script waits before checking the battery again. #
Expand All @@ -34,9 +38,11 @@
# -n : Use notify-send for message. #
# #
# -N : Don't use Tcl/Tk dialog. Use i3-nagbar. #
# -f : Font to use for i3-nagbar (e.g.: pango:Dejavu Sans Mono 10) #
# #
# -D : Enable debug output #
# #
# -I : Interval that the notification will appear #
# Overrides the -l parameter #
# -F : Specifies the logfile to write output to #
# #
# By R-J Ekker, 2016 #
# Thanks to: #
Expand All @@ -50,15 +56,15 @@ error () {
exit "$2"
}

while getopts 's:v:L:l:m:t:s:F:i:I:nND' opt; do
while getopts 's:v:L:l:m:t:s:F:i:I:f:nND' opt; do
case $opt in
L)
[[ $OPTARG =~ ^[0-9]+$ ]] || error "${opt}: ${OPTARG} is not a number" 2
UPPER_LIMIT="${OPTARG}"
[[ $OPTARG =~ ^[0-9]+%?$ ]] || error "${opt}: ${OPTARG} is not a number" 2
UPPER_LIMIT="${OPTARG%\%}"
;;
l)
[[ $OPTARG =~ ^[0-9]+$ ]] || error "${opt}: ${OPTARG} is not a number" 2
LOWER_LIMIT="${OPTARG}"
[[ $OPTARG =~ ^[0-9]+%?$ ]] || error "${opt}: ${OPTARG} is not a number" 2
LOWER_LIMIT="${OPTARG%\%}"
;;
m)
MESSAGE="${OPTARG}"
Expand All @@ -70,7 +76,8 @@ while getopts 's:v:L:l:m:t:s:F:i:I:nND' opt; do
NOTIFY_ICON="${OPTARG}"
;;
I)
INTERVAL="${OPTARG}"
[[ $OPTARG =~ ^[0-9]+%?$ ]] || error "${opt}: ${OPTARG} is not a number" 2
INTERVAL="${OPTARG%\%}"
;;
N)
DONT_USE_WISH="-n"
Expand All @@ -97,6 +104,9 @@ while getopts 's:v:L:l:m:t:s:F:i:I:nND' opt; do
# if -D not specified this will log nothing
LOGFILE="${OPTARG}"
;;
f)
FONT="${OPTARG}"
;;
:)
error "Option -$OPTARG requires an argument." 2
;;
Expand Down Expand Up @@ -147,7 +157,7 @@ show_popup() {
}

show_nagbar(){
i3-msg "exec i3-nagbar -m \"${1}\""
i3-msg "exec i3-nagbar -m \"${1}\" ${FONT:+-f "'${FONT}'"}"
}

show_notify(){
Expand All @@ -162,6 +172,7 @@ show_notify(){
fi
fi
[[ -n $NOTIFY_ICON ]] && NOTIFY_OPT="-i ${NOTIFY_ICON}"
# shellcheck disable=SC2086
notify-send -u critical "${1}" ${NOTIFY_OPT}
}

Expand Down Expand Up @@ -229,13 +240,13 @@ main (){
LIMIT=0
fi
else
LIMIT=$[$PERC - $INTERVAL]
LIMIT=$(( PERC - INTERVAL ))
fi
fi
else
# restart messages, reset limits
POPUP_CLICKED=""
if [[ $PERC -gt $UPPER_LIMIT ]] || ! [[ -z $INTERVAL ]]; then
if [[ $PERC -gt $UPPER_LIMIT ]] || [[ -n $INTERVAL ]]; then
LIMIT=${UPPER_LIMIT}
else
LIMIT=${LOWER_LIMIT}
Expand Down

0 comments on commit da5bcef

Please sign in to comment.