Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing MS Word .docx files in Midnight Commander

Tags:

docx

mc

I want to be able to quickly view (with F3) the content of Word doc/docx files in Midnight Commander. MC's extensions file calls /usr/lib/mc/ext.d/doc.sh, which contains wv, antiword, catdoc, and word2x as helper programs. On my system (debian), the first three are available, but none of them are able to deal with the newer docx format.

The obvious solution is to use LibreOffice:

libreoffice --headless --convert-to "txt:Text (encoded):UTF8" filename.docx

This works well, but how do I tell MC to use it and display the result of the conversion? If I put this in ~/.config/mc/mc.ext, replacing the lines

View=%view{ascii} /usr/lib/mc/ext.d/doc.sh view msdoc

with

View=libreoffice --headless --convert-to "txt:Text (encoded):UTF8" "${MC_EXT_FILENAME}"

then I end up with a filename.txt file in the current directory, and nothing is displayed. What I want to happen is for mc to do the conversion when I press F3 and discard it when I quit the viewer. (I guess the converted file would be written to /tmp/ and removed on quit.)

Bonus: it would be nice if the displayed file would be word-wrapped, I suppose that could be done by using the wrap command?

Can I do this without having to modify /usr/lib/mc/ext.d/doc.sh, in my ~/.config/mc/mc.ext?

like image 590
GrB Avatar asked Oct 12 '25 12:10

GrB


1 Answers

I use docx2txt:

View=%view{ascii} docx2txt %f -

Also you don't need such a long conversion string in libreoffice.

libreoffice --cat %f

is enough.

like image 152
phd Avatar answered Oct 16 '25 09:10

phd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!