Skip to content

Instantly share code, notes, and snippets.

@brianstorti
Created March 14, 2018 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianstorti/8ed8f467771de3eddb0c7d2eae79fbbe to your computer and use it in GitHub Desktop.
Save brianstorti/8ed8f467771de3eddb0c7d2eae79fbbe to your computer and use it in GitHub Desktop.
timing - script to prefix stdout with the executing time
#!/usr/bin/env bash
# Usage:
# $ command | timing
#
# Example:
# $ rails server | timing
# 00:00:00 | rails server -b 0.0.0.0
# 00:00:04 | => Booting Puma
# 00:00:04 | => Rails 5.1.3 application starting in development on http://0.0.0.0:3000
# 00:00:04 | => Run `rails server -h` for more startup options
# 00:00:04 | [11606] Puma starting in cluster mode...
# 00:00:04 | [11606] * Version 3.10.0 (ruby 2.4.2-p198), codename: Russell's Teapot
# 00:00:04 | [11606] * Min threads: 2, max threads: 4
# 00:00:04 | [11606] * Environment: development
# 00:00:04 | [11606] * Process workers: 3
# 00:00:04 | [11606] * Preloading application
# 00:00:05 | [11606] * Listening on tcp://0.0.0.0:3000
while read -r output; do
hours=$(($SECONDS / 3600 ))
minutes=$((($SECONDS % 3600) / 60))
seconds=$(($SECONDS % 60))
printf "\033[1;32m%02d:%02d:%02d |\033[00m %s\n" $hours $minutes $seconds "$output"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment