3 if command -v script &> /dev/null;
7 TIMESTAMP="$(date '+%Y-%m-%d-%H:%M:%S')"
9 # The trick here is to use 'type' to eat any leading environment variables
10 # and get to the command name.
11 COMMAND_NAME="$(type -P "$@" 2>/dev/null | cut -d ' ' -f 1)"
13 [ "x$COMMAND_NAME" = "x" ] && return 1
15 # Escape the argument so that it can be reused as shell input
16 # NOTE: this is Bash specific.
17 COMMAND_ESCAPED=$(printf "%q " "$@")
19 script -q -e -c "$COMMAND_ESCAPED" "${TIMESTAMP}_$(basename "$COMMAND_NAME").log"
21 complete -F _command record