3 # This program launch a web browser on the html page
4 # describing a git command.
6 # Copyright (c) 2007 Christian Couder
7 # Copyright (c) 2006 Theodore Y. Ts'o
9 # This file is heavily stolen from git-mergetool.sh, by
10 # Theodore Y. Ts'o (thanks) that is:
12 # Copyright (c) 2006 Theodore Y. Ts'o
14 # This file is licensed under the GPL v2, or a later version
15 # at the discretion of Junio C Hamano or any other official
19 USAGE='[--browser=browser|--tool=browser] url/file ...'
21 # This must be capable of running outside of git directory, so
22 # the vanilla git-sh-setup should not be used.
28 firefox | iceweasel | konqueror | w3m | links | lynx | dillo)
37 browser_path=`git config browser.$1.path`
38 test -z "$browser_path" && browser_path=$1
44 -b|--browser*|-t|--tool*)
47 browser=`expr "z$1" : 'z-[^=]*=\(.*\)'`
73 for opt in "help.browser" "web.browser"
75 browser="`git config $opt`"
76 test -z "$browser" || break
78 if test -n "$browser" && ! valid_tool "$browser"; then
79 echo >&2 "git config option $opt set to unknown browser: $browser"
80 echo >&2 "Resetting to default..."
85 if test -z "$browser" ; then
86 if test -n "$DISPLAY"; then
87 browser_candidates="firefox iceweasel konqueror w3m links lynx dillo"
88 if test "$KDE_FULL_SESSION" = "true"; then
89 browser_candidates="konqueror $browser_candidates"
92 browser_candidates="w3m links lynx"
95 for i in $browser_candidates; do
97 if type "$browser_path" > /dev/null 2>&1; then
102 test -z "$browser" && die "No known browser available."
104 valid_tool "$browser" || die "Unknown browser '$browser'."
106 init_browser_path "$browser"
108 if ! type "$browser_path" > /dev/null 2>&1; then
109 die "The browser $browser is not available as '$browser_path'."
115 # Check version because firefox < 2.0 does not support "-new-tab".
116 vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
118 test "$vers" -lt 2 && NEWTAB=''
119 nohup "$browser_path" $NEWTAB "$@" &
122 case "$(basename "$browser_path")" in
124 # It's simpler to use kfmclient to open a new tab in konqueror.
125 browser_path="$(echo "$browser_path" | sed -e 's/konqueror$/kfmclient/')"
126 type "$browser_path" > /dev/null 2>&1 || die "No '$browser_path' found."
127 eval "$browser_path" newTab "$@"
130 eval "$browser_path" newTab "$@"
133 nohup "$browser_path" "$@" &
138 eval "$browser_path" "$@"
141 nohup "$browser_path" "$@" &