Browse Source

Use xdg-open by default in mc.ext.in if present to open files,
fallback on current scheme otherwise.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>

Slava Zanko 13 years ago
parent
commit
ec7aafef83
10 changed files with 694 additions and 1 deletions
  1. 8 0
      configure.ac
  2. 1 1
      misc/Makefile.am
  3. 28 0
      misc/ext.d/Makefile.am
  4. 143 0
      misc/ext.d/archive.sh
  5. 96 0
      misc/ext.d/doc.sh.in
  6. 55 0
      misc/ext.d/image.sh
  7. 82 0
      misc/ext.d/misc.sh
  8. 59 0
      misc/ext.d/package.sh
  9. 89 0
      misc/ext.d/sound.sh
  10. 133 0
      misc/ext.d/text.sh.in

+ 8 - 0
configure.ac

@@ -481,6 +481,10 @@ AC_SUBST(LIBS)
 dnl Libraries used only when building the mc binary
 dnl Libraries used only when building the mc binary
 AC_SUBST(MCLIBS)
 AC_SUBST(MCLIBS)
 
 
+
+EXTHELPERSDIR=${prefix}/libexec/${PACKAGE}/ext.d
+AC_SUBST(EXTHELPERSDIR)
+
 MAN_DATE="$(LC_ALL=C date "+%B %Y")"
 MAN_DATE="$(LC_ALL=C date "+%B %Y")"
 AC_SUBST(MAN_DATE)
 AC_SUBST(MAN_DATE)
 
 
@@ -514,6 +518,10 @@ contrib/dist/prototype
 
 
 misc/Makefile
 misc/Makefile
 misc/skins/Makefile
 misc/skins/Makefile
+misc/ext.d/Makefile
+misc/ext.d/doc.sh
+misc/ext.d/text.sh
+misc/ext.d/web.sh
 misc/macros.d/Makefile
 misc/macros.d/Makefile
 misc/mc.ext
 misc/mc.ext
 
 

+ 1 - 1
misc/Makefile.am

@@ -1,6 +1,6 @@
 ## Process this file with automake to create Makefile.in.
 ## Process this file with automake to create Makefile.in.
 
 
-SUBDIRS = macros.d skins syntax
+SUBDIRS = ext.d macros.d skins syntax
 
 
 LIBFILES_OUT = mc.ext
 LIBFILES_OUT = mc.ext
 
 

+ 28 - 0
misc/ext.d/Makefile.am

@@ -0,0 +1,28 @@
+extdir = $(EXTHELPERSDIR)
+
+SCRIPTS_IN = \
+	doc.sh.in \
+	text.sh.in \
+	web.sh.in
+
+SCRIPTS_OUT = \
+	doc.sh \
+	text.sh \
+	web.sh
+
+SCRIPTS_UNTOUCHED = \
+	archive.sh \
+	image.sh \
+	misc.sh \
+	package.sh \
+	sound.sh \
+	video.sh
+
+ext_SCRIPTS = \
+	$(SCRIPTS_UNTOUCHED) \
+	$(SCRIPTS_OUT)
+
+EXTRA_DIST = \
+	$(SCRIPTS_UNTOUCHED) \
+	$(SCRIPTS_IN)
+

+ 143 - 0
misc/ext.d/archive.sh

