#!/bin/bash

# This script choose and run right text editor
# for Pearl applications
# Created by Paweł "pavroo' Pijanowski 2015/11/12
# Copyright 2015-2019 under the GNU GPL2 License
# Last update 2019/08/06

if [ -f /usr/bin/pearl-xterm ];then
	PEARLXTERM="/usr/bin/pearl-xterm"
else
	echo "pearl-xterm is missing... Exiting..."
	exit 1
fi

if [ $(pidof xfwm4) ] && [ -f /usr/bin/mousepad ]; then
	mousepad "$@"

elif [ $(pidof marco) ] && [ -f /usr/bin/pluma ]; then
	pluma "$@"

elif [ $(pidof kwin_x11) ] && [ -f /usr/bin/featherpad ]; then
	featherpad "$@"

elif [ $(pidof kwin_x11) ] && [ -f /usr/bin/leafpad ]; then
	leafpad "$@"

elif [ $(pidof enlightenment) ] && [ -f /usr/bin/ecrire ]; then
	ecrire "$@"

elif [ $(pidof gala) ] && [ -f /usr/bin/leafpad ]; then
	leafpad "$@"

elif [ $(pidof lxqt-session) ] && [ -f /usr/bin/featherpad ]; then
	featherpad "$@"

elif [ $(pidof openbox) ]; then
	if [ -f /usr/bin/leafpad ]; then
		leafpad "$@"
	elif [ -f /usr/bin/mousepad ]; then
		mousepad "$@"
	fi

else
	if [ -f /usr/bin/gnome-text-editor ]; then
		gnome-text-editor "$@"

	elif [ -f /bin/nano ]; then
		$PEARLXTERM nano "$@"

	fi
fi

exit 0
