From 3ec7dfb0e5ada870ee36b2fe061a02195bb95a1d Mon Sep 17 00:00:00 2001 From: Robin Wenglewski Date: Tue, 13 Sep 2011 17:10:15 +0200 Subject: [PATCH] modified my theme, make shell not return false --- themes/rweng.zsh-theme | 70 +++++++++++++++++++++++++++++++++++++----- zshrc | 4 ++- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/themes/rweng.zsh-theme b/themes/rweng.zsh-theme index 314171801..3596054be 100644 --- a/themes/rweng.zsh-theme +++ b/themes/rweng.zsh-theme @@ -1,15 +1,71 @@ -ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[green]%}" -ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%} ✘" -ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%} ✔" +# ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[green]%}" +# ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}[" + +ZSH_THEME_GIT_PROMPT_PREFIX="" +ZSH_THEME_GIT_PROMPT_SUFFIX="]" # "]%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="*" +ZSH_THEME_GIT_PROMPT_CLEAN="" function prompt_char { if [ $UID -eq 0 ]; then echo "%{$fg[red]%}#%{$reset_color%}"; else echo "%{$fg[red]%}⚡"; fi } -PROMPT='%(?, ,%{$fg[red]%}FAIL: $?%{$reset_color%} +PROMPT='%(?, ,%{$fg[red]%}FAILED WITH CODE: $?%{$reset_color%} ) -%{$fg[blue]%}%n%{$reset_color%}@%{$fg[yellow]%}%m%{$reset_color%}: %{$fg_bold[blue]%}%~%{$reset_color%}$(git_prompt_info) +%{$fg[blue]%}%~%{$reset_color%}$(git_time_since_commit)$(git_prompt_info) %_$(prompt_char) ' -RPROMPT='%{$fg[green]%}[%*]%{$reset_color%}' +RPROMPT='%{$fg[blue]%}%n%{$reset_color%}@%{$fg[cyan]%}%m%{$reset_color%}' + + +# Colors vary depending on time lapsed. +ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}" +ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}" +ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}" +ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}" + +# Determine the time since last commit. If branch is clean, +# use a neutral color, otherwise colors will vary according to time. +function git_time_since_commit() { + if git rev-parse --git-dir > /dev/null 2>&1; then + # Only proceed if there is actually a commit. + if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then + # Get the last commit. + last_commit=`git log --pretty=format:'%at' -1 2> /dev/null` + now=`date +%s` + seconds_since_last_commit=$((now-last_commit)) + + # Totals + MINUTES=$((seconds_since_last_commit / 60)) + HOURS=$((seconds_since_last_commit/3600)) + + # Sub-hours and sub-minutes + DAYS=$((seconds_since_last_commit / 86400)) + SUB_HOURS=$((HOURS % 24)) + SUB_MINUTES=$((MINUTES % 60)) + + if [[ -n $(git status -s 2> /dev/null) ]]; then + if [ "$MINUTES" -gt 60 ]; then + COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG" + elif [ "$MINUTES" -gt 30 ]; then + COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM" + else + COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT" + fi + else + COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" + fi + + if [ "$HOURS" -gt 24 ]; then + echo "${COLOR}[${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m|" + elif [ "$MINUTES" -gt 60 ]; then + echo "${COLOR}[${HOURS}h${SUB_MINUTES}m|" + else + echo "${COLOR}[${MINUTES}m|" + fi + else + COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" + echo "${COLOR}[~|" + fi + fi +} diff --git a/zshrc b/zshrc index 26b57876e..77bc5eb28 100755 --- a/zshrc +++ b/zshrc @@ -42,4 +42,6 @@ RWZSH=$HOME/.zsh . $ZSH/completion.zsh # use .localrc for settings specific to one system -[[ -f ~/.localrc ]] && . ~/.localrc +if [[ -f ~/.localrc ]]; then + . ~/.localrc +fi