Skip to content
Bash extension for printing execution time for each command.
Branch: master
Clone or download
Latest commit 3f35429 Apr 24, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Initial functional commit. Jun 9, 2014
LICENSE
README.md Update README.md Apr 24, 2017
bash_command_timer.sh - Added option to wrap to the next line if our output would overwrite May 23, 2016
bash_command_timer_screenshot.gif Add demo screenshot. Jun 9, 2014

README.md

bash-command-timer

Bash extension for printing timing information for each command line executed.

Usage

After the execution of each command line, the script prints out the total execution time (up to millisecond precision), followed by the current time. The execution time is formatted to be human readable; e.g., 2h 7m 42s301.

Demo:

Demo Screen-cap

Requirements

This script should run pretty much out of the box on modern Linux and Mac OS X systems. Please report any incompatibilities on on GitHub.

Note that this script will also conflict with any other script that uses the DEBUG trap and PROMPT_COMMAND.

Installation

To set up this extension, you can

  1. Download bash_command_timer.sh somewhere, and add the following to your ~/.bashrc (replace with actual path where you saved the script):

    source ~/.bash_command_timer.sh
  2. Alternatively, you can simply copy and paste the contents of bash_command_timer.sh into your ~/.bashrc.

That's it :)

Settings

You can use the following options to tweak the behavior of the script. You can either make the changes in-place (at the top of the script) or put them after sourcing the script in your .bashrc. You can also modify them on-the-fly if you want the changes to only affect your current Bash session.

  • BCT_ENABLE=1: Setting this to 0 disables the printing of timings.
  • BCT_COLOR='34': The color of the output. This should be a color string usable in a VT100 escape sequence (see Wikipedia), without the escape sequence prefix and suffix. For example, bold red would be '1;31'.
  • BCT_TIME_FORMAT='%b %d %I:%M%p': The display format of the current time. This is a strftime format string (see http://strftime.org/). If empty, the current time will not be printed.
  • BCT_MILLIS=1: Whether to print timings to millisecond precision. If set to zero, will print timings up to seconds.

Details

For an explanation of how the script works, you're welcome to check out my blog post: DEBUG trap and PROMPT_COMMAND in Bash.

You can’t perform that action at this time.