aboutsummaryrefslogtreecommitdiffstats
path: root/bin/www-browser
blob: df6b350a27dcd47f5cbaf0ffaaf2ae30ecda5bd9 (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
86
87
88
89
90
91
92
93
#!/bin/sh
#---------------------------------------------------------------
# Project         : Mandrakelinux
# Module          : bin
# File            : www-browser
# Version         : $Id: www-browser 243941 2008-08-12 12:48:22Z fcrozat $
# Author          : Frederic Lepied
# Created On      : Tue Aug 31 16:26:54 2004
# Purpose         : launch a web browser
#---------------------------------------------------------------

#
# If we got any argument, we can call xdg-open, if we haven´t already done it
#
if [ -n "$*" -a -z "$THROUGHXDG" ]; then
	# Lock against bug #29599
	export THROUGHXDG=1
	exec xdg-open "$@"
fi

#
# No URL specified, so we must find a proper browser for the current env
#

strip_browser_var() {
    if [[ -n "$BROWSER" ]]; then
	if [[ `basename "$BROWSER"` == "www-browser" ]]; then
	    unset BROWSER
	else
	    set $BROWSER
	    if ! which $1 > /dev/null 2>&1; then
		unset BROWSER
	    fi
	fi
    fi
}

strip_browser_var
if [[ -z "$BROWSER" ]]; then
 
    # using GNOME
    if [[ -n "$GNOME_DESKTOP_SESSION_ID" ]]; then
	BROWSER=`gconftool -g /desktop/gnome/url-handlers/http/command | sed -e 's/ %s//'`
	if [[ `gconftool -g /desktop/gnome/url-handlers/http/needs_terminal` == "true" ]]; then
	    BROWSER="xvt -e $BROWSER"
	fi
    fi

    #using KDE
    if [[ -n "$KDE_FULL_SESSION" ]]; then
	NEWBROWSER=`kreadconfig --group General --key BrowserApplication 2>/dev/null`
	if [[ -n "$NEWBROWSER" ]]; then
	    BROWSER=`echo $NEWBROWSER | sed -e 's/\(.*\).desktop/\1/'`
	    if [[ x"$KDE_SESSION_VERSION" == x"4" ]]; then   # KDE 4
		BROWSER="dbus-send --type=method_call --dest=org.kde.klauncher /KLauncher org.kde.KLauncher.start_service_by_desktop_name string:$BROWSER array:string: array:string: string: boolean:true"
	    else                                        # KDE 3
		BROWSER="dcop klauncher default start_service_by_desktop_name(QString,QStringList) $BROWSER [ ]"
	    fi
	fi
    fi

    #using XFCE
    if xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then
	    BROWSER="exo-open --launch WebBrowser"
    fi


    strip_browser_var
    
    [[ -z "$BROWSER" ]] && BROWSER=`which firefox 2> /dev/null` 
    [[ -z "$BROWSER" ]] && BROWSER=`which mozilla-firefox 2> /dev/null` 
    [[ -z "$BROWSER" ]] && [[ -n "$KDE_FULL_SESSION" ]] && which kfmclient > /dev/null 2>&1 && BROWSER="kfmclient openProfile webbrowsing"
    [[ -z "$BROWSER" ]] && BROWSER=`which epiphany 2> /dev/null`
    [[ -z "$BROWSER" ]] && BROWSER=`which galeon 2> /dev/null`
    [[ -z "$BROWSER" ]] && BROWSER=`which seamonkey 2> /dev/null`
    [[ -z "$BROWSER" ]] && BROWSER=`which chromium-browser 2> /dev/null`
    [[ -z "$BROWSER" ]] && which kfmclient > /dev/null 2>&1 && BROWSER="kfmclient openProfile webbrowsing"
    [[ -z "$BROWSER" ]] && which links > /dev/null 2>&1 && BROWSER="xvt -e links"
    [[ -z "$BROWSER" ]] && which lynx > /dev/null 2>&1 && BROWSER="xvt -e lynx"
fi

if [[ -n "$BROWSER" ]]; then 
    if [[ -n "$THROUGHXDG" ]]; then
	# xdg couldn't handle the url
	exec $BROWSER $@
    else
	exec $BROWSER
    fi
else
    echo "no web browser detected"
fi

# www-browser ends here