From 7285d78f1ff7084116297c6c69f827e521d61df7 Mon Sep 17 00:00:00 2001 From: Adam Hitchcock Date: Thu, 25 Mar 2010 15:52:46 -0700 Subject: [PATCH 1/3] added my own theme added my theme bail on linux bail on linux speed fix bug added my theme no git stat done, too slow added color to stderr minor changes to clolor for linux killed red git stuff is back! coproc for red stderr battery works! works on linux theme updates tweaks --- themes/north.zsh-theme | 151 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 themes/north.zsh-theme diff --git a/themes/north.zsh-theme b/themes/north.zsh-theme new file mode 100644 index 000000000..1d86e0cff --- /dev/null +++ b/themes/north.zsh-theme @@ -0,0 +1,151 @@ +autoload -U promptinit +promptinit +autoload -U colors; colors + +case $USER in + 'root') + export PS1="$PS1_NAME$PS1_TIME$PS1_PATH# " + local user_prompt="%B$fg[red]%b%% " + ;; + + *) + local user_prompt="%B$fg[magenta]%b%% " + ;; +esac + +local HOST_STRING="$fg[green]`hostname`" +local blue_ob="%{%B$fg[blue]%}[%{$reset_color%}%b" +local blue_cb="%{%B$fg[blue]%}]%{$reset_color%}%b" +local blue_op="%{%B$fg[blue]%}(%{$reset_color%}%b" +local blue_cp="%{%B$fg[blue]%})%{$reset_color%}%b" +local path_p="${blue_ob}$fg[red]%~${blue_cb}" +local user_host="${blue_ob}${HOST_STRING}$fg[magenta]@$fg[green]%m${blue_cb}" +local ret_status="${blue_ob}$fg[yellow]ret:%?${blue_cb}" +local hist_no="${blue_ob}$fg[yellow]hist:%h${blue_cb}" +local panic="${blue_ob}%(?,%{$fg[green]%}%BDON'T PANIC%b%{$reset_color%},%{$fg[red]%}>> PANIC <<%{$reset_color%})${blue_cb}" +local smiley="%(?,%{$fg[green]%}:%)%{$reset_color%},%{$fg[red]%}:(%{$reset_color%})" + + +function collapse_pwd { + echo $(pwd | sed -e "s,^$HOME,~,") +} + +function prompt_char { + git branch >/dev/null 2>/dev/null && echo "${fg[red]}git ∓∓∓${reset_color}" && return + # hg root >/dev/null 2>/dev/null && echo "${fg[red]}hg ☿${reset_color}" && return + # svn info >/dev/null 2>/dev/null && echo "${fg[red]}svn s${reset_color}" && return + echo "${fg[blue]}○${reset_color}" +} + +function battery_charge { + [[ ! ($1 == "arrows" || $1 == "steps") ]] && print "usage $0 arrows|steps [opt: CurrentCapacity]" && exit + [[ -e /usr/bin/pmset ]] || return + + s=`pmset -g ps` + # "Currently drawing from 'AC Power'" + # "-InternalBattery-0 54%; charging; 0:51 remaining" + + [[ -z $s ]] && return + [[ -z $1 && -z $2 ]] && return + [[ $1 == 'arrows' ]] && base=10 + [[ $1 == 'steps' ]] && base=8 + + [[ ! -z $2 ]] && cur=$2 + + percent=`pmset -g batt | awk '/-InternalBattery-0/ {print $2}'` + percent=${percent%%%*} + + fuel=$(( $percent / $base )) + # fuel=`echo "scale=1; $percent/$base" | bc -q` + + # color="" + # if [[ $fuel -ge 9 ]]; then + # #full + # color="$terminfo[bold]$fg[green]" + # elif [[ $fuel -ge 8 ]]; then + # #good + # color="$fg[green]" + # elif [[ $fuel -ge 5 ]]; then + # #ok + # color="$fg[orange]" + # elif [[ $fuel -ge 3 ]]; then + # #low + # color="$terminfo[bold]$fg[yellow]" + # elif [[ $fuel -ge 1 ]]; then + # #bad + # color="$fg[red]" + # fi + + if [[ $1 == arrows ]]; then + full='▶' + part='▷' + display="" + for (( i = 1; i <= $fuel; i++ )); do + display=$display$full + done + for (( i = $fuel; i < 10; i++ )); do + display=$display$part + done + fi + + if [[ $1 == steps ]]; then + level="▁▂▃▄▅▆▇▉" + for (( i = 1; i <= $fuel; i++ )); do + display=$display$level[$i] + done + for (( i = $fuel; i < 8; i++ )); do + display=" "$display + done + fi + + print "${display}" +} + +function virtualenv_info { + [ $VIRTUAL_ENV ] && echo "${blue_op}$fg[magenta]"`basename $VIRTUAL_ENV`"$fg[reset]${blue_cp}─" +} + +ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}!" +ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?" +ZSH_THEME_GIT_PROMPT_CLEAN="" + +function hg_prompt_info() { + hg prompt --angle-brackets "\ +< on %{$fg[magenta]%}%{$reset_color%}>\ +< at %{$fg[yellow]%}%{$reset_color%}>\ +%{$fg[green]%}%{$reset_color%}< +patches: >" 2>/dev/null +} + + +function parse_git_dirty2() { + gitstat=$(git status -u 2>/dev/null | grep '\(# Untracked\|# Changes\|# Changed but not updated:\)'&) + if [[ $(echo ${gitstat} | grep -c "^# Changes to be committed:$") > 0 ]]; then + echo -n "$ZSH_THEME_GIT_PROMPT_DIRTY" + fi + if [[ $(echo ${gitstat} | grep -c "^\(# Untracked files:\|# Changed but not updated:\)$") > 0 ]]; then + echo -n "$ZSH_THEME_GIT_PROMPT_UNTRACKED" + fi + if [[ $(echo ${gitstat} | grep -v '^$' | wc -l | tr -d ' ') == 0 ]]; then + echo -n "$ZSH_THEME_GIT_PROMPT_CLEAN" + fi +} + +# get the name of the branch we are on +function git_prompt_info2() { + ref=$(git symbolic-ref HEAD 2> /dev/null) || return + branch=${ref#refs/heads/} + sha=$(git rev-parse --short ${branch}) + echo "$ZSH_THEME_GIT_PROMPT_PREFIX${branch}%{$fg[green]%}@%{$fg[magenta]%}${sha}$ZSH_THEME_GIT_PROMPT_SUFFIX$(parse_git_dirty2)" +} + +PROMPT='╭─$(virtualenv_info)$(prompt_char)$(git_prompt_info2)─${user_host}─${path_p}─${panic}-${ret_status}─${hist_no} +╰─${blue_ob}${smiley}${blue_cb}${user_color}─> ⚡ ' +PROMPT2='${blue_ob}$_${blue_cb}> ' + +# righthand side + +RPROMPT='$(battery_charge arrows)' + From 32c9f40d6e88155a27332391537ec8f329afead7 Mon Sep 17 00:00:00 2001 From: Adam Hitchcock Date: Mon, 23 Jul 2012 14:43:26 -0700 Subject: [PATCH 2/3] added osx support for battery plugin --- plugins/battery/battery.plugin.zsh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index bc75c5cf9..57945565e 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -12,6 +12,21 @@ if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then fi echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}" } +elif [[ -e /usr/bin/pmset ]] ; then + function battery_pct_remaining() { echo "$(pmset -g ps | tr -cd '[:digit:][:blank:]:' | awk '{print $2}')"} + function battery_time_remaining() { echo "$(pmset -g ps | tr -cd '[:digit:][:blank:]:' | awk '{print $3}')"} + function battery_pct_prompt() { + b=$(battery_pct_remaining) + display="" + if [[ $1 == steps ]] ; then + fuel=$(( $b / 12.5 )) + echo ${(r:$fuel::▁▂▃▄▅▆▇█:)} + else ; + fuel=$(( $b / 10 )) + remainder=$(( 10 - $fuel )) + echo ${(r:$fuel::▶:)}${(l:$remainder::▷:)} + fi + } else error_msg='no battery' function battery_pct_remaining() { echo $error_msg } From 3dfd8c4efe99adacae17db9c6d73e7b345307e7b Mon Sep 17 00:00:00 2001 From: Adam Hitchcock Date: Mon, 23 Jul 2012 14:43:40 -0700 Subject: [PATCH 3/3] use my new battery plugin --- themes/north.zsh-theme | 83 +----------------------------------------- 1 file changed, 2 insertions(+), 81 deletions(-) diff --git a/themes/north.zsh-theme b/themes/north.zsh-theme index 1d86e0cff..1f1a7a5ee 100644 --- a/themes/north.zsh-theme +++ b/themes/north.zsh-theme @@ -37,70 +37,6 @@ function prompt_char { echo "${fg[blue]}○${reset_color}" } -function battery_charge { - [[ ! ($1 == "arrows" || $1 == "steps") ]] && print "usage $0 arrows|steps [opt: CurrentCapacity]" && exit - [[ -e /usr/bin/pmset ]] || return - - s=`pmset -g ps` - # "Currently drawing from 'AC Power'" - # "-InternalBattery-0 54%; charging; 0:51 remaining" - - [[ -z $s ]] && return - [[ -z $1 && -z $2 ]] && return - [[ $1 == 'arrows' ]] && base=10 - [[ $1 == 'steps' ]] && base=8 - - [[ ! -z $2 ]] && cur=$2 - - percent=`pmset -g batt | awk '/-InternalBattery-0/ {print $2}'` - percent=${percent%%%*} - - fuel=$(( $percent / $base )) - # fuel=`echo "scale=1; $percent/$base" | bc -q` - - # color="" - # if [[ $fuel -ge 9 ]]; then - # #full - # color="$terminfo[bold]$fg[green]" - # elif [[ $fuel -ge 8 ]]; then - # #good - # color="$fg[green]" - # elif [[ $fuel -ge 5 ]]; then - # #ok - # color="$fg[orange]" - # elif [[ $fuel -ge 3 ]]; then - # #low - # color="$terminfo[bold]$fg[yellow]" - # elif [[ $fuel -ge 1 ]]; then - # #bad - # color="$fg[red]" - # fi - - if [[ $1 == arrows ]]; then - full='▶' - part='▷' - display="" - for (( i = 1; i <= $fuel; i++ )); do - display=$display$full - done - for (( i = $fuel; i < 10; i++ )); do - display=$display$part - done - fi - - if [[ $1 == steps ]]; then - level="▁▂▃▄▅▆▇▉" - for (( i = 1; i <= $fuel; i++ )); do - display=$display$level[$i] - done - for (( i = $fuel; i < 8; i++ )); do - display=" "$display - done - fi - - print "${display}" -} - function virtualenv_info { [ $VIRTUAL_ENV ] && echo "${blue_op}$fg[magenta]"`basename $VIRTUAL_ENV`"$fg[reset]${blue_cp}─" } @@ -119,26 +55,12 @@ function hg_prompt_info() { patches: >" 2>/dev/null } - -function parse_git_dirty2() { - gitstat=$(git status -u 2>/dev/null | grep '\(# Untracked\|# Changes\|# Changed but not updated:\)'&) - if [[ $(echo ${gitstat} | grep -c "^# Changes to be committed:$") > 0 ]]; then - echo -n "$ZSH_THEME_GIT_PROMPT_DIRTY" - fi - if [[ $(echo ${gitstat} | grep -c "^\(# Untracked files:\|# Changed but not updated:\)$") > 0 ]]; then - echo -n "$ZSH_THEME_GIT_PROMPT_UNTRACKED" - fi - if [[ $(echo ${gitstat} | grep -v '^$' | wc -l | tr -d ' ') == 0 ]]; then - echo -n "$ZSH_THEME_GIT_PROMPT_CLEAN" - fi -} - # get the name of the branch we are on function git_prompt_info2() { ref=$(git symbolic-ref HEAD 2> /dev/null) || return branch=${ref#refs/heads/} sha=$(git rev-parse --short ${branch}) - echo "$ZSH_THEME_GIT_PROMPT_PREFIX${branch}%{$fg[green]%}@%{$fg[magenta]%}${sha}$ZSH_THEME_GIT_PROMPT_SUFFIX$(parse_git_dirty2)" + echo "$ZSH_THEME_GIT_PROMPT_PREFIX${branch}%{$fg[green]%}@%{$fg[magenta]%}${sha}$ZSH_THEME_GIT_PROMPT_SUFFIX$(parse_git_dirty)" } PROMPT='╭─$(virtualenv_info)$(prompt_char)$(git_prompt_info2)─${user_host}─${path_p}─${panic}-${ret_status}─${hist_no} @@ -146,6 +68,5 @@ PROMPT='╭─$(virtualenv_info)$(prompt_char)$(git_prompt_info2)─${user_host} PROMPT2='${blue_ob}$_${blue_cb}> ' # righthand side - -RPROMPT='$(battery_charge arrows)' +RPROMPT='$(battery_pct_prompt)'