@@ -0,0 +1,143 @@
+#!/bin/sh
+
+# $1 - action
+# $2 - type of file
+# $3 - pager
+
+action=$1
+filetype=$2
+pager=$3
+
+do_view_action() {
+    filetype=$1
+
+    case "${filetype}" in
+    gz)
+        gzip -dc "${MC_EXT_FILENAME}" 2>/dev/null
+        ;;
+    bz2)
+        bzip2 -dc "${MC_EXT_FILENAME}" 2>/dev/null
+        ;;
+    bzip)
+        bzip2 -dc "${MC_EXT_FILENAME}" 2>/dev/null
+        ;;
+    lzma)
+        lzma -dc "${MC_EXT_FILENAME}" 2>/dev/null
+        ;;
+    xz)
+        xz -dc "${MC_EXT_FILENAME}" 2>/dev/null
+        ;;
+    tar)
+        tar tvvf - < "${MC_EXT_FILENAME}"
+        ;;
+    tar.gz|tar.qpr)
+        gzip -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
+            tar tvvf -
+        ;;
+    tar.bzip)
+        bzip -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
+            tar tvvf -
+        ;;
+    tar.bzip2)
+        bzip2 -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
+            tar tvvf -
+        ;;
+    tar.lzma)
+        lzma -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
+            tar tvvf -
+        ;;
+    tar.xz)
+        xz -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
+            tar tvvf -
+        ;;
+    tar.F)
+        freeze -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
+            tar tvvf -
+        ;;
+
+    lha)
+        lha l "${MC_EXT_FILENAME}"
+        ;;
+    arj)
+        unarj l "${MC_EXT_FILENAME}"
+        ;;
+    cab)
+        cabextract -l "${MC_EXT_FILENAME}"
+        ;;
+    ha)
+        ha lf "${MC_EXT_FILENAME}"
+        ;;
+    rar)
+        rar v -c- "${MC_EXT_FILENAME}" 2>/dev/null || \
+            unrar v -c- "${MC_EXT_FILENAME}"
+        ;;
+    alz)
+        unalz -l "${MC_EXT_FILENAME}"
+        ;;
+    cpio.z|cpio.gz)
+        gzip -dc "${MC_EXT_FILENAME}" | \
+            cpio -itv 2>/dev/null
+        ;;
+    cpio.xz)
+        xz -dc "${MC_EXT_FILENAME}" | \
+            cpio -itv 2>/dev/null
+        ;;
+    cpio)
+        cpio -itv < "${MC_EXT_FILENAME}" 2>/dev/null
+        ;;
+    7z)
+        7za l "${MC_EXT_FILENAME}" 2>/dev/null
+        ;;
+    ace)
+        unace l "${MC_EXT_FILENAME}"
+        ;;
+    arc)
+        arc l "${MC_EXT_FILENAME}"
+        ;;
+    zip)
+        unzip -v "${MC_EXT_FILENAME}"
+        ;;
+    zoo)
+        zoo l "${MC_EXT_FILENAME}"
+        ;;
+    *)
+        ;;
+    esac
+}
+
+do_open_action() {
+    filetype=$1
+    pager=$2
+
+    case "${filetype}" in
+    bzip2)
+        bzip2 -dc "${MC_EXT_FILENAME}" | ${pager}
+        ;;
+    bzip)
+        bzip -dc "${MC_EXT_FILENAME}" | ${pager}
+        ;;
+    gz)
+        gz -dc "${MC_EXT_FILENAME}" | ${pager}
+        ;;
+    lzma)
+        lzma -dc "${MC_EXT_FILENAME}" | ${pager}
+        ;;
+    xz)
+        xz -dc "${MC_EXT_FILENAME}" | ${pager}
+        ;;
+    *)
+        ;;
+    esac
+}
+
+case "${action}" in
+view)
+    do_view_action "${filetype}"
+    ;;
+open)
+    xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
+        do_open_action "${filetype}" "${pager}"
+    ;;
+*)
+    ;;
+esac

+ 96 - 0
misc/ext.d/doc.sh.in

