• 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 "$LOGPATH" ] && export LOGPATH="$PWD"/log.txt
7
8if [ ${#BASH_SOURCE[@]} -lt 2 ] && [ $# -eq 0 ]
9then
10  echo "usage: WRAPDIR=dir LOGPATH=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/logpath" ]
16then
17  mkdir -p "$WRAPDIR" && PREFIX="$WRAPDIR/" scripts/single.sh logpath || exit 1
18  echo "$PATH" | tr : '\n' | while read DIR
19  do
20    find "$DIR/" -type f,l -maxdepth 1 -executable -exec basename {} \; | \
21    while read FILE
22    do
23      ln -s logpath "$WRAPDIR/$FILE" 2>/dev/null
24    done
25  done
26fi
27
28# Delete old log (if any)
29rm -f "$LOGPATH"
30
31# When sourced, set up wrapper for current context.
32export PATH="$WRAPDIR:$PATH"
33if [ ${#BASH_SOURCE[@]} -lt 2 ]
34then
35  "$@"
36  X=$?
37
38  [ ! -z "$RM" ] && "$RM" -rf "$WRAPDIR"
39
40  exit $X
41fi
42
43