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 [ ! -x "$WRAPDIR/logpath" ] 9then 10 LOG="$(which logpath)" 11 mkdir -p "$WRAPDIR" || exit 1 12 [ -e "$LOG" ] && cp -H "$LOG" "$WRAPDIR/logpath" || { cd "$(dirname $0)/.." && 13 PREFIX="$WRAPDIR/" scripts/single.sh logpath >/dev/null && 14 LOG="$PWD/logpath" || exit 1; } 15 tr : '\n' <<< "$PATH" | while read i; do 16 find "$i" \( -type f -o -type l \) -maxdepth 1 -executable -exec basename {} \; | \ 17 while read FILE; do ln -s logpath "$WRAPDIR/$FILE" 2>/dev/null; done 18 done 19fi 20 21# Delete old log (if any) 22rm -f "$LOGPATH" 23 24# When sourced, set up wrapper for current context. 25if [ $# -gt 0 ] 26then 27 PATH="$WRAPDIR:$PATH" "$@" 28 X=$? 29 [ -n "$RM" ] && "$RM" -rf "$WRAPDIR" 30 31 exit $X 32else 33 echo export LOGPATH=${LOGPATH@Q} PATH=${WRAPDIR@Q}:${PATH@Q} 34fi 35 36