~ubuntu-branches/ubuntu/wily/xdg-utils/wily

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/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
}

#[ 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"
    ;;

    generic)
    terminal_generic "$command"
    ;;

    *)
    exit_failure_operation_impossible "no terminal emulator available"
    ;;
esac