#!/bin/sh
# launch a text editor

exec_editor() {
    if [ -n "$1" ] && [ $(basename "$1") != "editor" ] \
        && which "$1" > /dev/null 2>&1
    then
        exec "$@"
    fi
}

exec_editor "$TEXTEDITOR" "$@"
exec_editor "$VISUAL"     "$@"
exec_editor "$EDITOR"     "$@"
[ -n "$GNOME_DESKTOP_SESSION_ID" ] && exec_editor gedit "$@"
[ -n "$KDE_FULL_SESSION" ] && exec_editor kwrite "$@"
exec_editor kwrite "$@"
exec_editor gedit  "$@"
exec_editor emacs  "$@"
exec_editor vim    "$@"
exec_editor nano   "$@"

echo "no text editor detected" >&2
exit 1
