X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=zsh%2Frc;h=c3fd79fc9544cdd7b1fb493ef8c318cf9eff64dc;hb=b6ec7a5cd9626062f51f88437b7b4ee4323e85a2;hp=e2f7f9ccea2b86620aa9ffe62c8070ff5065f480;hpb=8bae2dfd3bcedce28e8e1d86d878cc3eaa83e21f;p=config%2Fdotfiles.git diff --git a/zsh/rc b/zsh/rc index e2f7f9c..c3fd79f 100644 --- a/zsh/rc +++ b/zsh/rc @@ -265,6 +265,46 @@ else RUN_VCS_INFO= fi +typeset -a longrun_data +longrun_data=() +# Display runtime in seconds for long running programs (> 60 seconds) and send +# a bell to notify me. +longrun_preexec() { + # 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 $3 in + $ignore | $ignore\ *) + longrun_data=() + return + ;; + esac + done + + longrun_data=("$3" $EPOCHSECONDS) +} +longrun_precmd() { + # No previous timestamp available or disabled for this command, ignore. + if [[ -z $longrun_data ]]; then + return + fi + + local difference=$(( EPOCHSECONDS - longrun_data[2] )) + if [[ $difference -gt 60 ]]; then + echo + echo -n "${fg[yellow]}" + echo -n "~> ${(V)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. + longrun_data=() +} +preexec_functions+=(longrun_preexec) +precmd_functions+=(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, @@ -773,9 +813,12 @@ exec 2>>(while read -r -k -u 0 line; do print -n $'\0'; done &) -# Run reminder and redisplay it every four hours (if it's available). +# Run the following programs every 4 hours. PERIOD=14400 periodic() { + # Display fortunes. + (( $+commands[fortune] )) && fortune -ac + # Display reminders. (( $+commands[rem] )) && [ -f ~/.reminders ] && rem -h }