mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-26 02:12:33 +01:00
Added battery charge gauge from: http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/ to themes
Battery gauge requires a python script, 'battcharge.py' added to $ZSH/lib/ directory to work properly. Cleaned up zshmarks again, now uses proper return codes in case bookmark not found, etc.
This commit is contained in:
parent
2dc12882af
commit
59e2f43237
5 changed files with 78 additions and 16 deletions
38
lib/battcharge.py
Executable file
38
lib/battcharge.py
Executable file
|
|
@ -0,0 +1,38 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# coding=UTF-8
|
||||||
|
|
||||||
|
import math, subprocess
|
||||||
|
|
||||||
|
p = subprocess.Popen(["ioreg", "-rc", "AppleSmartBattery"], stdout=subprocess.PIPE)
|
||||||
|
output = p.communicate()[0]
|
||||||
|
|
||||||
|
o_max = [l for l in output.splitlines() if 'MaxCapacity' in l][0]
|
||||||
|
o_cur = [l for l in output.splitlines() if 'CurrentCapacity' in l][0]
|
||||||
|
|
||||||
|
b_max = float(o_max.rpartition('=')[-1].strip())
|
||||||
|
b_cur = float(o_cur.rpartition('=')[-1].strip())
|
||||||
|
|
||||||
|
charge = b_cur / b_max
|
||||||
|
charge_threshold = int(math.ceil(10 * charge))
|
||||||
|
|
||||||
|
# Output
|
||||||
|
|
||||||
|
total_slots, slots = 10, []
|
||||||
|
filled = int(math.ceil(charge_threshold * (total_slots / 10.0))) * u'▸'
|
||||||
|
empty = (total_slots - len(filled)) * u'▹'
|
||||||
|
|
||||||
|
out = (filled + empty).encode('utf-8')
|
||||||
|
import sys
|
||||||
|
|
||||||
|
color_green = '%{[1;32m%}'
|
||||||
|
color_yellow = '%{[1;33m%}'
|
||||||
|
color_red = '%{[1;31m%}'
|
||||||
|
color_reset = '%{[00m%}'
|
||||||
|
color_out = (
|
||||||
|
color_green if len(filled) > 6
|
||||||
|
else color_yellow if len(filled) > 4
|
||||||
|
else color_red
|
||||||
|
)
|
||||||
|
|
||||||
|
out = color_out + out + color_reset
|
||||||
|
sys.stdout.write(out)
|
||||||
|
|
@ -13,19 +13,21 @@ if [[ ! -f $bookmarks_file ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function bookmark() {
|
function bookmark() {
|
||||||
bookmark_name=$1
|
bookmark_name=$1
|
||||||
if [[ -z $bookmark_name ]]; then
|
if [[ -z $bookmark_name ]]; then
|
||||||
echo 'Invalid name, please provide a name for your bookmark. For example:'
|
echo 'Invalid name, please provide a name for your bookmark. For example:'
|
||||||
echo ' bookmark foo'
|
echo ' bookmark foo'
|
||||||
else
|
return 1
|
||||||
bookmark="$(pwd)|$bookmark_name" # Store the bookmark as folder|name
|
else
|
||||||
if [[ -z $(grep "$bookmark" $bookmarks_file) ]]; then
|
bookmark="$(pwd)|$bookmark_name" # Store the bookmark as folder|name
|
||||||
echo $bookmark >> $bookmarks_file
|
if [[ -z $(grep "$bookmark" $bookmarks_file) ]]; then
|
||||||
echo "Bookmark '$bookmark_name' saved"
|
echo $bookmark >> $bookmarks_file
|
||||||
else
|
echo "Bookmark '$bookmark_name' saved"
|
||||||
echo "Bookmark already existed"
|
else
|
||||||
fi
|
echo "Bookmark already existed"
|
||||||
fi
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function go() {
|
function go() {
|
||||||
|
|
@ -37,6 +39,7 @@ function go() {
|
||||||
echo
|
echo
|
||||||
echo "To bookmark a folder, go to the folder then do this (naming the bookmark 'foo'):"
|
echo "To bookmark a folder, go to the folder then do this (naming the bookmark 'foo'):"
|
||||||
echo " bookmark foo"
|
echo " bookmark foo"
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
dir="${bookmark%%|*}"
|
dir="${bookmark%%|*}"
|
||||||
cd "${dir}"
|
cd "${dir}"
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,11 @@ preexec () {
|
||||||
echo -en $reset_color
|
echo -en $reset_color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function battery_charge {
|
||||||
|
$ZSH/lib/battcharge.py
|
||||||
|
echo `$BAT_CHARGE` 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
setprompt () {
|
setprompt () {
|
||||||
# Need this so the prompt will work.
|
# Need this so the prompt will work.
|
||||||
setopt prompt_subst
|
setopt prompt_subst
|
||||||
|
|
@ -78,7 +83,7 @@ setprompt () {
|
||||||
PR_URCORNER=${altchar[k]:--}
|
PR_URCORNER=${altchar[k]:--}
|
||||||
|
|
||||||
# set return code to display if greater than zero
|
# set return code to display if greater than zero
|
||||||
return_code="%(?..$PR_MAGENTA($PR_RED%? ↵ $PR_MAGENTA%))"
|
return_code="%(?..$PR_MAGENTA($PR_RED%?↩ $PR_MAGENTA%))"
|
||||||
|
|
||||||
PROMPT='$PR_SET_CHARSET\
|
PROMPT='$PR_SET_CHARSET\
|
||||||
$PR_MAGENTA$PR_SHIFT_IN$PR_ULCORNER$PR_HBAR$PR_SHIFT_OUT(\
|
$PR_MAGENTA$PR_SHIFT_IN$PR_ULCORNER$PR_HBAR$PR_SHIFT_OUT(\
|
||||||
|
|
@ -95,6 +100,8 @@ $return_code\
|
||||||
$PR_MAGENTA$PR_SHIFT_IN$PR_HBAR\
|
$PR_MAGENTA$PR_SHIFT_IN$PR_HBAR\
|
||||||
$PR_GREEN❯$PR_SHIFT_OUT '
|
$PR_GREEN❯$PR_SHIFT_OUT '
|
||||||
|
|
||||||
|
RPROMPT='$(battery_charge)$PR_GREEN'
|
||||||
|
|
||||||
PS2='$PR_MAGENTA$PR_SHIFT_IN$PR_LLCORNER$PR_HBAR$PR_HBAR$PR_SHIFT_OUT$PR_GREEN\ '
|
PS2='$PR_MAGENTA$PR_SHIFT_IN$PR_LLCORNER$PR_HBAR$PR_HBAR$PR_SHIFT_OUT$PR_GREEN\ '
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,11 @@ preexec () {
|
||||||
echo -en $reset_color
|
echo -en $reset_color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function battery_charge {
|
||||||
|
$ZSH/lib/battcharge.py
|
||||||
|
echo `$BAT_CHARGE` 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
setprompt () {
|
setprompt () {
|
||||||
# Need this so the prompt will work.
|
# Need this so the prompt will work.
|
||||||
setopt prompt_subst
|
setopt prompt_subst
|
||||||
|
|
@ -78,7 +83,7 @@ setprompt () {
|
||||||
PR_URCORNER=${altchar[k]:--}
|
PR_URCORNER=${altchar[k]:--}
|
||||||
|
|
||||||
# set return code to display if greater than zero
|
# set return code to display if greater than zero
|
||||||
return_code="%(?..$PR_WHITE($PR_RED%? ↵ $PR_WHITE%))"
|
return_code="%(?..$PR_WHITE($PR_RED%?↩ $PR_WHITE%))"
|
||||||
|
|
||||||
PROMPT='$PR_SET_CHARSET\
|
PROMPT='$PR_SET_CHARSET\
|
||||||
$PR_WHITE$PR_SHIFT_IN$PR_ULCORNER$PR_HBAR$PR_SHIFT_OUT(\
|
$PR_WHITE$PR_SHIFT_IN$PR_ULCORNER$PR_HBAR$PR_SHIFT_OUT(\
|
||||||
|
|
@ -95,6 +100,8 @@ $return_code\
|
||||||
$PR_WHITE$PR_SHIFT_IN$PR_HBAR\
|
$PR_WHITE$PR_SHIFT_IN$PR_HBAR\
|
||||||
$PR_GREEN❯$PR_SHIFT_OUT '
|
$PR_GREEN❯$PR_SHIFT_OUT '
|
||||||
|
|
||||||
|
RPROMPT='$(battery_charge)$PR_GREEN'
|
||||||
|
|
||||||
PS2='$PR_MAGENTA$PR_SHIFT_IN$PR_LLCORNER$PR_HBAR$PR_HBAR$PR_SHIFT_OUT$PR_GREEN\ '
|
PS2='$PR_MAGENTA$PR_SHIFT_IN$PR_LLCORNER$PR_HBAR$PR_HBAR$PR_SHIFT_OUT$PR_GREEN\ '
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,11 @@ preexec () {
|
||||||
echo -en $reset_color
|
echo -en $reset_color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function battery_charge {
|
||||||
|
$ZSH/lib/battcharge.py
|
||||||
|
echo `$BAT_CHARGE` 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
setprompt () {
|
setprompt () {
|
||||||
# Need this so the prompt will work.
|
# Need this so the prompt will work.
|
||||||
setopt prompt_subst
|
setopt prompt_subst
|
||||||
|
|
@ -78,7 +83,7 @@ setprompt () {
|
||||||
PR_URCORNER=${altchar[k]:--}
|
PR_URCORNER=${altchar[k]:--}
|
||||||
|
|
||||||
# set return code to display if greater than zero
|
# set return code to display if greater than zero
|
||||||
return_code="%(?..$PR_BLUE($PR_RED%? ↵ $PR_BLUE%))"
|
return_code="%(?..$PR_BLUE($PR_RED%?↩ $PR_BLUE%))"
|
||||||
|
|
||||||
PROMPT='$PR_SET_CHARSET\
|
PROMPT='$PR_SET_CHARSET\
|
||||||
$PR_BLUE$PR_SHIFT_IN$PR_ULCORNER$PR_HBAR$PR_SHIFT_OUT(\
|
$PR_BLUE$PR_SHIFT_IN$PR_ULCORNER$PR_HBAR$PR_SHIFT_OUT(\
|
||||||
|
|
@ -95,6 +100,8 @@ $return_code\
|
||||||
$PR_BLUE$PR_SHIFT_IN$PR_HBAR\
|
$PR_BLUE$PR_SHIFT_IN$PR_HBAR\
|
||||||
$PR_GREEN❯$PR_SHIFT_OUT '
|
$PR_GREEN❯$PR_SHIFT_OUT '
|
||||||
|
|
||||||
|
RPROMPT='$(battery_charge)$PR_GREEN'
|
||||||
|
|
||||||
PS2='$PR_MAGENTA$PR_SHIFT_IN$PR_LLCORNER$PR_HBAR$PR_HBAR$PR_SHIFT_OUT$PR_GREEN\ '
|
PS2='$PR_MAGENTA$PR_SHIFT_IN$PR_LLCORNER$PR_HBAR$PR_HBAR$PR_SHIFT_OUT$PR_GREEN\ '
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue