plan9port/bin/page

99 lines
1.1 KiB
Text
Raw Normal View History

2005-01-11 19:23:52 +00:00
#!/bin/sh
2005-01-11 19:35:27 +00:00
# BUG - Should clean up $tmp but how to know when viewer is done?
2005-01-11 19:23:52 +00:00
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
}
2005-01-11 19:35:27 +00:00
main()
{
case `uname` in
Darwin)
preview "$@"
;;
*)
case "`file $1`" in
*PDF*)
psv $1
;;
*PS*)
psv $1
;;
*PostScript*)
psv $1
;;
*)
qiv "$@"
;;
esac
;;
esac
}
2005-01-11 19:23:52 +00:00
case $# in
0)
2005-01-11 19:35:27 +00:00
tmp=/var/tmp/page.$$.tmp
cat >$tmp
case "`file $tmp`" in
2005-01-11 19:23:52 +00:00
*PDF*)
2005-01-11 19:35:27 +00:00
mv $tmp $tmp.pdf
tmp=$tmp.pdf
2005-01-11 19:23:52 +00:00
;;
*PS*)
2005-01-11 19:35:27 +00:00
mv $tmp $tmp.ps
tmp=$tmp.ps
2005-01-11 19:23:52 +00:00
;;
*PostScript*)
2005-01-11 19:35:27 +00:00
mv $tmp $tmp.ps
tmp=$tmp.ps
2005-01-11 19:23:52 +00:00
;;
2005-01-11 19:35:27 +00:00
*GIF*)
mv $tmp $tmp.gif
tmp=$tmp.gif
;;
*JPG*)
mv $tmp $tmp.jpg
tmp=$tmp.jpg
2005-01-11 19:23:52 +00:00
;;
2005-01-11 19:35:27 +00:00
*JPEG*)
mv $tmp $tmp.jpg
tmp=$tmp.jpg
;;
*PNG*)
mv $tmp $tmp.png
tmp=$tmp.png
;;
*)
2005-01-14 05:28:38 +00:00
echo 1>&2 page: unrecognized file type on standard input
2005-01-11 19:35:27 +00:00
rm -f $tmp
exit 1
2005-01-11 19:23:52 +00:00
esac
2005-01-11 19:35:27 +00:00
main $tmp
if [ `uname` != Darwin ]
then
rm -f $tmp
fi
;;
*)
main "$@"
2005-01-11 19:23:52 +00:00
;;
esac