mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
BatteryService: add -q option to supress notifications
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SUPPRESS_NOTIFICATIONS=false
|
||||
|
||||
print_error() {
|
||||
echo -e "$1" >&2
|
||||
@@ -15,25 +16,47 @@ send_notification() {
|
||||
local title="$2"
|
||||
local message="$3"
|
||||
|
||||
if command -v notify-send >/dev/null 2>&1; then
|
||||
if [ "$SUPPRESS_NOTIFICATIONS" = false ] && command -v notify-send >/dev/null 2>&1; then
|
||||
notify-send -u "$urgency" "$title" "$message"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$#" -ne 1 ]; then
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-q|--quiet)
|
||||
SUPPRESS_NOTIFICATIONS=true
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
print_error "Unknown option: $1"
|
||||
echo "Usage: $0 [OPTIONS] <number>" >&2
|
||||
echo "Options:" >&2
|
||||
echo " -q, --quiet Suppress notifications" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
BATTERY_LEVEL="$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$BATTERY_LEVEL" ]; then
|
||||
print_error "Battery level not specified"
|
||||
echo "Usage: $0 <number>" >&2
|
||||
echo "Usage: $0 [OPTIONS] <number>" >&2
|
||||
echo "Options:" >&2
|
||||
echo " -q, --quiet Suppress notifications" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [[ "$1" =~ ^[0-9]+$ ]] || [ "$1" -gt 100 ] || [ "$1" -lt 0 ]; then
|
||||
if ! [[ "$BATTERY_LEVEL" =~ ^[0-9]+$ ]] || [ "$BATTERY_LEVEL" -gt 100 ] || [ "$BATTERY_LEVEL" -lt 0 ]; then
|
||||
print_error "Battery level must be a number between 0-100"
|
||||
echo "Usage: $0 <number>" >&2
|
||||
echo "Usage: $0 [OPTIONS] <number>" >&2
|
||||
echo "Options:" >&2
|
||||
echo " -q, --quiet Suppress notifications" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BATTERY_LEVEL="$1"
|
||||
|
||||
CURRENT_USER="$USER"
|
||||
if [ -z "$CURRENT_USER" ]; then
|
||||
CURRENT_USER="$(whoami)"
|
||||
|
||||
Reference in New Issue
Block a user