Coder Social home page Coder Social logo

typescript_cleaner's Introduction

typescript_cleaner.py

A simple utility to clean shell typescript files by removing terminal escape sequences and (optionally) applying backspace characters.

Typescript files (created using the script command) contain escape sequences for backspaces, font colors, tab completion, etc., which make them difficult to read (without using cat) or grep through. This utility aims to fix that. Just provide one or more typescript filepaths as an argument, and the script will automatically remove escape sequences (optionally leaving BELL and/or backspace characters) and output the result to a matching file with _cleaned appended to the filename. Files that contain _cleaned as a suffix as assumed to have already been cleaned and will be skipped.

Requires Python 3.6+ due to use of type hinting.

Usage


python3 typescript_cleaner.py [-h] [--keep_backspace] [--keep_bell] [filepaths ...]

Cleans shell typescript files by removing terminal escape sequences and applying backspace characters

positional arguments:
  filepaths         Paths to typescript files (i.e., logs created using the "script" command)

optional arguments:
  -h, --help        show this help message and exit
  --keep_backspace  Keep BACKSPACE characters; useful for identifying things typed accidentally (like passwords)
  --keep_bell       Keep BELL characters; useful for identifying tab completion

Examples


# Create a typescript
script -f ssh_session_$(date +%F).log

# Remove all escape sequences and metacharacters
python3 typescript_cleaner.py ssh_session_2022-09-24.log

# Remove all escape sequences and metacharacters and files in and below the 'logs' directory
python3 typescript_cleaner.py ./logs

# Keep BELL characters (to show tab completion)
python3 typescript_cleaner.py -keep_bell ssh_session_2022-09-24.log

# Keep BACKSPACE characters
python3 typescript_cleaner.py -keep_backspace ssh_session_2022-09-24.log

# Keep BACKSPACE and BELL characters
python3 typescript_cleaner.py -keep_backspace -keep_bell ssh_session_2022-09-24.log

typescript_cleaner's People

Contributors

breakid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.