Updated theme
This commit is contained in:
parent
25b11a5fba
commit
3cc1e08c9f
2 changed files with 42 additions and 14 deletions
33
themes/twain/charge.py
Executable file
33
themes/twain/charge.py
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python
|
||||
# coding=UTF-8
|
||||
""" Prints a battery meter for use in a zsh theme """
|
||||
|
||||
import math, sys
|
||||
|
||||
""" Config """
|
||||
|
||||
output_length = 10
|
||||
blank_when_battery_full = True
|
||||
filled_char, empty_char = u'▪', u'▫'
|
||||
|
||||
""" Read battery charge """
|
||||
|
||||
def read_battery_percent ():
|
||||
""" Reads the battery charge as an integer between 0 and 100,
|
||||
using 'acpi -b' """
|
||||
import subprocess, re
|
||||
process = subprocess.Popen(["acpi", "-b"], stdout=subprocess.PIPE)
|
||||
output = process.communicate()[0].strip()
|
||||
return int(re.search("^Battery 0: .+, ([\d]+)\%",output).group(1))
|
||||
|
||||
""" Output """
|
||||
|
||||
charge = read_battery_percent()
|
||||
|
||||
if not(blank_when_battery_full == True and charge == 100):
|
||||
filled = int(math.ceil(charge / output_length))
|
||||
empty = output_length - filled
|
||||
meter = (filled * filled_char + empty * empty_char).encode('utf-8')
|
||||
|
||||
color = 'green'if filled > 6 else 'yellow' if filled > 4 else 'red'
|
||||
sys.stdout.write("%F{{{}}}{}%f".format(color, meter))
|
|
@ -1,22 +1,16 @@
|
|||
#
|
||||
# A verbose theme
|
||||
# A light theme showing only the needed information.
|
||||
#
|
||||
# Authors:
|
||||
# Samuel Clements <samuel@borntyping.co.uk>
|
||||
#
|
||||
# Screenshot:
|
||||
#
|
||||
#
|
||||
|
||||
# Get the current directory and collapse $HOME to ~
|
||||
function collapse_pwd {
|
||||
echo $(pwd | sed -e "s,^$HOME,~,")
|
||||
}
|
||||
|
||||
# Get the current battery charge
|
||||
# Requires a script that returns a battery meter
|
||||
function battery_charge {
|
||||
CHARGE_SCRIPT="~/bin/charge.py"
|
||||
if [[ -a $CHARGE_SCRIPT ]]; then
|
||||
echo `$(CHARGE_SCRIPT)` 2>/dev/null
|
||||
fi
|
||||
# Get the current battery charge
|
||||
echo `python ~/.oh-my-zsh/themes/twain/charge.py` 2>/dev/null
|
||||
}
|
||||
|
||||
function prompt_twain_setup() {
|
||||
|
@ -38,8 +32,9 @@ function prompt_twain_setup() {
|
|||
zstyle ':vcs_info:*' formats 'on branch %F{blue}%r:%b%f%c%u '
|
||||
zstyle ':vcs_info:*' actionformats 'on branch %F{blue}%r:%b%f%c%u %F{cyan}%a%f '
|
||||
|
||||
# %F{red}%n%f at %F{yellow}%m%f in
|
||||
PROMPT='%B%F{blue}${PWD/#$HOME/~}%f%b ${vcs_info_msg_0_}❯ '
|
||||
PROMPT='%B%F{blue}%~%f%b ${vcs_info_msg_0_}❯ '
|
||||
# Uncomment to add 'user at host ' to the prompt
|
||||
#PROMPT='%F{red}%n%f at %F{yellow}%m%f in $(PROMPT)'
|
||||
RPROMPT='%(?..[ %F{red}%?%f ] )$(battery_charge)'
|
||||
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f? '
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue