+
+ # Display number of WIP stashes (this excludes manually named commits
+ # which might be used for something else), thanks to
+ # http://eseth.org/2010/git-in-zsh.html (viewed on 2013-04-27) for the
+ # idea to display the stash count.
+ function +vi-git-stashes() {
+ if [[ -s ${hook_com[base]/.git/refs/stash} ]]; then
+ local -a stashes
+ # Thanks to Valodim in #zsh on Freenode (2013-07-01 14:14 CEST)
+ # for the solution to "grep" the output with (M) and :#(...).
+ stashes=( ${(M)${(f)"$(git stash list 2>/dev/null)"}:#(*WIP*)} )
+
+ if [[ ${#stashes} -gt 0 ]]; then
+ hook_com[misc]+=" ${yellow}${#stashes}s${default}"
+ fi
+ fi
+ }
+
+ # Apply hooks to Git.
+ zstyle ':vcs_info:git*+set-message:*' hooks git-stashes
+
+ # Must run vcs_info when changing directories.
+ prompt_chpwd() {
+ zshrc_force_run_vcs_info=1
+ }
+ chpwd_functions+=(prompt_chpwd)
+
+ # Used by prompt code below to determine if vcs_info should be run.
+ zshrc_use_vcs_info=1
+else
+ zshrc_use_vcs_info=
+fi
+
+typeset -a zshrc_longrun_data
+zshrc_longrun_data=()
+# Display runtime in seconds for long running programs (> 60 seconds) and send
+# a bell to notify me.
+zshrc_longrun_preexec() {
+ local program="$3"
+
+ # Handle fg.
+ local REPLY
+ zshrc_resolve_fg_to_resumed_job_name "$program"
+ program="$REPLY"
+
+ # Don't track the time for certain (possible) long running processes which
+ # need no automatic notification.
+ for ignore in elinks man mutt vim; do
+ case $program in
+ $ignore | $ignore\ *)
+ zshrc_longrun_data=()
+ return
+ ;;
+ esac
+ done
+
+ zshrc_longrun_data=("$program" $EPOCHSECONDS)
+}
+zshrc_longrun_precmd() {
+ # No previous timestamp available or disabled for this command, ignore.
+ if [[ -z $zshrc_longrun_data ]]; then
+ return
+ fi
+
+ local difference=$(( EPOCHSECONDS - zshrc_longrun_data[2] ))
+ if [[ $difference -gt 60 ]]; then
+ echo
+ echo -n "${fg[yellow]}"
+ echo -n "~> ${(V)zshrc_longrun_data[1]} took $difference seconds."
+ echo -n "${fg[default]}"
+ echo "\a" # send bell
+ fi
+
+ # Clear status. Prevents displaying old status information when pressing
+ # enter with an empty command line.
+ zshrc_longrun_data=()
+}
+preexec_functions+=(zshrc_longrun_preexec)
+precmd_functions+=(zshrc_longrun_precmd)
+
+# Set the prompt. A two line prompt is used. On the top left the current
+# working directory is displayed, on the right vcs_info (if available) and the
+# current time in hex. On the bottom left current user name and host is shown,
+# the exit code of the last command if it wasn't 0, the number of running jobs
+# if not 0.
+#
+# The prompt is in green and blue to make easily detectable, the error exit
+# code in red and bold and the job count in yellow. Designed for dark
+# terminals.
+#
+# Thanks to Adam's prompt for the basic idea of this prompt.
+zshrc_prompt_precmd() {
+ # Regex to remove elements which take no space. Used to calculate the
+ # width of the top prompt. Thanks to Bart's and Adam's prompt code in
+ # Functions/Prompts/prompt_*_setup.
+ local zero='%([BSUbfksu]|([FB]|){*})'
+
+ # Call vcs_info before every prompt.
+ if [[ -n $zshrc_use_vcs_info ]]; then
+ vcs_info