Last active
March 11, 2018 18:41
-
-
Save thiemok/9066d27ecb6fb30536ae7d0332901c1a to your computer and use it in GitHub Desktop.
zsh Theme for the fantastic pocketCHIP, will display battery level and charging indicator
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
# https://github.com/blinks zsh theme | |
# edited to display pocketchip battery status by https://github.com/thiemok | |
function _prompt_char() { | |
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then | |
echo "%{%F{blue}%}±%{%f%k%b%}" | |
else | |
echo ' ' | |
fi | |
} | |
# This theme works with both the "dark" and "light" variants of the | |
# Solarized color schema. Set the SOLARIZED_THEME variable to one of | |
# these two values to choose. If you don't specify, we'll assume you're | |
# using the "dark" variant. | |
case ${SOLARIZED_THEME:-dark} in | |
light) bkg=white;; | |
*) bkg=black;; | |
esac | |
ZSH_THEME_GIT_PROMPT_PREFIX=" [%{%B%F{blue}%}" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{%f%k%b%K{${bkg}}%B%F{green}%}]" | |
ZSH_THEME_GIT_PROMPT_DIRTY=" %{%F{red}%}*%{%f%k%b%}" | |
ZSH_THEME_GIT_PROMPT_CLEAN="" | |
VOLTAGE_DROP=43 | |
MAX_VOLTAGE=4202 | |
MIN_VOLTAGE=3600 | |
function batteryIndicator() { | |
is_charging=$(cat /usr/lib/pocketchip-batt/charging) | |
voltage=$(cat /usr/lib/pocketchip-batt/voltage) | |
voltage_offset=$(bc <<< "$is_charging*$VOLTAGE_DROP") | |
excess_voltage=$(bc <<< "$voltage-$voltage_offset-$MIN_VOLTAGE") | |
max_excess_voltage=$(bc <<< "$MAX_VOLTAGE-$VOLTAGE_DROP-$MIN_VOLTAGE") | |
percentage=$(bc <<< "scale=2; $excess_voltage/($max_excess_voltage/100)") | |
battStatus="-" && [[ "$is_charging" == 1 ]] && battStatus="+" | |
if (( $(bc <<< "$percentage < 20") )) | |
then | |
statusColor=red | |
else | |
statusColor=green | |
fi | |
echo "%B%F{${statusColor}}%}$percentage$battStatus" | |
} | |
PROMPT='%{%f%k%b%} | |
%{%K{${bkg}}%B%F{green}%}%n%{%B%F{blue}%}@%{%B%F{cyan}%}%m%{%B%F{green}%} %{%b%F{yellow}%K{${bkg}}%}%~%{%B%F{green}%}$(git_prompt_info)%E%{%f%k%b%} | |
%{%K{${bkg}}%}$(_prompt_char)%{%K{${bkg}}%} %#%{%f%k%b%} ' | |
RPROMPT='!%{%B%F{cyan}%}%!%{%f%k%b%} - $(batteryIndicator)%{%f%k%b%}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment