diff --git a/lib/battcharge.py b/lib/battcharge.py new file mode 100755 index 000000000..e4aa4d4d8 --- /dev/null +++ b/lib/battcharge.py @@ -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 = '%{%}' +color_yellow = '%{%}' +color_red = '%{%}' +color_reset = '%{%}' +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) \ No newline at end of file diff --git a/plugins/zshmarks/zshmarks.plugin.zsh b/plugins/zshmarks/zshmarks.plugin.zsh index 80e419169..7a49154c9 100644 --- a/plugins/zshmarks/zshmarks.plugin.zsh +++ b/plugins/zshmarks/zshmarks.plugin.zsh @@ -13,19 +13,21 @@ if [[ ! -f $bookmarks_file ]]; then fi function bookmark() { - bookmark_name=$1 - if [[ -z $bookmark_name ]]; then - echo 'Invalid name, please provide a name for your bookmark. For example:' - echo ' bookmark foo' - else - bookmark="$(pwd)|$bookmark_name" # Store the bookmark as folder|name - if [[ -z $(grep "$bookmark" $bookmarks_file) ]]; then - echo $bookmark >> $bookmarks_file - echo "Bookmark '$bookmark_name' saved" - else - echo "Bookmark already existed" - fi - fi + bookmark_name=$1 + if [[ -z $bookmark_name ]]; then + echo 'Invalid name, please provide a name for your bookmark. For example:' + echo ' bookmark foo' + return 1 + else + bookmark="$(pwd)|$bookmark_name" # Store the bookmark as folder|name + if [[ -z $(grep "$bookmark" $bookmarks_file) ]]; then + echo $bookmark >> $bookmarks_file + echo "Bookmark '$bookmark_name' saved" + else + echo "Bookmark already existed" + return 1 + fi + fi } function go() { @@ -37,6 +39,7 @@ function go() { echo echo "To bookmark a folder, go to the folder then do this (naming the bookmark 'foo'):" echo " bookmark foo" + return 1 else dir="${bookmark%%|*}" cd "${dir}" diff --git a/themes/jocelyn_new.zsh-theme b/themes/jocelyn_new.zsh-theme index 9bdce4c06..0bac73a72 100644 --- a/themes/jocelyn_new.zsh-theme +++ b/themes/jocelyn_new.zsh-theme @@ -39,6 +39,11 @@ preexec () { echo -en $reset_color } +function battery_charge { + $ZSH/lib/battcharge.py + echo `$BAT_CHARGE` 2>/dev/null +} + setprompt () { # Need this so the prompt will work. setopt prompt_subst @@ -78,7 +83,7 @@ setprompt () { PR_URCORNER=${altchar[k]:--} # 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\ $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_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\ ' } diff --git a/themes/jocelyn_new2.zsh-theme b/themes/jocelyn_new2.zsh-theme index 7f102215b..9651ce97f 100644 --- a/themes/jocelyn_new2.zsh-theme +++ b/themes/jocelyn_new2.zsh-theme @@ -39,6 +39,11 @@ preexec () { echo -en $reset_color } +function battery_charge { + $ZSH/lib/battcharge.py + echo `$BAT_CHARGE` 2>/dev/null +} + setprompt () { # Need this so the prompt will work. setopt prompt_subst @@ -78,7 +83,7 @@ setprompt () { PR_URCORNER=${altchar[k]:--} # 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\ $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_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\ ' } diff --git a/themes/jocelyn_new3.zsh-theme b/themes/jocelyn_new3.zsh-theme index d9872bb0f..e59f39a41 100644 --- a/themes/jocelyn_new3.zsh-theme +++ b/themes/jocelyn_new3.zsh-theme @@ -39,6 +39,11 @@ preexec () { echo -en $reset_color } +function battery_charge { + $ZSH/lib/battcharge.py + echo `$BAT_CHARGE` 2>/dev/null +} + setprompt () { # Need this so the prompt will work. setopt prompt_subst @@ -78,7 +83,7 @@ setprompt () { PR_URCORNER=${altchar[k]:--} # 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\ $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_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\ ' }