2007-12-02 06:07:55 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# This program launch a web browser on the html page
|
|
|
|
# describing a git command.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Christian Couder
|
|
|
|
# Copyright (c) 2006 Theodore Y. Ts'o
|
|
|
|
#
|
|
|
|
# This file is heavily stolen from git-mergetool.sh, by
|
|
|
|
# Theodore Y. Ts'o (thanks) that is:
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Theodore Y. Ts'o
|
|
|
|
#
|
|
|
|
# This file is licensed under the GPL v2, or a later version
|
|
|
|
# at the discretion of Junio C Hamano or any other official
|
|
|
|
# git maintainer.
|
|
|
|
#
|
|
|
|
|
2008-02-02 07:32:41 +01:00
|
|
|
USAGE='[--browser=browser|--tool=browser] [--config=conf.var] url/file ...'
|
2007-12-13 02:34:30 +01:00
|
|
|
|
|
|
|
# This must be capable of running outside of git directory, so
|
|
|
|
# the vanilla git-sh-setup should not be used.
|
|
|
|
NONGIT_OK=Yes
|
2007-12-02 06:07:55 +01:00
|
|
|
. git-sh-setup
|
|
|
|
|
2008-03-14 05:56:49 +01:00
|
|
|
valid_custom_tool()
|
|
|
|
{
|
|
|
|
browser_cmd="$(git config "browser.$1.cmd")"
|
|
|
|
test -n "$browser_cmd"
|
|
|
|
}
|
|
|
|
|
2007-12-02 06:07:55 +01:00
|
|
|
valid_tool() {
|
|
|
|
case "$1" in
|
2010-12-03 17:47:39 +01:00
|
|
|
firefox | iceweasel | seamonkey | iceape | \
|
|
|
|
chrome | google-chrome | chromium | chromium-browser |\
|
2010-12-03 17:47:38 +01:00
|
|
|
konqueror | opera | w3m | elinks | links | lynx | dillo | open | start)
|
2010-12-03 17:47:36 +01:00
|
|
|
;; # happy
|
|
|
|
*)
|
|
|
|
valid_custom_tool "$1" || return 1
|
|
|
|
;;
|
2007-12-02 06:07:55 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
init_browser_path() {
|
2008-02-11 16:57:34 +01:00
|
|
|
browser_path=$(git config "browser.$1.path")
|
2010-12-03 17:47:39 +01:00
|
|
|
if test -z "$browser_path" &&
|
|
|
|
test "$1" = chromium &&
|
|
|
|
type chromium-browser >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
browser_path=chromium-browser
|
|
|
|
fi
|
|
|
|
: ${browser_path:="$1"}
|
2007-12-02 06:07:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while test $# != 0
|
|
|
|
do
|
2010-12-03 17:47:36 +01:00
|
|
|
case "$1" in
|
2007-12-02 06:07:55 +01:00
|
|
|
-b|--browser*|-t|--tool*)
|
2010-12-03 17:47:36 +01:00
|
|
|
case "$#,$1" in
|
2007-12-02 06:07:55 +01:00
|
|
|
*,*=*)
|
2010-12-03 17:47:36 +01:00
|
|
|
browser=`expr "z$1" : 'z-[^=]*=\(.*\)'`
|
|
|
|
;;
|
2007-12-02 06:07:55 +01:00
|
|
|
1,*)
|
2010-12-03 17:47:36 +01:00
|
|
|
usage ;;
|
2007-12-02 06:07:55 +01:00
|
|
|
*)
|
2010-12-03 17:47:36 +01:00
|
|
|
browser="$2"
|
|
|
|
shift ;;
|
|
|
|
esac
|
|
|
|
;;
|
2008-02-02 07:32:41 +01:00
|
|
|
-c|--config*)
|
2010-12-03 17:47:36 +01:00
|
|
|
case "$#,$1" in
|
2008-02-02 07:32:41 +01:00
|
|
|
*,*=*)
|
2010-12-03 17:47:36 +01:00
|
|
|
conf=`expr "z$1" : 'z-[^=]*=\(.*\)'`
|
|
|
|
;;
|
2008-02-02 07:32:41 +01:00
|
|
|
1,*)
|
2010-12-03 17:47:36 +01:00
|
|
|
usage ;;
|
2008-02-02 07:32:41 +01:00
|
|
|
*)
|
2010-12-03 17:47:36 +01:00
|
|
|
conf="$2"
|
|
|
|
shift ;;
|
|
|
|
esac
|
|
|
|
;;
|
2007-12-02 06:07:55 +01:00
|
|
|
--)
|
2010-12-03 17:47:36 +01:00
|
|
|
break
|
|
|
|
;;
|
2007-12-02 06:07:55 +01:00
|
|
|
-*)
|
2010-12-03 17:47:36 +01:00
|
|
|
usage
|
|
|
|
;;
|
2007-12-02 06:07:55 +01:00
|
|
|
*)
|
2010-12-03 17:47:36 +01:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2007-12-02 06:07:55 +01:00
|
|
|
done
|
|
|
|
|
2008-02-02 07:32:33 +01:00
|
|
|
test $# = 0 && usage
|
|
|
|
|
2007-12-15 05:57:28 +01:00
|
|
|
if test -z "$browser"
|
2007-12-13 02:34:30 +01:00
|
|
|
then
|
2010-12-03 17:47:36 +01:00
|
|
|
for opt in "$conf" "web.browser"
|
|
|
|
do
|
|
|
|
test -z "$opt" && continue
|
|
|
|
browser="`git config $opt`"
|
|
|
|
test -z "$browser" || break
|
|
|
|
done
|
|
|
|
if test -n "$browser" && ! valid_tool "$browser"; then
|
|
|
|
echo >&2 "git config option $opt set to unknown browser: $browser"
|
|
|
|
echo >&2 "Resetting to default..."
|
|
|
|
unset browser
|
|
|
|
fi
|
2007-12-02 06:07:55 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test -z "$browser" ; then
|
2010-12-03 17:47:36 +01:00
|
|
|
if test -n "$DISPLAY"; then
|
2010-12-03 17:47:39 +01:00
|
|
|
browser_candidates="firefox iceweasel google-chrome chrome chromium chromium-browser konqueror opera seamonkey iceape w3m elinks links lynx dillo"
|
2010-12-03 17:47:36 +01:00
|
|
|
if test "$KDE_FULL_SESSION" = "true"; then
|
|
|
|
browser_candidates="konqueror $browser_candidates"
|
|
|
|
fi
|
|
|
|
else
|
2010-12-03 17:47:38 +01:00
|
|
|
browser_candidates="w3m elinks links lynx"
|
2007-12-02 06:07:55 +01:00
|
|
|
fi
|
2010-12-03 17:47:36 +01:00
|
|
|
# SECURITYSESSIONID indicates an OS X GUI login session
|
|
|
|
if test -n "$SECURITYSESSIONID" \
|
|
|
|
-o "$TERM_PROGRAM" = "Apple_Terminal" ; then
|
|
|
|
browser_candidates="open $browser_candidates"
|
2007-12-02 06:07:55 +01:00
|
|
|
fi
|
2010-12-03 17:47:36 +01:00
|
|
|
# /bin/start indicates MinGW
|
|
|
|
if test -x /bin/start; then
|
|
|
|
browser_candidates="start $browser_candidates"
|
|
|
|
fi
|
|
|
|
|
|
|
|
for i in $browser_candidates; do
|
|
|
|
init_browser_path $i
|
|
|
|
if type "$browser_path" > /dev/null 2>&1; then
|
|
|
|
browser=$i
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
test -z "$browser" && die "No known browser available."
|
2007-12-02 06:07:55 +01:00
|
|
|
else
|
2010-12-03 17:47:36 +01:00
|
|
|
valid_tool "$browser" || die "Unknown browser '$browser'."
|
2007-12-02 06:07:55 +01:00
|
|
|
|
2010-12-03 17:47:36 +01:00
|
|
|
init_browser_path "$browser"
|
2007-12-02 06:07:55 +01:00
|
|
|
|
2010-12-03 17:47:36 +01:00
|
|
|
if test -z "$browser_cmd" && ! type "$browser_path" > /dev/null 2>&1; then
|
|
|
|
die "The browser $browser is not available as '$browser_path'."
|
|
|
|
fi
|
2007-12-02 06:07:55 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
case "$browser" in
|
2010-12-03 17:47:38 +01:00
|
|
|
firefox|iceweasel|seamonkey|iceape)
|
2007-12-02 06:07:55 +01:00
|
|
|
# Check version because firefox < 2.0 does not support "-new-tab".
|
|
|
|
vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
|
|
|
|
NEWTAB='-new-tab'
|
|
|
|
test "$vers" -lt 2 && NEWTAB=''
|
2008-02-10 08:22:22 +01:00
|
|
|
"$browser_path" $NEWTAB "$@" &
|
2007-12-02 06:07:55 +01:00
|
|
|
;;
|
2010-12-03 17:47:39 +01:00
|
|
|
google-chrome|chrome|chromium|chromium-browser)
|
2010-05-29 20:36:51 +02:00
|
|
|
# No need to specify newTab. It's default in chromium
|
2011-10-02 02:44:17 +02:00
|
|
|
"$browser_path" "$@" &
|
2010-05-29 20:36:51 +02:00
|
|
|
;;
|
2010-12-03 17:47:36 +01:00
|
|
|
konqueror)
|
2007-12-02 06:07:55 +01:00
|
|
|
case "$(basename "$browser_path")" in
|
2010-12-03 17:47:36 +01:00
|
|
|
konqueror)
|
2007-12-02 06:07:55 +01:00
|
|
|
# It's simpler to use kfmclient to open a new tab in konqueror.
|
|
|
|
browser_path="$(echo "$browser_path" | sed -e 's/konqueror$/kfmclient/')"
|
|
|
|
type "$browser_path" > /dev/null 2>&1 || die "No '$browser_path' found."
|
2011-10-02 02:44:17 +02:00
|
|
|
"$browser_path" newTab "$@" &
|
2007-12-02 06:07:55 +01:00
|
|
|
;;
|
2010-12-03 17:47:36 +01:00
|
|
|
kfmclient)
|
2011-10-02 02:44:17 +02:00
|
|
|
"$browser_path" newTab "$@" &
|
2007-12-02 06:07:55 +01:00
|
|
|
;;
|
2010-12-03 17:47:36 +01:00
|
|
|
*)
|
2008-02-10 08:22:22 +01:00
|
|
|
"$browser_path" "$@" &
|
2007-12-02 06:07:55 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2010-12-03 17:47:38 +01:00
|
|
|
w3m|elinks|links|lynx|open)
|
2011-10-02 02:44:17 +02:00
|
|
|
"$browser_path" "$@"
|
2007-12-02 06:07:55 +01:00
|
|
|
;;
|
2010-12-03 17:47:36 +01:00
|
|
|
start)
|
|
|
|
exec "$browser_path" '"web-browse"' "$@"
|
|
|
|
;;
|
2010-12-03 17:47:38 +01:00
|
|
|
opera|dillo)
|
2008-02-10 08:22:22 +01:00
|
|
|
"$browser_path" "$@" &
|
2007-12-02 06:07:55 +01:00
|
|
|
;;
|
2010-12-03 17:47:36 +01:00
|
|
|
*)
|
2008-03-14 05:56:49 +01:00
|
|
|
if test -n "$browser_cmd"; then
|
2011-10-02 02:44:17 +02:00
|
|
|
( eval "$browser_cmd \"\$@\"" )
|
2008-03-14 05:56:49 +01:00
|
|
|
fi
|
|
|
|
;;
|
2007-12-02 06:07:55 +01:00
|
|
|
esac
|