Created
August 8, 2019 07:53
-
-
Save amitu/4277f8cc55e008b53f86ba5e6fab8d70 to your computer and use it in GitHub Desktop.
~/cmd.log
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
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 | |
} |
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/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