#!/bin/bash # # Syntax: pd [-h] [pdf_file [...]] # # Purpose: Shows one or more pdf file using acroreader, okular, xpdf, epdfview, # ghostview, or evince (where the first command of this list that can # be found is used). # The -h flag shows the help info for this command. # Created: Jun 30, 2016 by Bart De Schutter # Last revised: # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: pdf, latex if [ $# -ge 1 -a "$1" = "-h" ]; then sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi #if [ $# -ne 0 ]; #then # echo >&2 # echo >&2 "ERROR: ${0##*/} requires no input arguments." # echo >&2 # sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 # exit 1 #fi pdf_viewer=$(type -p acroread) options="" if [ -z "$pdf_viewer" ] then pdf_viewer=$(type -p okular) options="" if [ -z "$pdf_viewer" ] then pdf_viewer=$(type -p xpdf) options="-z page" if [ -z "$pdf_viewer" ] then pdf_viewer=$(type -p epdfview) options="" if [ -z "$pdf_viewer" ] then pdf_viewer=$(type -p ghostview) options="" if [ -z "$pdf_viewer" ] then pdf_viewer=$(type -p evince) options="" if [ -z "$pdf_viewer" ] then echo >&2 echo >&2 "ERROR: No pdf viewer found on this system." echo >&2 exit 1 fi fi fi fi fi fi if [ $# -eq 0 ]; then pdffile=$( (ls -t *.pdf | head -n 1) 2>/dev/null) if [ -n "$pdffile" ]; then $pdf_viewer $options "$pdffile" & else echo "No .pdf files found in the current directory." fi else for pdffile in "$@" do echo "Viewing $pdffile" $pdf_viewer $options "$pdffile" done fi