Last active
October 21, 2018 17:23
-
-
Save AndrewRadev/62e49b55706f6b2f182e0c40fcd2d60e to your computer and use it in GitHub Desktop.
Keep track of a long-running process
This file contains 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
# 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