summaryrefslogtreecommitdiff
path: root/shell/source/unix/misc/open-url.sh
blob: 8cfcf0e09358ed86c9dfc42e04ee8254fcb884ba (plain)
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
#!/bin/sh
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#
#   Licensed to the Apache Software Foundation (ASF) under one or more
#   contributor license agreements. See the NOTICE file distributed
#   with this work for additional information regarding copyright
#   ownership. The ASF licenses this file to you under the Apache
#   License, Version 2.0 (the "License"); you may not use this file
#   except in compliance with the License. You may obtain a copy of
#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
#

# tries to locate the executable specified
# as first parameter in the user's path.
which() {
  if [ ! -z "$1" ]; then
    for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
      if [ -x "$i/$1" -a ! -d "$i/$1" ]; then
        echo "$i/$1"
        break;
      fi
    done
  fi
}

# checks for the original mozilla start script(s)
# and restrict the "-remote" semantics to those.
run_mozilla() {
    "$1" -new-tab "$2" &
}

# special handling for mailto: uris
if echo "$1" | grep '^mailto:' > /dev/null; then
  # check for xdg-email
  mailer=`which xdg-email`
  if [ ! -z "$mailer" ]; then
    $mailer "$1" &
    exit 0
  fi
  # check $MAILER variable
  if [ ! -z "$MAILER" ]; then
    $MAILER "$1" &
    exit 0
  fi
  # mozilla derivates may need -remote semantics
  for i in thunderbird mozilla netscape icedove iceape; do
    mailer=`which $i`
    if [ ! -z "$mailer" ]; then
      run_mozilla "$mailer" "$1"
      exit 0
    fi
  done
  # handle all non mozilla mail clients below
  # ..
else
  # check for xdg-open
  browser=`which xdg-open`
  if [ ! -z "$browser" ]; then
    $browser "$1" &
    exit 0
  fi
  # check $BROWSER variable
  if [ ! -z "$BROWSER" ]; then
    $BROWSER "$1" &
    exit 0
  fi
  # mozilla derivates may need -remote semantics
  for i in chrome seamonkey firefox iceweasel iceape; do
    browser=`which $i`
    if [ ! -z "$browser" ]; then
      run_mozilla "$browser" "$1"
      exit 0
    fi
  done
  # handle all non mozilla browers below
  # ..
fi
exit 1