mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-12-04 14:19:04 +01:00
feat(macos): add low power mode management functions (#13517)
This commit is contained in:
1 parent
6d5348a397
commit
5b2db7b495
3 files changed
+74
-22
No files matched your search
+24
-22
@@ -9,6 +9,7 @@ plugins=(... macos)
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Supported Terminals
|
## Supported Terminals
|
||||||
|
|
||||||
- [iTerm](https://iterm.sourceforge.net/)
|
- [iTerm](https://iterm.sourceforge.net/)
|
||||||
- [iTerm2](https://iterm2.com/)
|
- [iTerm2](https://iterm2.com/)
|
||||||
- [Hyper](https://hyper.is/)
|
- [Hyper](https://hyper.is/)
|
||||||
@@ -17,28 +18,29 @@ plugins=(... macos)
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
| :------------ | :------------------------------------------------------- |
|
| :------------ | :------------------------------------------------------------- |
|
||||||
| `tab` | Open the current directory in a new tab |
|
| `tab` | Open the current directory in a new tab |
|
||||||
| `split_tab` | Split the current terminal tab horizontally |
|
| `split_tab` | Split the current terminal tab horizontally |
|
||||||
| `vsplit_tab` | Split the current terminal tab vertically |
|
| `vsplit_tab` | Split the current terminal tab vertically |
|
||||||
| `ofd` | Open passed directories (or $PWD by default) in Finder |
|
| `ofd` | Open passed directories (or $PWD by default) in Finder |
|
||||||
| `pfd` | Return the path of the frontmost Finder window |
|
| `pfd` | Return the path of the frontmost Finder window |
|
||||||
| `pfs` | Return the current Finder selection |
|
| `pfs` | Return the current Finder selection |
|
||||||
| `cdf` | `cd` to the current Finder directory |
|
| `cdf` | `cd` to the current Finder directory |
|
||||||
| `pushdf` | `pushd` to the current Finder directory |
|
| `pushdf` | `pushd` to the current Finder directory |
|
||||||
| `pxd` | Return the current Xcode project directory |
|
| `pxd` | Return the current Xcode project directory |
|
||||||
| `cdx` | `cd` to the current Xcode project directory |
|
| `cdx` | `cd` to the current Xcode project directory |
|
||||||
| `quick-look` | Quick-Look a specified file |
|
| `quick-look` | Quick-Look a specified file |
|
||||||
| `man-preview` | Open man pages in Preview app |
|
| `man-preview` | Open man pages in Preview app |
|
||||||
| `showfiles` | Show hidden files in Finder |
|
| `showfiles` | Show hidden files in Finder |
|
||||||
| `hidefiles` | Hide the hidden files in Finder |
|
| `hidefiles` | Hide the hidden files in Finder |
|
||||||
| `itunes` | _DEPRECATED_. Use `music` from macOS Catalina on |
|
| `itunes` | _DEPRECATED_. Use `music` from macOS Catalina on |
|
||||||
| `music` | Control Apple Music. Use `music -h` for usage details |
|
| `music` | Control Apple Music. Use `music -h` for usage details |
|
||||||
| `spotify` | Control Spotify and search by artist, album, track… |
|
| `spotify` | Control Spotify and search by artist, album, track… |
|
||||||
| `rmdsstore` | Remove .DS_Store files recursively in a directory |
|
| `lpm` | Toggle Low Power Mode. Use `lpm on\|off\|status` (macOS 12.0+) |
|
||||||
| `btrestart` | Restart the Bluetooth daemon |
|
| `rmdsstore` | Remove .DS_Store files recursively in a directory |
|
||||||
| `freespace` | Erases purgeable disk space with 0s on the selected disk |
|
| `btrestart` | Restart the Bluetooth daemon |
|
||||||
|
| `freespace` | Erases purgeable disk space with 0s on the selected disk |
|
||||||
|
|
||||||
## Acknowledgements
|
## Acknowledgements
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
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 lpm_status
|
||||||
|
|
||||||
|
case "${1:-toggle}" in
|
||||||
|
on)
|
||||||
|
sudo pmset -a lowpowermode 1
|
||||||
|
;;
|
||||||
|
off)
|
||||||
|
sudo pmset -a lowpowermode 0
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
lpm_status=$(pmset -g | awk '/lowpowermode/ {print $2}')
|
||||||
|
if [[ "$lpm_status" == "1" ]]; then
|
||||||
|
echo "enabled"
|
||||||
|
elif [[ "$lpm_status" == "0" ]]; then
|
||||||
|
echo "disabled"
|
||||||
|
else
|
||||||
|
echo "unknown" >&2
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
toggle)
|
||||||
|
lpm_status=$(pmset -g | awk '/lowpowermode/ {print $2}')
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -314,3 +314,6 @@ source "${0:h:A}/music"
|
|||||||
|
|
||||||
# Spotify control function
|
# Spotify control function
|
||||||
source "${0:h:A}/spotify"
|
source "${0:h:A}/spotify"
|
||||||
|
|
||||||
|
# low power mode toggle-switch function
|
||||||
|
source "${0:h:A}/lpm"
|
||||||
Reference in new issue
Block a user