Created
May 21, 2024 14:40
-
-
Save jdrzj/76666ec6af01ae902802675246b5d1ca to your computer and use it in GitHub Desktop.
Zsh Prompt with power source / battery level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function set_battery_envs() { | |
| export POWER_SOURCE=$([[ $(pmset -g batt | grep -Eoi "(\w+) Power") == "Battery Power" ]] && echo "๐" || echo "๐") | |
| export BATTERY_LEVEL=$(pmset -g batt | grep -Eoi '([0-9]{1,3}\%)' | grep -Eoi '[0-9]+') | |
| PS1="(%h) %K{22}[${BATTERY_LEVEL}%%]%k ${POWER_SOURCE} %* %n:%~$ " | |
| } | |
| typeset -a precmd_functions | |
| precmd_functions=(set_battery_envs) | |
| setopt PROMPT_SUBST | |
| PROMPT="(%h) %K{22}[${BATTERY_LEVEL}%%]%k ${POWER_SOURCE} %* %n:%~$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment