Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

De-script (Re: Vanishing files ?)



On May 29, 10:57am, Anssi Saari wrote:
}
} > }  By the way: Does anyone know a trick how to remove _all_
} > }  Escape-Sequences from a script generated by the command "script" ...
} > 
} > 	sed "s/[^"$'\t '"-~]//g"
} 
} That doesn't really work for escape sequences now does it?

Ah, I see, I misinterpreted the original question.  In order to strip
entire terminal-control strings, you have to know what they are; which
means in effect that you have to (a) read the termcap/terminfo database
and (b) know the value of $TERM at the time the typescript was created.

You could create something to do this using the perl Term::Cap and/or
Term::Info modules, or in zsh with zsh/termcap and zsh/terminfo.  The
tricky bit is knowing which escapes use numeric counts or positions, so
you can accept arbitrary digits at those locations.

E.g. this is an UNTESTED example of what might work in zsh:

    function descript {
        ( # Subshell for parent terminal sanity
        emulate -R zsh
        typeset -A tpat
        TERM=${1:-$TERM}
        # Replace terminfo + echoti with termcap + echotc as needed
        for key in ${(k)terminfo}
        do
            [[ $terminfo[$key] == (yes|no) ]] && continue
	    # Replace programmable digits with the <-> pattern.
	    # If you have a 1000x1000 or larger terminal, I give up.
            tpat[$key]=${${(q)"$(echoti $key 998 998)"//$'\0'/}//99[89]/<->}
            # Debugging output:
            # print -u2 -R $key = ${(V)tpat[$key]}
        done
        pat=${(j:|:)tpat}
        # Run through "col" first to handle simple cursor movement
        col -bp | while read -r line
        do
            print -R -- ${line//(${~pat})/}
        done
        )
    }

Usage is e.g.:

    descript color-xterm < typescript

Also realize that after you strip those, the result is no longer going
to resemble what was visible on the screen during the creation of the
typescript.



Messages sorted by: Reverse Date, Date, Thread, Author