Last active
August 29, 2015 14:02
-
-
Save wancw/f6d0e6634228cd9e3da3 to your computer and use it in GitHub Desktop.
Report elapsed time for command take long time to execute.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typeset -gaU preexec_functions | |
typeset -gaU precmd_functions | |
preexec_functions+='preexec_start_timer' | |
precmd_functions+='precmd_report_time' | |
_tr_current_cmd="?" | |
_tr_sec_begin="${SECONDS}" | |
_tr_ignored="yes" | |
TIME_REPORT_THRESHOLD=${TIME_REPORT_THRESHOLD:=30} | |
function preexec_start_timer() { | |
if [[ "x$TTY" != "x" ]]; then | |
_tr_current_cmd="$2" | |
_tr_sec_begin="$SECONDS" | |
_tr_ignored="" | |
fi | |
} | |
function precmd_report_time() { | |
local te | |
te=$((${SECONDS}-${_tr_sec_begin})) | |
if [[ "x${_tr_ignored}" = "x" && $te -gt $TIME_REPORT_THRESHOLD ]] ; then | |
_tr_ignored="yes" | |
echo "\`${_tr_current_cmd}\` completed in ${te} seconds." | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment