Add to ~/.zshrc
zplug "matrixik/d28c717108b0c1bfad233588da5cac31", \
from:gist, \
as:themeFix for prezto
# Fix for Soup theme
zstyle ':prezto:module:git:info' verbose yes
| # | |
| # A simple theme that only shows relevant information. | |
| # | |
| # Authors: | |
| # Soup | |
| # Fixes by: | |
| # Dobrosław Żybort <[email protected]> | |
| # Inspiration: | |
| # Jack Chen <[email protected]> | |
| # Sorin Ionescu <[email protected]> | |
| # | |
| # Screenshots: | |
| # http://i.imgur.com/aipDQ.png | |
| # | |
| function prompt_soup_precmd { | |
| # Save option state | |
| # Any options will be reverted when this function ends. | |
| setopt LOCAL_OPTIONS | |
| # Don't print any command results results, | |
| # Use KSH style arrays | |
| unsetopt XTRACE KSH_ARRAYS | |
| # set pwd variable | |
| prompt_soup_pwd | |
| # attempt to get git info if its around | |
| if (( $+functions[git-info] )); then | |
| git-info | |
| fi | |
| } | |
| # Colors vary depending on time lapsed. | |
| ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%F{green}" | |
| ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%F{yellow}" | |
| ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%F{red}" | |
| ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%F{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 30 ]; then | |
| COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG" | |
| elif [ "$MINUTES" -gt 10 ]; 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%f]" | |
| elif [ "$MINUTES" -gt 60 ]; then | |
| echo "[$COLOR${HOURS}h${SUB_MINUTES}m%f]" | |
| else | |
| echo "[$COLOR${MINUTES}m%f]" | |
| fi | |
| else | |
| COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" | |
| echo "[$COLOR~%f]" | |
| fi | |
| fi | |
| } | |
| function prompt_soup_pwd { | |
| # Get repo root dir name if its present in our path | |
| local repo="${$(git rev-parse -q --show-toplevel 2> /dev/null):t}" | |
| n=3 # n = number of directories to show in full (n = 3, /u/b/c/dfull/efull/ffull) | |
| pwd=${${PWD}/#${HOME}/\~} | |
| # split our path on / | |
| dirs=("${(s:/:)pwd}") | |
| dirs_length=$#dirs | |
| if [[ $dirs_length -ge $n ]]; then | |
| # we have more dirs than we want to show in full, so compact those down | |
| ((max=dirs_length - n)) | |
| for (( i = 1; i <= $max; i++ )); do | |
| local step="$dirs[$i]" | |
| if [[ -z $step ]]; then | |
| continue | |
| fi | |
| if [[ "$step" == "$repo" ]]; then | |
| # don't contract our repo dir | |
| dirs[$i]=$step | |
| else | |
| if [[ $step =~ "^\." ]]; then | |
| dirs[$i]=$step[0,3] #make .mydir => .my | |
| else | |
| dirs[$i]=$step[0,2] # make mydir => my | |
| fi | |
| fi | |
| done | |
| fi | |
| # underline our git repo root dir if present | |
| for (( i = 1; i <= $dirs_length; i++ )); do | |
| local step="$dirs[$i]" | |
| if [[ "$step" == "$repo" ]]; then | |
| # underline seems to stop path color | |
| dirs[$i]="%F{cyan}%U$step%u%F{cyan}" | |
| fi | |
| done | |
| _prompt_soup_pwd="%F{cyan}${(j:/:)dirs}%{$reset_color%}" | |
| } | |
| function prompt_soup_setup { | |
| setopt LOCAL_OPTIONS | |
| unsetopt XTRACE KSH_ARRAYS | |
| prompt_opts=(cr percent subst) | |
| # Load required functions. | |
| autoload -Uz add-zsh-hook | |
| # Add hook for calling git-info before each command. | |
| add-zsh-hook precmd prompt_soup_precmd | |
| # zsh styles | |
| zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b' | |
| zstyle ':prezto:module:editor:info:keymap:primary' format ' %B%F{red}❯%F{yellow}❯%F{green}❯%f%b' | |
| zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format ' %F{red}♺%f' | |
| zstyle ':prezto:module:editor:info:keymap:alternate' format ' %B%F{green}❮%F{yellow}❮%F{red}❮%f%b' | |
| # Git styling | |
| # see modules/git/git-info for details | |
| zstyle ':prezto:module:git:info' verbose yes | |
| zstyle ':prezto:module:git:info:action' format ':%%B%F{yellow}%s%f%%b' | |
| zstyle ':prezto:module:git:info:added' format ' %%B%F{green}✚%f%%b' | |
| zstyle ':prezto:module:git:info:ahead' format ' %%B%F{yellow}⬆%f%%b' | |
| zstyle ':prezto:module:git:info:behind' format ' %%B%F{yellow}⬇%f%%b' | |
| zstyle ':prezto:module:git:info:dirty' format '%B%F{red}⚡%f%b' | |
| zstyle ':prezto:module:git:info:clean' format '%B%F{green}✔%f%b' | |
| zstyle ':prezto:module:git:info:branch' format '%F{yellow}%b%f' | |
| zstyle ':prezto:module:git:info:commit' format ':%F{green}%.7c%f' | |
| zstyle ':prezto:module:git:info:deleted' format ' %%B%F{red}✖%f%%b' | |
| zstyle ':prezto:module:git:info:modified' format ' %%B%F{blue}✱%f%%b' | |
| zstyle ':prezto:module:git:info:position' format ':%F{green}%p%f' | |
| zstyle ':prezto:module:git:info:renamed' format ' %%B%F{magenta}➜%f%%b' | |
| zstyle ':prezto:module:git:info:stashed' format ' %%B%F{cyan}✭%f%%b' | |
| zstyle ':prezto:module:git:info:unmerged' format ' %%B%F{yellow}═%f%%b' | |
| zstyle ':prezto:module:git:info:untracked' format ' %%B%F{white}◼%f%%b' | |
| zstyle ':prezto:module:git:info:keys' format \ | |
| 'prompt' '%F{yellow}<%f%b:%D%C%F{yellow}>%f' \ | |
| 'rprompt' '%A%B%S%a%d%m%r%U%u' | |
| # RPROMPT='${editor_info[keymap]}${editor_info[overwrite]}%(?:: %F{red}⏎%f)${VIM:+" %B%F{green}V%f%b"}${git_info[rprompt]}' | |
| PROMPT=' | |
| %F{blue}%n@%m%f:%F{cyan}${_prompt_soup_pwd}%f ${git_info:+${(e)git_info[prompt]}} | |
| %F{red}%D{%H:%M:%S} %F{yellow}λ%f %{$reset_color%}' | |
| PS2=" ... " | |
| RPROMPT='${return_status} $(git_time_since_commit)${git_info:+${(e)git_info[rprompt]}}%{$reset_color%}' | |
| SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? ' | |
| } | |
| #Auto call our setup method after file load. | |
| prompt_soup_setup "$@" |