Skip to content

Instantly share code, notes, and snippets.

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 motemen/6697410 to your computer and use it in GitHub Desktop.
Save motemen/6697410 to your computer and use it in GitHub Desktop.
User: motemen
Host: dominica.local
Date: 2013年 9月25日 水曜日 18時40分43秒 JST
Directory: /Users/motemen/work/op
Git-Revision: 568cc195834d2bc6a94dfe5e69620d92433e1dfa (master)
% ruby -e 3.times { |i| p i; sleep 1 }; abort 'bye'
[Wed Sep 25 18:40:44 2013] OUT 0
[Wed Sep 25 18:40:45 2013] OUT 1
[Wed Sep 25 18:40:46 2013] OUT 2
[Wed Sep 25 18:40:47 2013] ERR bye
dominica.local% op-run ruby -e "3.times { |i| p i; sleep 1 }; abort 'bye'"
Log file is '20130925_184043.ruby_-e_3.times____i__p_i__sleep_1____abort__bye_.log'
[Wed Sep 25 18:40:44 2013] OUT 0
[Wed Sep 25 18:40:45 2013] OUT 1
[Wed Sep 25 18:40:46 2013] OUT 2
[Wed Sep 25 18:40:47 2013] ERR bye
#!/bin/bash
command_line="$@"
log_file=$(date +%Y%m%d_%H%M%S).${command_line//[^a-zA-Z0-9._-]/_}.log
echo Log file is \'$log_file\' >&2
echo "User: $USER" >> $log_file
echo "Host: $(uname -n)" >> $log_file
echo "Date: $(date)" >> $log_file
echo "Directory: $PWD" >> $log_file
git_revision=$(git rev-parse HEAD 2> /dev/null)
if [ -n "$git_revision" ]; then
git_revision="$git_revision ($(git name-rev --name-only HEAD 2> /dev/null))"
if git diff --quiet && git diff --cached --quiet; then
:
else
dirty=' (dirty)'
fi
echo "Git-Revision: $git_revision$dirty" >> $log_file
fi
echo >> $log_file
echo "% $@" >> $log_file
{ "$@" > >(perl -pe '$|=1; $_="[${\~~localtime}] OUT $_"') 2> >(perl -pe '$|=1; $_="[${\~~localtime}] ERR $_"' >&2); } 2>&1 | tee -a $log_file
${PAGER-less} $log_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment