Skip to content

Instantly share code, notes, and snippets.

@klmr
Last active August 29, 2015 14:27
Show Gist options
  • Save klmr/f8890faa8a72957a4dd3 to your computer and use it in GitHub Desktop.
Save klmr/f8890faa8a72957a4dd3 to your computer and use it in GitHub Desktop.
Command line drop-in substitute to log diagnostics; simply create a symlink to this wrapper with the target somewhere inside the $PATH, and its name that of a tool to wrap.
#!/usr/bin/env bash
logfile="${SHELL_USAGE_LOG-$HOME/shell-usage.log}"
cmd=$(basename "$0")
real_cmd=$(type -ap "$cmd" | sed -n 2p)
echo "[$(date +"%Y-%m-%dT%H:%M")] $(whoami) $SHELL $cmd" >> "$logfile"
$real_cmd "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment