Skip to content

Instantly share code, notes, and snippets.

@jdrzj
Created May 21, 2024 14:40
Show Gist options
  • Select an option

  • Save jdrzj/76666ec6af01ae902802675246b5d1ca to your computer and use it in GitHub Desktop.

Select an option

Save jdrzj/76666ec6af01ae902802675246b5d1ca to your computer and use it in GitHub Desktop.
Zsh Prompt with power source / battery level
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