#!/bin/sh
#
# Run comand on output files from within PriMa
#
# Maybe you have to change some settings
#

# file to save cmdline in
SAVED_CMDLINE=~/.prima-cmdline

# prompt text
PROMPT="Comandline: "
#PROMPT="Kommando: "

#set default cmdline
if [ -f $SAVED_CMDLINE ] ; then
  DEFAULT_CMDLINE=$(cat $SAVED_CMDLINE)
else
  DEFAULT_CMDLINE="gs -sDEVICE=ppm -sOutputFile=/tmp/foobar.ppm PSFILE"
fi

# get new cmdline using PriMa.input 
NEW_CMDLINE=$(PriMa.input "$PROMPT" "$DEFAULT_CMDLINE" "PriMa Command")

if [ $? = 1 ]; then
  exit 1
else	
  echo $NEW_CMDLINE > $SAVED_CMDLINE

# replace PSFILE by the real filename
CMD=$(sed "s/PSFILE/$1/g" $SAVED_CMDLINE)

#
# print file
# 
  echo $CMD
  exit $?
fi
