Created
March 14, 2018 18:09
-
-
Save brianstorti/8ed8f467771de3eddb0c7d2eae79fbbe to your computer and use it in GitHub Desktop.
timing - script to prefix stdout with the executing time
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
#!/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