Created
September 25, 2013 09:48
-
-
Save motemen/6697410 to your computer and use it in GitHub Desktop.
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
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 |
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
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 |
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
#!/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