@@ -0,0 +1,96 @@
+#!/bin/sh
+
+# $1 - action
+# $2 - type of file
+
+action=$1
+filetype=$2
+
+
+do_view_action() {
+    filetype=$1
+
+    case "${filetype}" in
+    ps)
+        ps2ascii "${MC_EXT_FILENAME}"
+        ;;
+    pdf)
+        pdftotext "${MC_EXT_FILENAME}" -
+        ;;
+    odt)
+        odt2txt "${MC_EXT_FILENAME}"
+        ;;
+    msdoc)
+        antiword -t "${MC_EXT_FILENAME}" || \
+            catdoc -w "${MC_EXT_FILENAME}" || \
+            word2x -f text "${MC_EXT_FILENAME}" - || \
+            strings "${MC_EXT_FILENAME}"
+        ;;
+    msxls)
+        xls2csv "${MC_EXT_FILENAME}" || \
+            strings "${MC_EXT_FILENAME}"
+        ;;
+    dvi)
+        dvi2tty "${MC_EXT_FILENAME}"
+        ;;
+    djvu)
+        djvused -e print-pure-txt "${MC_EXT_FILENAME}"
+        ;;
+    *)
+        ;;
+    esac
+}
+
+do_open_action() {
+    filetype=$1
+
+    case "${filetype}" in
+    ps)
+        (gv "${MC_EXT_FILENAME}" &)
+        ;;
+    pdf)
+        (xpdf "${MC_EXT_FILENAME}" &)
+        #(acroread "${MC_EXT_FILENAME}" &)
+        #(ghostview "${MC_EXT_FILENAME}" &)
+        ;;
+    ooffice)
+        (ooffice "${MC_EXT_FILENAME}" &)
+        ;;
+    abw)
+        (abiword "${MC_EXT_FILENAME}" &)
+        ;;
+    msdoc)
+        (abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
+        ;;
+    msxls)
+        (gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
+        ;;
+    framemaker)
+        fmclient -f "${MC_EXT_FILENAME}"
+        ;;
+    dvi)
+        if [ x$DISPLAY = x ]; then
+            dvisvga "${MC_EXT_FILENAME}"
+        else
+            (xdvi "${MC_EXT_FILENAME}" &)
+        fi
+        ;;
+    djvu)
+        djview "${MC_EXT_FILENAME}" &
+        ;;
+    *)
+        ;;
+    esac
+}
+
+case "${action}" in
+view)
+    do_view_action "${filetype}"
+    ;;
+open)
+    xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
+        do_open_action "${filetype}"
+    ;;
+*)
+    ;;
+esac

+ 55 - 0
misc/ext.d/image.sh

@@ -0,0 +1,55 @@
+#!/bin/sh
+
+# $1 - action
+# $2 - type of file
+
+action=$1
+filetype=$2
+
+do_view_action() {
+    filetype=$1
+
+    case "${filetype}" in
+    jpeg)
+        identify "${MC_EXT_FILENAME}"; test -x /usr/bin/exif && echo && exif "${MC_EXT_FILENAME}" 2>/dev/null
+        ;;
+    xpm)
+        sxpm "${MC_EXT_FILENAME}"
+        ;;
+    *)
+        identify "${MC_EXT_FILENAME}"
+        ;;
+    esac
+}
+
+do_open_action() {
+    filetype=$1
+
+    case "${filetype}" in
+    xbm)
+        bitmap "${MC_EXT_FILENAME}"
+        ;;
+    xcf)
+        (gimp "${MC_EXT_FILENAME}" &)
+        ;;
+    *)
+        if [ "$DISPLAY" = "" ]; then
+            zgv "${MC_EXT_FILENAME}"
+        else
+            (gqview "${MC_EXT_FILENAME}" &)
+        fi
+        ;;
+    esac
+}
+
+case "${action}" in
+view)
+    do_view_action "${filetype}"
+    ;;
+open)
+    xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
+        do_open_action "${filetype}"
+    ;;
+*)
+    ;;
+esac

+ 82 - 0
misc/ext.d/misc.sh

@@ -0,0 +1,82 @@
+#!/bin/sh
+
+# $1 - action
+# $2 - type of file
+
+action=$1
+filetype=$2
+
+do_view_action() {
+    filetype=$1
+    filename=$2
+
+    case "${filetype}" in
+    iso9660)
+        isoinfo -l -i "${MC_EXT_FILENAME}"
+        ;;
+    cat)
+        /bin/cat "${MC_EXT_FILENAME}" 2>/dev/null
+        ;;
+    ar)
+        file "${MC_EXT_FILENAME}" && nm -C "${MC_EXT_FILENAME}"
+        ;;
+    so)
+        file "${MC_EXT_FILENAME}" && nm -C -D "${MC_EXT_FILENAME}"
+        ;;
+    elf)
+        file "${MC_EXT_FILENAME}" && nm -C "${MC_EXT_FILENAME}"
+        ;;
+    dbf)
+        dbview -b "${MC_EXT_FILENAME}"
+        ;;
+    mo)
+        msgunfmt "${MC_EXT_FILENAME}" || \
+            cat "${MC_EXT_FILENAME}"
+        ;;
+    lyx)
+        lyxcat "${MC_EXT_FILENAME}"
+        ;;
+    torrent)
+        ctorrent -x "${MC_EXT_FILENAME}" 2>/dev/null
+        ;;
+    *)
+        ;;
+    esac
+}
+
+do_open_action() {
+    filetype=$1
+
+    case "${filetype}" in
+    imakefile)
+        xmkmf -a
+        ;;
+    dbf)
+        dbview "${MC_EXT_FILENAME}"
+        ;;
+    glade)
+        if glade-3 --version >/dev/null 2>&1; then
+            (glade-3 "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
+        else
+            (glade-2 "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
+        fi
+        ;;
+    lyx)
+        lyx "${MC_EXT_FILENAME}"
+        ;;
+    *)
+        ;;
+    esac
+}
+
+case "${action}" in
+view)
+    do_view_action "${filetype}"
+    ;;
+open)
+    xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
+        do_open_action "${filetype}"
+    ;;
+*)
+    ;;
+esac

