+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
+ else
+ vcs_info_msg_0_=
+ vcs_info_msg_1_=
+ fi
+
+ # Setup. Create variables holding the formatted content.
+
+ # Current directory in yellow, truncated if necessary (WIDTH is replaced
+ # below).
+ local directory="${yellow}%WIDTH<..<%~%<<${default}"
+ # Minimal information about the VCS, only displayed if there are
+ # unstaged/staged changes.
+ local vcs_staged="${vcs_info_msg_1_}"
+
+ # Information about the VCS in this directory.
+ local vcs="${vcs_info_msg_0_}"
+ # Current time (seconds since epoch) in Hex in bright blue.
+ local seconds="${blue}%B0x$(([##16] EPOCHSECONDS))%b${default}"
+
+ # User name (%n) in bright green.
+ local user="${green}%B%n%b${default}"
+ # Host name (%m) in bright green; underlined if running on a remote system
+ # through SSH.
+ local host="${green}%B%m%b${default}"
+ if [[ -n $SSH_CONNECTION ]]; then
+ host="%U${host}%u"
+ fi
+
+ # Number of background processes in yellow if not zero.
+ local background="%(1j.${yellow}%j${default}.)"
+ # Exit code in bright red in parentheses if not zero.
+ local exitcode="%(?..(${red}%B%?%b${default}%) )"
+ # Prompt symbol, % for normal users, # in red for root.
+ local symbol="%(!.${red}#${default}.%%)"
+
+ # Prefix characters in first and second line.
+ local top_prefix="${blue}%B.-%b${default}"
+ local bottom_prefix="${blue}%B'%b${default}"
+
+ # Combine them to create the prompt.
+
+ local top_left="${vcs_staged}"
+ local top_right="${vcs}(${seconds})"
+
+ local width_top_prefix=${#${(S%%)top_prefix//$~zero/}}
+ local width_top_left=${#${(S%%)top_left//$~zero/}}
+ local width_top_right=${#${(S%%)top_right//$~zero/}}
+
+ # Calculate the maximum width of ${top_left}. -2 are the braces of
+ # ${top_left}, -1 is one separator from ${top_separator} (we want at least
+ # one between left and right parts).
+ local top_left_width_max=$((
+ COLUMNS - $width_top_prefix
+ - $width_top_left - 2
+ - 1
+ - $width_top_right
+ ))
+ # Truncate directory if necessary.
+ top_left="(${directory/WIDTH/${top_left_width_max}})${top_left}"
+ width_top_left=${#${(S%%)top_left//$~zero/}}
+
+ # Calculate the width of the top prompt to fill the middle with "-".
+ local width=$((
+ COLUMNS - width_top_prefix - width_top_left - width_top_right
+ ))
+ local top_separator="%B${blue}${(l:${width}::-:)}%b${default}"
+
+ PROMPT="${top_prefix}${top_left}${top_separator}${top_right}
+${bottom_prefix}${user}@${host} ${background}${symbol} ${exitcode}"
+}
+precmd_functions+=(zshrc_prompt_precmd)
+
+
+# When GNU screen, tmux, xterm or rxvt is used set the name of the window to
+# the currently running program.