├── README └── sfistak.zsh-theme /README: -------------------------------------------------------------------------------- 1 | My ZSH Theme 2 | 3 | #slighlty modified robbyrussel + zanish theme 4 | 5 | Displays the time from last git commit. -------------------------------------------------------------------------------- /sfistak.zsh-theme: -------------------------------------------------------------------------------- 1 | # Determine the time since last commit. If branch is clean, 2 | # use a neutral color, otherwise colors will vary according to time. 3 | function git_time_since_commit() { 4 | if git rev-parse --git-dir > /dev/null 2>&1; then 5 | # Only proceed if there is actually a commit. 6 | if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then 7 | # Get the last commit. 8 | last_commit=`git log --pretty=format:'%at' -1 2> /dev/null` 9 | now=`date +%s` 10 | seconds_since_last_commit=$((now-last_commit)) 11 | 12 | # Totals 13 | MINUTES=$((seconds_since_last_commit / 60)) 14 | HOURS=$((seconds_since_last_commit/3600)) 15 | 16 | # Sub-hours and sub-minutes 17 | DAYS=$((seconds_since_last_commit / 86400)) 18 | SUB_HOURS=$((HOURS % 24)) 19 | SUB_MINUTES=$((MINUTES % 60)) 20 | 21 | if [[ -n $(git status -s 2> /dev/null) ]]; then 22 | if [ "$MINUTES" -gt 30 ]; then 23 | COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG" 24 | elif [ "$MINUTES" -gt 10 ]; then 25 | COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM" 26 | else 27 | COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT" 28 | fi 29 | else 30 | COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" 31 | fi 32 | 33 | if [ "$HOURS" -gt 24 ]; then 34 | echo "($COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|" 35 | elif [ "$MINUTES" -gt 60 ]; then 36 | echo "($COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|" 37 | else 38 | echo "($COLOR${MINUTES}m%{$reset_color%}|" 39 | fi 40 | else 41 | COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" 42 | echo "($COLOR~|" 43 | fi 44 | fi 45 | } 46 | PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_time_since_commit)$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}' 47 | 48 | ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[red]%}" 49 | ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" 50 | ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗%{$reset_color%}" 51 | ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})" 52 | # Colors vary depending on time lapsed. 53 | ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}" 54 | ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}" 55 | ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}" 56 | ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}" --------------------------------------------------------------------------------