#! /bin/sh
#######################################################################
# xeditor
# Version: 1.0
# This script is used by worker to call a X editor
# Several editors are searched with vi in a xterm as fallback
# but the env variable WORKER_XEDITOR can force another editor
#
# written by Ralf Hoffmann 2005
# Worker: http://www.boomerangsworld.de/worker
#######################################################################
# $Id: xeditor,v 1.3 2005/03/30 05:31:14 ralf Exp $
#######################################################################

XEDITOR="xterm"
SEARCH_EDITORS="nedit gedit gvim jedit emacs xemacs xedit"
USE_EDITOR=""

if [ -z "$WORKER_XEDITOR" ]; then
  for e in $SEARCH_EDITORS; do
    p=$(which $e 2>/dev/null)
    if [ -x "$p" ]; then
      USE_EDITOR="$p"
      break
    fi
  done
else
  USE_EDITOR="$WORKER_XEDITOR"
fi

if [ -n "$USE_EDITOR" ]; then
  "$USE_EDITOR" "$@"
else
  "$XEDITOR" -e vi "$@"
fi
