From: Francois Fleuret Date: Sun, 21 Mar 2010 17:38:47 +0000 (+0100) Subject: Initial commit. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=scripts.git;a=commitdiff_plain;h=e96a1e611533a6aa3631fad94d606ae4cab392a3 Initial commit. --- diff --git a/viewer.sh b/viewer.sh new file mode 100755 index 0000000..27b93df --- /dev/null +++ b/viewer.sh @@ -0,0 +1,156 @@ +#!/bin/sh + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +set -e + +function getgeometry () { + XSETUP="/tmp/xsetup" + + if [[ -f "${XSETUP}" ]]; then + + ACTIVE_SCREEN_GEOMETRY=($(awk '{ + if(0>= $5 && 0 < $5+$3) { print $2" "$3" "$4" "$5 } + }' < ${XSETUP})) + + ACTIVE_WIDTH=${ACTIVE_SCREEN_GEOMETRY[0]} + ACTIVE_HEIGHT=${ACTIVE_SCREEN_GEOMETRY[1]} + ACTIVE_X=${ACTIVE_SCREEN_GEOMETRY[2]} + ACTIVE_Y=${ACTIVE_SCREEN_GEOMETRY[3]} + + GEOMETRY="${ACTIVE_WIDTH}x${ACTIVE_HEIGHT}+${ACTIVE_X}+${ACTIVE_Y}" + fi +} + +# This is my universal file viewer + +# If no argument is given, we pick the most recent file + +if [[ ! $1 ]]; then + file=$(\ls -tQ | head -1 | sed -e s/\"//g) + echo "Most recent is ${file}" + $0 ${file} + exit 0 +fi + +# If there were arguments, we loop through them + +echo "Viewing $*" + +while [[ $1 ]]; do + + file=$1 + + # file=$(\ls -tQd $1 | head -1 | sed -e s/\"//g) + + # if [[ ! -a ${file} ]]; then + # echo "Can not find file $1" + # exit 1 + # fi + + type=$(file -L "${file}") + + case ${type} in + + *"FIG image text"*) + echo "${file}" + temp=$(mktemp /tmp/view.XXXXXX) + fig2dev -L pdf ${file} ${temp} + # xpdf -g 800x600+8+8 ${temp} + getgeometry + xpdf -g ${GEOMETRY} ${temp} + rm ${temp} + ;; + + *"image"*) + echo "${file}" + # feh -g 800x600 ${file} + getgeometry + feh -g ${GEOMETRY} ${file} + ;; + + *"TeX DVI"*) + echo "${file}" + xdvi ${file} + ;; + + # *"FIG image"*) + # echo "${file}" + # xfig ${file} + # ;; + + *"PostScript"*) + echo "${file}" + gv ${file} + ;; + + *"PDF"*) + echo "${file}" + # xpdf -g 800x600+8+8 ${file} + getgeometry + xpdf -g ${GEOMETRY} ${file} + ;; + + *"WAVE audio"*) + echo "${file}" + esdplay ${file} + ;; + + *"MP3"*|*"MPEG"*|*"movie"*|*"video"*|*"AVI"*|*"Microsoft ASF"*) + mplayer -quiet ${file} + ;; + + *" text"*) + HEIGHT=$(stty size | awk '{print $1}') + if [[ $(wc -l ${file} | cut -f 1 -d' ') -gt $((HEIGHT-2)) ]]; then + less ${file} + else + cat ${file} + fi + ;; + + *"tar archive"*) + tar ztf ${file} + ;; + + *"Microsoft Word Document"*) + antiword ${file} | less + ;; + + *"directory"*) + echo "${file}:"; ls -lt ${file} + ;; + + *"gzip compressed"*) + temp=$(mktemp /tmp/view.XXXXXX) + echo "Decompressing to ${temp}" + zcat ${file} > ${temp} + $0 ${temp} + echo "Removing ${temp}" + rm ${temp} + ;; + + *) + echo "Unable to handle ${type}" + ;; + + esac + + shift + +done