Skip to content

Instantly share code, notes, and snippets.

@amitu
Created August 8, 2019 07:53
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 amitu/4277f8cc55e008b53f86ba5e6fab8d70 to your computer and use it in GitHub Desktop.
Save amitu/4277f8cc55e008b53f86ba5e6fab8d70 to your computer and use it in GitHub Desktop.
~/cmd.log
preexec () {
START="$(python -c 'import time; print(time.time())')"
LAST_CMD=$1
export SHELL_ID="$(python -c 'import uuid; print(uuid.uuid4())')"
}
precmd () {
LAST=$?
if [ -z ${START} ];
then
else
echo -n "Executed [$LAST_CMD: $LAST] in "
~/bin/precmd "$START" "$LAST_CMD" "$LAST"
fi
unset LAST
unset LAST_CMD
unset START
}
#!/usr/bin/python
import sys
import os
import time
START = float(sys.argv[1])
CMD = sys.argv[2]
CODE = sys.argv[3]
PWD = os.getcwd().replace("/Users/amitu", "~")
SHELL = os.environ["SHELL_ID"]
DURATION = time.time() - START
print('%0.3fs.' % DURATION)
DURATION = int(DURATION * 1000)
file("/Users/amitu/cmd.log", "a+").write(
"%(START)s|%(SHELL)s|%(PWD)s|%(CODE)s|%(DURATION)s|%(CMD)s\n" % locals()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment