1 #!/bin/bash 2 3 # Set up command recording wrapper 4 5 [ -z "$WRAPDIR" ] && WRAPDIR="$PWD"/record-commands && RM=$(which rm) 6 [ -z "$WRAPLOG" ] && export WRAPLOG="$PWD"/log.txt 7 8 if [ $# -eq 0 ] 9 then 10 echo "usage: WRAPDIR=dir WRAPLOG=log.txt record-commands COMMAND..." 11 echo 'Then examine log.txt. "record-commands echo" to just setup $WRAPDIR' 12 exit 1 13 fi 14 15 if [ ! -x "$WRAPDIR/logwrapper" ] 16 then 17 make logwrapper 18 mkdir -p "$WRAPDIR" && mv logwrapper "$WRAPDIR" || exit 1 19 20 echo "$PATH" | tr : '\n' | while read DIR 21 do 22 ls "$DIR/" | while read FILE 23 do 24 ln -s logwrapper "$WRAPDIR/$FILE" 2>/dev/null 25 done 26 done 27 fi 28 29 # Delete old log (if any) 30 rm -f "$WRAPLOG" 31 32 X=0 33 if [ ! -z "$1" ] 34 then 35 PATH="$WRAPDIR:$PATH" "$@" 36 fi 37 X=$? 38 [ ! -z "$RM" ] && "$RM" -rf "$WRAPDIR" 39 40 exit $X 41