+ 59 - 0
misc/ext.d/package.sh

@@ -0,0 +1,59 @@
+#!/bin/sh
+
+# $1 - action
+# $2 - type of file
+
+action=$1
+filetype=$2
+
+
+do_view_action() {
+    filetype=$1
+    filename=$2
+
+    case "${filetype}" in
+    trpm)
+        rpm -qivl --scripts `basename "${MC_EXT_BASENAME}" .trpm`
+        ;;
+    src.rpm|rpm)
+        if rpm --nosignature --version >/dev/null 2>&1; then 
+            RPM="rpm --nosignature"
+        else
+            RPM="rpm"
+        fi
+        $RPM -qivlp --scripts "${MC_EXT_FILENAME}"
+        ;;
+    deb)
+        dpkg-deb -I "${filename}" && echo && dpkg-deb -c "${MC_EXT_FILENAME}"
+        ;;
+    debd)
+        dpkg -s `echo "${MC_EXT_BASENAME}" | sed 's/\([0-9a-z.-]*\).*/\1/'`
+        ;;
+    deba)
+        apt-cache show `echo "${MC_EXT_BASENAME}" | sed 's/\([0-9a-z.-]*\).*/\1/'`
+        ;;
+    *)
+        ;;
+    esac
+}
+
+do_open_action() {
+    filetype=$1
+
+    case "${filetype}" in
+    *)
+        ;;
+    esac
+}
+
+case "${action}" in
+view)
+    do_view_action "${filetype}"
+    ;;
+open)
+    xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
+        do_open_action "${filetype}"
+    ;;
+*)
+    ;;
+esac

+ 89 - 0
misc/ext.d/sound.sh

@@ -0,0 +1,89 @@
+#!/bin/sh
+
+# $1 - action
+# $2 - type of file
+
+action=$1
+filetype=$2
+
+do_view_action() {
+    filetype=$1
+
+    case "${filetype}" in
+    mp3)
+        mpg123 -vtn1 "${MC_EXT_FILENAME}" 2>&1 | \
+            sed -n '/^Title/,/^Comment/p;/^MPEG/,/^Audio/p'
+        ;;
+    ogg)
+        ogginfo "${MC_EXT_SELECTED}"
+        ;;
+    wma)
+        mplayer -quiet -slave -frames 0 -vo null -ao null -identify "${MC_EXT_FILENAME}" 2>/dev/null | \
+            tail +13 || file "${MC_EXT_FILENAME}"
+        ;;
+    *)
+        ;;
+    esac
+}
+
+do_open_action() {
+    filetype=$1
+
+    case "${filetype}" in
+    common)
+        if [ "$DISPLAY" = "" ]; then
+            play "${MC_EXT_FILENAME}"
+        else
+            (xmms  "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
+        fi
+        ;;
+    mod)
+        mikmod "${MC_EXT_FILENAME}"
+        #tracker "${MC_EXT_FILENAME}"
+        ;;
+    wav22)
+        vplay -s 22 "${MC_EXT_FILENAME}"
+        ;;
+    mp3)
+        if [ "$DISPLAY" = "" ]; then
+            mpg123 "${MC_EXT_FILENAME}"
+        else
+            (xmms "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
+        fi
+        ;;
+    ogg)
+        if [ "$DISPLAY" = "" ]; then
+            ogg123 "${MC_EXT_FILENAME}"
+        else
+            (xmms "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
+        fi
+        ;;
+    midi)
+        timidity "${MC_EXT_FILENAME}"
+        ;;
+    wma)
+        mplayer -vo null "${MC_EXT_FILENAME}"
+        ;;
+    playlist)
+        if [ -z "$DISPLAY" ]; then
+            mplayer -vo null -playlist "${MC_EXT_FILENAME}"
+        else
+            (xmms -p "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
+        fi
+        ;;
+    *)
+        ;;
+    esac
+}
+
+case "${action}" in
+view)
+    do_view_action "${filetype}"
+    ;;
+open)
+    xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
+        do_open_action "${filetype}"
+    ;;
+*)
+    ;;
+esac

