mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-23 02:35:38 +01:00
feat(macos): add low power mode management functions
This commit is contained in:
parent
ec14da72fb
commit
23e8881147
3 changed files with 99 additions and 22 deletions
68
plugins/macos/lpm
Normal file
68
plugins/macos/lpm
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
function lpm() {
|
||||
local sw_vers=$(sw_vers -productVersion 2>/dev/null)
|
||||
|
||||
autoload is-at-least
|
||||
if [[ -z "$sw_vers" ]] || ! is-at-least 12.0 $sw_vers; then
|
||||
echo "Error: Low Power Mode requires macOS 12.0 (Monterey) or later" >&2
|
||||
echo "Current version: ${sw_vers:-unknown}" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local action="${1:-}"
|
||||
|
||||
# Helper function to get current status (returns 0, 1, or empty string)
|
||||
local get_status() {
|
||||
pmset -g | grep lowpowermode | awk '{print $2}'
|
||||
}
|
||||
|
||||
case "${action}" in
|
||||
on)
|
||||
sudo pmset -a lowpowermode 1
|
||||
;;
|
||||
off)
|
||||
sudo pmset -a lowpowermode 0
|
||||
;;
|
||||
status)
|
||||
local lpm_status=$(get_status)
|
||||
if [[ "$lpm_status" == "1" ]]; then
|
||||
echo "enabled"
|
||||
elif [[ "$lpm_status" == "0" ]]; then
|
||||
echo "disabled"
|
||||
else
|
||||
echo "unknown" >&2
|
||||
return 3
|
||||
fi
|
||||
;;
|
||||
toggle)
|
||||
local lpm_status=$(get_status)
|
||||
if [[ "$lpm_status" == "1" ]]; then
|
||||
sudo pmset -a lowpowermode 0
|
||||
elif [[ "$lpm_status" == "0" ]]; then
|
||||
sudo pmset -a lowpowermode 1
|
||||
else
|
||||
echo "Unable to determine current status to toggle" >&2
|
||||
return 3
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "usage: lpm on|off|status|toggle" >&2
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function lpm-off() {
|
||||
lpm off
|
||||
}
|
||||
|
||||
function lpm-on() {
|
||||
lpm on
|
||||
}
|
||||
|
||||
function lpm-status() {
|
||||
lpm status
|
||||
}
|
||||
|
||||
function lpm-toggle() {
|
||||
lpm toggle
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue