How to add a custom parser for a file type into MC viewer?

1

When you press F3 on a .sqlite file in midnight commander the Viewer shows the SQL dump of the file instead of the original binary, and F8 can be used to switch between parsed and raw modes.

This behaviour is available for quite a few other file types, e.g. F3 on a .zip file will list the file contents, on a .doc file will pipe the file through antiword, .pdf gets piped through pdftotext etc.

Is it possible to add your own parsers for custom file types?

ccpizza

Posted 2018-03-25T12:11:07.367

Reputation: 5 372

Answers

3

Yes, it is possible. Take a look at /etc/mc/mc.ext: programs and file type associations are defined there. For example, here are associations for zip, sqlite and doc that you mentioned:

# sqlite3.db
type/^SQLite 3.x database
    Open=/usr/lib/mc/ext.d/misc.sh open sqlite
    View=%view{ascii} /usr/lib/mc/ext.d/misc.sh view sqlite

# zip
type/^([Zz][Ii][Pp])\ archive
    Open=%cd %p/uzip://
    View=%view{ascii} unzip -v %f

# Microsoft Word Document
regex/\.([Dd][oO][cCtT]|[Ww][rR][iI])$
    Open=(lowriter %f >/dev/null 2>&1 &)
    View=%view{ascii} antiword -t %f || catdoc -w %f || word2x -f text %f - || strings %f

You can read about mc.ext syntax in comments in the beginning of the file: https://github.com/MidnightCommander/mc/blob/master/misc/mc.ext.in.

Here is a relevant article: https://ubuntuincident.wordpress.com/2010/12/08/configure-mc-open-files/

baltazar

Posted 2018-03-25T12:11:07.367

Reputation: 401