#!/bin/bash # # Reconstruct: Build a new xterm out of old TR state dump. # Karl Kleinpaste, Just Research, February/March 1999. # # Usage: Reconstruct [-n] [-r] [dump] # -n: no destruction of reconstruction source files. # -r: start TR in the reconstructed shell. # No dump specified -> use stdin # newrecall='#' save='' while [ "$1" = "-n" -o "$1" = "-r" ] ; do case "$1" in -n ) shift ; save='#' ;; -r ) shift ; newrecall='' ;; esac done # # make working files in a sensible directory. TMPDIR="${RECALL_DUMP:-/tmp}" mkdir -p "$TMPDIR" # # identify program for stuffing a command into the pty. STI=/home/karl/bin/i686/sti # # get the dump file, either argv1 or stdin. if [ "$#" -eq 0 ] ; then TMP=""$TMPDIR"/reconstruct.data-$$" trap "rm $TMP" EXIT cat - > "$TMP" else TMP="$1" shift fi if [ "$#" -ne 0 ] ; then echo Usage: 'Reconstruct -n [dump]' exit 1 fi # # get xterm geometry. GEOMETRY="`grep -e '^-geometry [0-9]*x[0-9]*$' "$TMP" | head -1`" # # define the temporary files to be inhaled and run. export RECON=""$TMPDIR"/reconstruct.script-$$" export HISTFILE=""$TMPDIR"/reconstruct.history-$$" # # extract the history. sed -e '1,/^--history-begin$/d' -e '/^--history-end$/,$d' -e 's/^ *[0-9]* //' < "$TMP" > $HISTFILE # (nothing more need be done w/history -- bash will find it on its own.) # # create the startup script. # fix histfile problem first. export defunctHISTFILE="$HISTFILE" # tell user what's up. cat > "$RECON" <> $RECON eval `grep RECALL_TIMESTAMP $RECON` # get dirstack elements. dirlist="`sed -e '1,/^--dirstack-begin$/d' -e '/^--dirstack-end$/,$d' < $TMP`" # add dirstack initialization. cat >> "$RECON" < /dev/null dcmd="builtin pushd" dirnum=\$[\$dirnum-1] done echo -ne "\033]0;Total Recall: Shell Reconstruction ${RECALL_TIMESTAMP}\007" ${save}rm "\$RECON" "\$defunctHISTFILE" ${newrecall}. Recall unset RECON defunctHISTFILE dcmd dirlist dirnum EOF # needs to be executable. chmod 700 "$RECON" # # start an xterm, with proper geometry, initialized from startup. cd xterm $GEOMETRY -e bash -c "stty -echo ; $STI \". $RECON \" ; stty echo ; exec $SHELL" < /dev/null > /dev/null 2>&1 & exit 0