-
Notifications
You must be signed in to change notification settings - Fork 0
/
batcut
61 lines (57 loc) · 1.86 KB
/
batcut
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# File path for conservation_mode
CONSERVATION_MODE_PATH="/sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode"
# Function to display help
show_help() {
echo "Usage: batcut [OPTION] [VALUE]"
echo
echo "Options:"
echo " 0 Disable conservation mode (allow full battery charge)"
echo " 1 Enable conservation mode (limit battery to 60% charge)"
echo " -s, --status Show current conservation mode status"
echo " -h, --help Display this help message"
echo
echo "Examples:"
echo " batcut 1 Enable conservation mode"
echo " batcut 0 Disable conservation mode"
echo " batcut -s Show current conservation mode status"
}
# Check for arguments
if [[ $# -eq 0 ]]; then
echo "Error: No arguments provided. Use -h or --help for usage information."
exit 1
fi
# Handle options
case "$1" in
-h|--help)
show_help
exit 0
;;
-s|--status)
if [[ -f "$CONSERVATION_MODE_PATH" ]]; then
status=$(cat "$CONSERVATION_MODE_PATH")
if [[ "$status" == "1" ]]; then
echo "Conservation mode is currently ENABLED."
elif [[ "$status" == "0" ]]; then
echo "Conservation mode is currently DISABLED."
else
echo "Unknown status: $status"
fi
else
echo "Error: Conservation mode file not found at $CONSERVATION_MODE_PATH."
fi
exit 0
;;
1)
echo 1 | sudo tee "$CONSERVATION_MODE_PATH" > /dev/null
echo "Conservation mode enabled."
;;
0)
echo 0 | sudo tee "$CONSERVATION_MODE_PATH" > /dev/null
echo "Conservation mode disabled."
;;
*)
echo "Error: Invalid argument '$1'. Use -h or --help for usage information."
exit 1
;;
esac