+ 133 - 0
misc/ext.d/text.sh.in

@@ -0,0 +1,133 @@
+#!/bin/sh
+
+# $1 - action
+# $2 - type of archive
+# $3 - pager
+
+action=$1
+filetype=$2
+pager=$3
+
+get_unpacker() {
+    filetype=$1
+    case "${filetype}" in
+    man.gz)
+        unpacker="gzip -dc"
+        ;;
+    man.bz)
+        unpacker="bzip -dc"
+        ;;
+    man.bz2)
+        unpacker="bzip2 -dc"
+        ;;
+    man.lzma)
+        unpacker="lzma -dc"
+        ;;
+    man.xz)
+        unpacker="xz -dc"
+        ;;
+    esac
+    echo ${unpacker}
+}
+
+
+do_view_action() {
+    filetype=$1
+    pager=$2
+
+    unpacker=`get_unpacker ${filetype}`
+
+    case "${filetype}" in
+    man)
+        case "${MC_EXT_CURRENTDIR}"/"${MC_EXT_FILENAME}" in
+        */log/*|*/logs/*)
+            cat "${MC_EXT_FILENAME}"
+            ;;
+        *)
+            { zsoelim "${MC_EXT_FILENAME}" 2>/dev/null || cat "${MC_EXT_FILENAME}"; } | nroff @MAN_FLAGS@ @MANDOC@
+            ;;
+        esac
+        ;;
+    pod)
+        pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
+        ;;
+    nroff.me)
+        nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}"
+        ;;
+    nroff.ms)
+        nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}"
+        ;;
+    man.gz|man.bz|man.bz2|man.lzma|man.xz)
+        case "${MC_EXT_CURRENTDIR}"/"${MC_EXT_FILENAME}" in
+        */log/*|*/logs/*)
+            ${unpacker} %f
+            ;;
+        *)
+             ${unpacker} ${filename} | nroff @MAN_FLAGS@ @MANDOC@
+             ;;
+        esac
+        ;;
+    *)
+        ;;
+    esac
+}
+
+do_open_action() {
+    filetype=$1
+    pager=$2
+
+    unpacker=`get_unpacker ${filetype}`
+
+    case "${filetype}" in
+    info)
+        info -f "${MC_EXT_FILENAME}"
+        ;;
+    man)
+        case "${MC_EXT_CURRENTDIR}"/"${MC_EXT_FILENAME}" in
+        */log/*|*/logs/*)
+            cat "${MC_EXT_FILENAME}"
+            ;;
+        *)
+            { zsoelim "${MC_EXT_FILENAME}" 2>/dev/null || cat "${MC_EXT_FILENAME}"; } | \
+                nroff @MAN_FLAGS@ @MANDOC@
+            ;;
+        esac | ${pager}
+        ;;
+    pod)
+        pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@ | ${pager}
+        ;;
+    nroff.me)
+        nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}" | ${pager}
+        ;;
+    nroff.ms)
+        nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}" | ${pager}
+        ;;
+    man.gz|man.bz|man.bz2|man.lzma|man.xz)
+        case "${MC_EXT_CURRENTDIR}"/"${MC_EXT_FILENAME}" in
+        */log/*|*/logs/*)
+            ${unpacker} "${MC_EXT_FILENAME}"
+            ;;
+        *)
+            ${unpacker} "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
+            ;;
+        esac | ${pager}
+        ;;
+    chm)
+        which kchmviewer > /dev/null 2>&1 && (kchmviewer "${MC_EXT_FILENAME}" &) || (xchm "${MC_EXT_FILENAME}" &)
+        ;;
+    *)
+        ;;
+    esac
+}
+
+case "${action}" in
+view)
+    do_view_action "${filetype}" "${pager}"
+    ;;
+open)
+    xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
+        do_open_action "${filetype}" "${pager}"
+    ;;
+*)
+    ;;
+esac

Some files were not shown because too many files changed in this diff