-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-ac
More file actions
26 lines (22 loc) · 754 Bytes
/
check-ac
File metadata and controls
26 lines (22 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Copyright (C) 2025 sppidy
#
# This file is a part of <https://github.com/sppidy/scripts>
# Please read the GNU General Public License in
# <https://www.github.com/sppidy/scripts/blob/main/LICENSE/>.
#!/bin/bash
AC_DIR=$(ls /sys/class/power_supply/ | grep -E "^AC|^AC0|^ACAD" | head -n 1)
if [ -n "$AC_DIR" ]; then
AC_STATUS_FILE="/sys/class/power_supply/$AC_DIR/online"
if [ -f "$AC_STATUS_FILE" ]; then
AC_STATUS=$(cat "$AC_STATUS_FILE")
if [ "$AC_STATUS" -eq 1 ]; then
echo "1 : Plugged into AC power"
else
echo "0 : Running on battery"
fi
else
echo "AC status file not found! Check your power supply path."
fi
else
echo "No AC power supply directory found!"
fi