Skip to content

Instantly share code, notes, and snippets.

@ubone

ubone/doc.md

Last active Oct 31, 2018
Embed
What would you like to do?

open .doc .docx .odt .rtf with leafpad and .djvu with mupdf

~/.local/share/applications/doc.desktop

[Desktop Entry]
Version=1.0
Name=Doc Viewer
Comment=Read doc docx and odt files
StartupNotify=false
Terminal=false
Icon=x-office-document
Type=Application
#Categories=Office;WordProcessor;
Exec=doc.sh %f

~/.local/bin/doc.sh

#!/bin/bash

case "$1" in
    *.doc)
        antiword -frs -i 1 "$1" > /tmp/antiword
        leafpad /tmp/antiword &
    ;;
    *.docx)
        docx2txt.sh "$1"
        (leafpad "${1%.*}".txt && rm "${1%.*}".txt) &
    ;;
    *.odt)
        odt2txt "$1" --width=-1 --output=/tmp/odt2txt
        leafpad /tmp/odt2txt &
    ;;
    *.rtf)
        unrtf "$1" --nopict --text --quiet > /tmp/unrtf
        leafpad /tmp/unrtf &
        unrtf "$1" --nopict --quiet > /tmp/unrtfhtml
        firefox --new-tab /tmp/unrtfhtml &
    ;;
    *.djvu)
        notify-send 'Working, please wait...'
        ddjvu -format=pdf -skip "$1" "${1%.*}".pdf
        mupdf "${1%.*}".pdf &
    ;;
esac

~/.bash_profile

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment