distribution/packages/jelos/sources/scripts/say

28 lines
555 B
Text
Raw Normal View History

#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2023-present Fewtarius (https://github.com/fewtarius)
. /etc/profile
battery_percent() {
cat /sys/class/power_supply/{BAT,bat}*/uevent 2>/dev/null | grep -E "^POWER_SUPPLY_CAPACITY=" | sed -e s+'^POWER_SUPPLY_CAPACITY='++ | sort -rn | head -1
}
case ${SDL_AUDIODRIVER} in
alsa)
PLAYCMD="aplay -q"
;;
pulseaudio)
PLAYCMD="paplay"
;;
esac
case $1 in
-b)
espeak --stdout "$(battery_percent)%" | ${PLAYCMD}
;;
*)
espeak --stdout "$*" | ${PLAYCMD}
;;
esac