OLD | NEW |
1 #!/bin/sh | 1 #!/bin/sh |
2 #--------------------------------------------- | 2 #--------------------------------------------- |
3 # xdg-terminal | 3 # xdg-terminal |
4 # | 4 # |
5 # Utility script to open the registered terminal emulator | 5 # Utility script to open the registered terminal emulator |
6 # | 6 # |
7 # Refer to the usage() function below for usage. | 7 # Refer to the usage() function below for usage. |
8 # | 8 # |
| 9 # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org> |
| 10 # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org> |
9 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> | 11 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> |
10 # | 12 # |
11 # LICENSE: | 13 # LICENSE: |
12 # | 14 # |
13 # Permission is hereby granted, free of charge, to any person obtaining a | 15 # Permission is hereby granted, free of charge, to any person obtaining a |
14 # copy of this software and associated documentation files (the "Software"), | 16 # copy of this software and associated documentation files (the "Software"), |
15 # to deal in the Software without restriction, including without limitation | 17 # to deal in the Software without restriction, including without limitation |
16 # the rights to use, copy, modify, merge, publish, distribute, sublicense, | 18 # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
17 # and/or sell copies of the Software, and to permit persons to whom the | 19 # and/or sell copies of the Software, and to permit persons to whom the |
18 # Software is furnished to do so, subject to the following conditions: | 20 # Software is furnished to do so, subject to the following conditions: |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 exit_failure_file_permission_read() | 190 exit_failure_file_permission_read() |
189 { | 191 { |
190 if [ $# -gt 0 ]; then | 192 if [ $# -gt 0 ]; then |
191 echo "xdg-terminal: $@" >&2 | 193 echo "xdg-terminal: $@" >&2 |
192 fi | 194 fi |
193 | 195 |
194 exit 5 | 196 exit 5 |
195 } | 197 } |
196 | 198 |
197 #------------------------------------------------------------ | 199 #------------------------------------------------------------ |
198 # Exit script on insufficient permission to read a specified file | 200 # Exit script on insufficient permission to write a specified file |
199 | 201 |
200 exit_failure_file_permission_write() | 202 exit_failure_file_permission_write() |
201 { | 203 { |
202 if [ $# -gt 0 ]; then | 204 if [ $# -gt 0 ]; then |
203 echo "xdg-terminal: $@" >&2 | 205 echo "xdg-terminal: $@" >&2 |
204 fi | 206 fi |
205 | 207 |
206 exit 6 | 208 exit 6 |
207 } | 209 } |
208 | 210 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 echo "Use 'man xdg-terminal' or 'xdg-terminal --manual' for addition
al info." | 267 echo "Use 'man xdg-terminal' or 'xdg-terminal --manual' for addition
al info." |
266 exit_success | 268 exit_success |
267 ;; | 269 ;; |
268 | 270 |
269 --manual) | 271 --manual) |
270 manualpage | 272 manualpage |
271 exit_success | 273 exit_success |
272 ;; | 274 ;; |
273 | 275 |
274 --version) | 276 --version) |
275 echo "xdg-terminal 1.0.1" | 277 echo "xdg-terminal 1.0.2" |
276 exit_success | 278 exit_success |
277 ;; | 279 ;; |
278 esac | 280 esac |
279 done | 281 done |
280 } | 282 } |
281 | 283 |
282 check_common_commands "$@" | 284 check_common_commands "$@" |
283 | 285 |
284 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; | 286 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; |
285 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then | 287 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then |
286 # Be silent | 288 # Be silent |
287 xdg_redirect_output=" > /dev/null 2> /dev/null" | 289 xdg_redirect_output=" > /dev/null 2> /dev/null" |
288 else | 290 else |
289 # All output to stderr | 291 # All output to stderr |
290 xdg_redirect_output=" >&2" | 292 xdg_redirect_output=" >&2" |
291 fi | 293 fi |
292 | 294 |
293 #-------------------------------------- | 295 #-------------------------------------- |
294 # Checks for known desktop environments | 296 # Checks for known desktop environments |
295 # set variable DE to the desktop environments name, lowercase | 297 # set variable DE to the desktop environments name, lowercase |
296 | 298 |
297 detectDE() | 299 detectDE() |
298 { | 300 { |
299 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; | 301 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; |
300 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; | 302 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; |
301 elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then
DE=xfce; | 303 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/D
Bus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/nul
l 2>&1` ; then DE=gnome; |
| 304 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; |
| 305 elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde; |
| 306 else DE="" |
302 fi | 307 fi |
303 } | 308 } |
304 | 309 |
305 #---------------------------------------------------------------------------- | 310 #---------------------------------------------------------------------------- |
306 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 | 311 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 |
307 # It also always returns 1 in KDE 3.4 and earlier | 312 # It also always returns 1 in KDE 3.4 and earlier |
308 # Simply return 0 in such case | 313 # Simply return 0 in such case |
309 | 314 |
310 kfmclient_fix_exit_code() | 315 kfmclient_fix_exit_code() |
311 { | 316 { |
312 version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE` | 317 version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep '^KDE
'` |
313 major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'` | 318 major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'` |
314 minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'` | 319 minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'` |
315 release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` | 320 release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` |
316 test "$major" -gt 3 && return $1 | 321 test "$major" -gt 3 && return $1 |
317 test "$minor" -gt 5 && return $1 | 322 test "$minor" -gt 5 && return $1 |
318 test "$release" -gt 4 && return $1 | 323 test "$release" -gt 4 && return $1 |
319 return 0 | 324 return 0 |
320 } | 325 } |
321 | 326 |
322 terminal_kde() | 327 terminal_kde() |
323 { | 328 { |
324 terminal=`kreadconfig --file kdeglobals --group General --key TerminalApplic
ation --default konsole` | 329 terminal=`kreadconfig --file kdeglobals --group General --key TerminalApplic
ation --default konsole` |
325 | 330 |
326 terminal_exec=`which $terminal >/dev/null 2>/dev/null` | 331 terminal_exec=`which $terminal 2>/dev/null` |
327 | 332 |
328 if [ -x "$terminal_exec" ]; then | 333 if [ -x "$terminal_exec" ]; then |
329 if [ x"$1" == x"" ]; then | 334 if [ x"$1" == x"" ]; then |
330 $terminal_exec | 335 $terminal_exec |
331 else | 336 else |
332 $terminal_exec -e "$1" | 337 $terminal_exec -e "$1" |
333 fi | 338 fi |
334 | 339 |
335 if [ $? -eq 0 ]; then | 340 if [ $? -eq 0 ]; then |
336 exit_success | 341 exit_success |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 if [ $? -eq 0 ]; then | 406 if [ $? -eq 0 ]; then |
402 exit_success | 407 exit_success |
403 else | 408 else |
404 exit_failure_operation_failed | 409 exit_failure_operation_failed |
405 fi | 410 fi |
406 else | 411 else |
407 exit_failure_operation_impossible "configured terminal program '$TERM' n
ot found or not executable" | 412 exit_failure_operation_impossible "configured terminal program '$TERM' n
ot found or not executable" |
408 fi | 413 fi |
409 } | 414 } |
410 | 415 |
| 416 terminal_lxde() |
| 417 { |
| 418 if which lxterminal &>/dev/null; then |
| 419 if [ x"$1" == x"" ]; then |
| 420 lxterminal |
| 421 else |
| 422 lxterminal -e "$1" |
| 423 fi |
| 424 else |
| 425 terminal_generic "$1" |
| 426 fi |
| 427 } |
| 428 |
411 #[ x"$1" != x"" ] || exit_failure_syntax | 429 #[ x"$1" != x"" ] || exit_failure_syntax |
412 | 430 |
413 command= | 431 command= |
414 while [ $# -gt 0 ] ; do | 432 while [ $# -gt 0 ] ; do |
415 parm="$1" | 433 parm="$1" |
416 shift | 434 shift |
417 | 435 |
418 case "$parm" in | 436 case "$parm" in |
419 -*) | 437 -*) |
420 exit_failure_syntax "unexpected option '$parm'" | 438 exit_failure_syntax "unexpected option '$parm'" |
(...skipping 24 matching lines...) Expand all Loading... |
445 ;; | 463 ;; |
446 | 464 |
447 gnome) | 465 gnome) |
448 terminal_gnome "$command" | 466 terminal_gnome "$command" |
449 ;; | 467 ;; |
450 | 468 |
451 xfce) | 469 xfce) |
452 terminal_xfce "$command" | 470 terminal_xfce "$command" |
453 ;; | 471 ;; |
454 | 472 |
| 473 lxde) |
| 474 terminal_lxde "$command" |
| 475 ;; |
| 476 |
455 generic) | 477 generic) |
456 terminal_generic "$command" | 478 terminal_generic "$command" |
457 ;; | 479 ;; |
458 | 480 |
459 *) | 481 *) |
460 exit_failure_operation_impossible "no terminal emulator available" | 482 exit_failure_operation_impossible "no terminal emulator available" |
461 ;; | 483 ;; |
462 esac | 484 esac |
OLD | NEW |