xdg-utils/scripts/xdg-terminal.in

277 lines
5.9 KiB
Bash

#!/bin/sh
#---------------------------------------------
# xdg-terminal
#
# Utility script to open the registered terminal emulator
#
# Refer to the usage() function below for usage.
#
# Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
# Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
# Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
#
# LICENSE:
#
#---------------------------------------------
manualpage()
{
cat << _MANUALPAGE
_MANUALPAGE
}
usage()
{
cat << _USAGE
_USAGE
}
#@xdg-utils-common@
terminal_kde()
{
terminal=`kreadconfig --file kdeglobals --group General --key TerminalApplication --default konsole`
terminal_exec=`which $terminal 2>/dev/null`
if [ -x "$terminal_exec" ]; then
if [ x"$1" = x"" ]; then
$terminal_exec
else
$terminal_exec -e "$1"
fi
if [ $? -eq 0 ]; then
exit_success
else
exit_failure_operation_failed
fi
else
exit_failure_operation_impossible "configured terminal program '$terminal' not found or not executable"
fi
}
terminal_gnome()
{
term_exec_key="/desktop/gnome/applications/terminal/exec"
term_exec_arg_key="/desktop/gnome/applications/terminal/exec_arg"
term_exec=`gconftool-2 --get ${term_exec_key}`
term_exec_arg=`gconftool-2 --get ${term_exec_arg_key}`
terminal_exec=`which $term_exec 2>/dev/null`
if [ -x "$terminal_exec" ]; then
if [ x"$1" = x"" ]; then
$terminal_exec
else
if [ x"$term_exec_arg" = x"" ]; then
$terminal_exec "$1"
else
$terminal_exec "$term_exec_arg" "$1"
fi
fi
if [ $? -eq 0 ]; then
exit_success
else
exit_failure_operation_failed
fi
else
exit_failure_operation_impossible "configured terminal program '$term_exec' not found or not executable"
fi
}
terminal_gsettings()
{
term_schema="$1"; shift
term_exec=`gsettings get ${term_schema} exec`
term_exec_arg=`gsettings get ${term_schema} exec-arg`
terminal_exec=`which $term_exec 2>/dev/null`
if [ -x "$terminal_exec" ]; then
if [ x"$1" = x"" ]; then
$terminal_exec
else
if [ x"$term_exec_arg" = x"" ]; then
$terminal_exec "$1"
else
$terminal_exec "$term_exec_arg" "$1"
fi
fi
if [ $? -eq 0 ]; then
exit_success
else
exit_failure_operation_failed
fi
else
exit_failure_operation_impossible "configured terminal program '$term_exec' not found or not executable"
fi
}
terminal_xfce()
{
if [ x"$1" = x"" ]; then
exo-open --launch TerminalEmulator
else
exo-open --launch TerminalEmulator "$1"
fi
if [ $? -eq 0 ]; then
exit_success
else
exit_failure_operation_failed
fi
}
terminal_generic()
{
# if $TERM is a known non-command, use hard-coded fallbacks
if [ x"$TERM" = x"" ] || [ x"$TERM" = x"linux" ] || [ x"$TERM" = x"vt100" ]; then
TERM=xterm
fi
terminal_exec=`which $TERM 2>/dev/null`
if [ -x "$terminal_exec" ]; then
if [ x"$1" = x"" ]; then
$terminal_exec
else
# screen and urxvt won't do their own parsing of quoted arguments
if [ x"$TERM" = x"screen" ]; then
# screen has an incompatible meaning for -e
sh -c "exec $terminal_exec $1"
elif [ x"$TERM" = x"urxvt" ] || [ x"$TERM" = x"rxvt-unicode" ] || [ x"$TERM" = x"rxvt" ]; then
#TODO: Use whatever mechanism dash supports to test for
# rxvt-* to match things like rxvt-unicode-256color
sh -c "exec $terminal_exec -e $1"
else
$terminal_exec -e "$1"
fi
fi
if [ $? -eq 0 ]; then
exit_success
else
exit_failure_operation_failed
fi
else
exit_failure_operation_impossible "configured terminal program '$TERM' not found or not executable"
fi
}
terminal_lxde()
{
if which lxterminal &>/dev/null; then
if [ x"$1" = x"" ]; then
lxterminal
else
lxterminal -e "$1"
fi
else
terminal_generic "$1"
fi
}
terminal_lxqt()
{
if which qterminal &>/dev/null; then
if [ x"$1" = x"" ]; then
qterminal
else
qterminal -e "$1"
fi
else
terminal_generic "$1"
fi
}
terminal_enlightenment()
{
if which terminology &>/dev/null; then
if [ x"$1" = x"" ]; then
terminology
else
terminology -e "$1"
fi
else
terminal_generic "$1"
fi
}
#[ x"$1" != x"" ] || exit_failure_syntax
command=
while [ $# -gt 0 ] ; do
parm="$1"
shift
case "$parm" in
-*)
exit_failure_syntax "unexpected option '$parm'"
;;
*)
if [ -n "$command" ] ; then
exit_failure_syntax "unexpected argument '$parm'"
fi
command="$parm"
;;
esac
done
detectDE
if [ x"$DE" = x"" ]; then
DE=generic
fi
case "$DE" in
kde)
terminal_kde "$command"
;;
gnome)
terminal_gnome "$command"
;;
gnome3)
terminal_gsettings org.gnome.desktop.default-applications.terminal "$command"
;;
cinnamon)
terminal_gsettings org.cinnamon.desktop.default-applications.terminal "$command"
;;
mate)
terminal_gsettings org.mate.applications-terminal "$command"
;;
xfce)
terminal_xfce "$command"
;;
lxde)
terminal_lxde "$command"
;;
lxqt)
terminal_lxqt "$command"
;;
enlightenment)
terminal_enlightenment "$command"
;;
generic)
terminal_generic "$command"
;;
*)
exit_failure_operation_impossible "no terminal emulator available"
;;
esac