Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Last active October 21, 2018 17:23
Show Gist options
  • Save AndrewRadev/62e49b55706f6b2f182e0c40fcd2d60e to your computer and use it in GitHub Desktop.
Save AndrewRadev/62e49b55706f6b2f182e0c40fcd2d60e to your computer and use it in GitHub Desktop.
Keep track of a long-running process
# Given a long-running process in the terminal:
#
# - Ctrl+Z to suspend it
# - Run `keep-track`
# - Output resumes, when done will show a notification with the time it took for the process to run
#
# Can be customized with an `--icon` to `notify-send`,
# maybe a sound effect added in the `&&` list.
#
function keep-track() {
last_command=$(history | tail -1 | cut -d' ' -f3-)
pid=$(jobs -p | sed 's/.*+\s*\([0-9]\+\) suspended.*/\1/' | head -1)
start_time=$(date --date="$(ps -p $pid -o lstart | tail -1)" +%s)
fg && notify-send "keep-track" "Done: $last_command, Time: $(expr $(date +%s) - $start_time)s"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment