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] [--config=conf.var] 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 browser_cmd="$(git config "browser.$1.cmd")"
29 test -n "$browser_cmd"
34 firefox | iceweasel | seamonkey | iceape | \
35 chrome | google-chrome | chromium | chromium-browser | \
36 konqueror | opera | w3m | elinks | links | lynx | dillo | open | \
37 start | cygstart | xdg-open)
40 valid_custom_tool "$1" || return 1
46 browser_path=$(git config "browser.$1.path")
47 if test -z "$browser_path" &&
48 test "$1" = chromium &&
49 type chromium-browser >/dev/null 2>&1
51 browser_path=chromium-browser
53 : ${browser_path:="$1"}
59 -b|--browser*|-t|--tool*)
62 browser=$(expr "z$1" : 'z-[^=]*=\(.*\)')
74 conf=$(expr "z$1" : 'z-[^=]*=\(.*\)')
100 for opt in "$conf" "web.browser"
102 test -z "$opt" && continue
103 browser="$(git config $opt)"
104 test -z "$browser" || break
106 if test -n "$browser" && ! valid_tool "$browser"; then
107 echo >&2 "git config option $opt set to unknown browser: $browser"
108 echo >&2 "Resetting to default..."
113 if test -z "$browser" ; then
114 if test -n "$DISPLAY"; then
115 browser_candidates="firefox iceweasel google-chrome chrome chromium chromium-browser konqueror opera seamonkey iceape w3m elinks links lynx dillo xdg-open"
116 if test "$KDE_FULL_SESSION" = "true"; then
117 browser_candidates="konqueror $browser_candidates"
120 browser_candidates="w3m elinks links lynx"
122 # SECURITYSESSIONID indicates an OS X GUI login session
123 if test -n "$SECURITYSESSIONID" || test -n "$TERM_PROGRAM"
125 browser_candidates="open $browser_candidates"
127 # /bin/start indicates MinGW
128 if test -x /bin/start; then
129 browser_candidates="start $browser_candidates"
131 # /usr/bin/cygstart indicates Cygwin
132 if test -x /usr/bin/cygstart; then
133 browser_candidates="cygstart $browser_candidates"
136 for i in $browser_candidates; do
138 if type "$browser_path" > /dev/null 2>&1; then
143 test -z "$browser" && die "No known browser available."
145 valid_tool "$browser" || die "Unknown browser '$browser'."
147 init_browser_path "$browser"
149 if test -z "$browser_cmd" && ! type "$browser_path" > /dev/null 2>&1; then
150 die "The browser $browser is not available as '$browser_path'."
155 firefox|iceweasel|seamonkey|iceape)
156 # Check version because firefox < 2.0 does not support "-new-tab".
157 vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
159 test "$vers" -lt 2 && NEWTAB=''
160 "$browser_path" $NEWTAB "$@" &
162 google-chrome|chrome|chromium|chromium-browser)
163 # No need to specify newTab. It's default in chromium
164 "$browser_path" "$@" &
167 case "$(basename "$browser_path")" in
169 # It's simpler to use kfmclient to open a new tab in konqueror.
170 browser_path="$(echo "$browser_path" | sed -e 's/konqueror$/kfmclient/')"
171 type "$browser_path" > /dev/null 2>&1 || die "No '$browser_path' found."
172 "$browser_path" newTab "$@" &
175 "$browser_path" newTab "$@" &
178 "$browser_path" "$@" &
182 w3m|elinks|links|lynx|open|cygstart|xdg-open)
186 exec "$browser_path" '"web-browse"' "$@"
189 "$browser_path" "$@" &
192 if test -n "$browser_cmd"; then
193 ( eval "$browser_cmd \"\$@\"" )