zsh
settings, I came across a very interesting solution for inviting the command line, which is located in this shell on the right . Usually, it is customary to put a clock there, but I quite liked the idea of placing a battery charge notifier there as well. Depending on the level of charge, the notifier is shown in green, yellow or red. The author of the idea for some reason dragged to the solution of python, I rewrote everything in my native shell.%F{…}
) everything is required to work on any distributions for zsh
. So let's get started.zsh
is set by the RPROMPT
environment RPROMPT
. Here is a piece of code that makes sense to put in ~/.zshrc
(or ~/.oh-my-zsh/themes/_
, if you already know about oh-my-zsh ): function battery_charge { # Battery 0: Discharging, 94%, 03:46:34 remaining bat_percent=`acpi | awk -F ':' {'print $2;'} | awk -F ',' {'print $2;'} | sed -e "s/\s//" -e "s/%.*//"` if [ $bat_percent -lt 20 ]; then cl='%F{red}' elif [ $bat_percent -lt 50 ]; then cl='%F{yellow}' else cl='%F{green}' fi filled=${(l:`expr $bat_percent / 10`::▸:)} empty=${(l:`expr 10 - $bat_percent / 10`::▹:)} echo $cl$filled$empty'%F{default}' } RPROMPT='[%*] $(battery_charge)'
acpi
(you may need to install sudo apt-get install acpi
); RPROMPT='%{$fg[red]%} ⏎ $? %{$reset_color%} '$RPROMPT
Source: https://habr.com/ru/post/132599/
All Articles