• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8if [ $# -eq 0 ]
9then
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
13fi
14
15if [ ! -x "$WRAPDIR/logwrapper" ]
16then
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
27fi
28
29# Delete old log (if any)
30rm -f "$WRAPLOG"
31
32X=0
33if [ ! -z "$1" ]
34then
35  PATH="$WRAPDIR:$PATH" "$@"
36fi
37X=$?
38[ ! -z "$RM" ] && "$RM" -rf "$WRAPDIR"
39
40exit $X
41