mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
120 lines
1.4 KiB
Bash
Executable file
120 lines
1.4 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
# BUG - Should clean up $tmp but how to know when viewer is done?
|
|
|
|
preview()
|
|
{
|
|
list=""
|
|
pwd=`pwd`
|
|
for i in "$@"
|
|
do
|
|
if [ -n "$list" ]
|
|
then
|
|
list="$list, "
|
|
fi
|
|
n=`cleanname -d $pwd $i | sed 's!/!:!g'`
|
|
list="$list\"$n\""
|
|
done
|
|
# echo run $list
|
|
echo 'tell application "Preview"
|
|
activate
|
|
open {'"$list"'}
|
|
end tell' | osascript
|
|
}
|
|
|
|
xfile()
|
|
{
|
|
if sed 1q "$1" | 9 grep '^x T '
|
|
then
|
|
echo 'troff intermediate output'
|
|
else
|
|
9 file < "$1" | sed 's/stdin: //' | tr A-Z a-z
|
|
fi
|
|
}
|
|
|
|
main()
|
|
{
|
|
case `uname` in
|
|
Darwin)
|
|
preview "$@"
|
|
;;
|
|
*)
|
|
case "`xfile $1`" in
|
|
*troff*)
|
|
tr2post "$1" | psfonts | page
|
|
;;
|
|
*pdf*)
|
|
psv $1
|
|
;;
|
|
*ps*)
|
|
psv $1
|
|
;;
|
|
*postscript*)
|
|
psv $1
|
|
;;
|
|
*)
|
|
qiv "$@"
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|
|
}
|
|
|
|
case $# in
|
|
0)
|
|
tmp=/var/tmp/page.$$.tmp
|
|
cat >$tmp
|
|
type=`xfile $tmp`
|
|
case "$type" in
|
|
*troff*)
|
|
mv $tmp $tmp.tr
|
|
tmp=$tmp.tr
|
|
;;
|
|
*pdf*)
|
|
mv $tmp $tmp.pdf
|
|
tmp=$tmp.pdf
|
|
;;
|
|
*gif*)
|
|
mv $tmp $tmp.gif
|
|
tmp=$tmp.gif
|
|
;;
|
|
*jpg*)
|
|
mv $tmp $tmp.jpg
|
|
tmp=$tmp.jpg
|
|
;;
|
|
*jpeg*)
|
|
mv $tmp $tmp.jpg
|
|
tmp=$tmp.jpg
|
|
;;
|
|
*png*)
|
|
mv $tmp $tmp.png
|
|
tmp=$tmp.png
|
|
;;
|
|
*postscript*)
|
|
mv $tmp $tmp.ps
|
|
tmp=$tmp.ps
|
|
;;
|
|
*postscript*)
|
|
mv $tmp $tmp.ps
|
|
tmp=$tmp.ps
|
|
;;
|
|
*ps*)
|
|
mv $tmp $tmp.ps
|
|
tmp=$tmp.ps
|
|
;;
|
|
*)
|
|
echo 1>&2 page: unrecognized file type on standard input: $type
|
|
rm -f $tmp
|
|
exit 1
|
|
esac
|
|
main $tmp
|
|
if [ `uname` != Darwin ]
|
|
then
|
|
rm -f $tmp
|
|
fi
|
|
;;
|
|
*)
|
|
main "$@"
|
|
;;
|
|
esac
|
|
|