O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



View microsoft word documents with less
Hack #52 in Linux Destop Hacks introduced wvWare doc viewer. This hack allows it to be used in conjunction with the pager less.

Contributed by:
trexx
[04/20/05 | Discuss (0) | Link to this hack]

The pager less allows for an INPUT PREPROCESSOR. This is pointed to by the environment variable LESSOPEN. Adding the following line to the function lesspipe allows less to page the output of the MS Word document.

  *.doc|*.DOC)  wvWare -x /usr/local/share/wv/wvText.xml  "$1"
the complet lesspipe.sh I use in </#!/bin/sh - # # To use this filter with less, define LESSOPEN: # export LESSOPEN="|/usr/bin/lesspipe.sh %s" lesspipe() { case "$1" in *.[1-9n]|*.man|*.[1-9n].bz2|*.man.bz2|*.[1-9].gz|*.[1-9]x.gz|*.[1-9].man.gz) case "$1" in *.gz) DECOMPRESSOR="gunzip -c" ;; *.bz2) DECOMPRESSOR="bunzip2 -c" ;; *) DECOMPRESSOR="cat" ;; esac if $DECOMPRESSOR -- "$1" | file - | grep -q troff; then if echo "$1" | grep -q ^/; then #absolute path man -- "$1" | cat -s else man -- "./$1" | cat -s fi else $DECOMPRESSOR -- "$1" fi ;; *.tar) tar tvvf "$1" ;; *.jar) jar -tvvf "$1" ;; *.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1" ;; *.tar.bz2|*.tbz2) bzip2 -dc "$1" | tar tvvf - ;; *.[zZ]|*.gz) gzip -dc -- "$1" ;; *.bz2) bzip2 -dc -- "$1" ;; *.doc|*.DOC) wvWare -x /usr/local/share/wv/wvText.xml "$1" ;; *.zip) zipinfo -- "$1" ;; *.rpm) rpm -qpivl --changelog -- "$1" ;; *.cpi|*.cpio) cpio -itv < "$1" ;; esac } if [ -d "$1" ] ; then /bin/ls -alF -- "$1" else lesspipe "$1" 2> /dev/null fi code>

See also:


  • "View Microsoft Word Documents in a Terminal" (Linux Desktop Hacks #52)

  • man less


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.