2007-12-02 13:07:55 +08: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 14:32:41 +08:00
|
|
|
USAGE='[--browser=browser|--tool=browser] [--config=conf.var] url/file ...'
|
2007-12-13 09:34:30 +08: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 13:07:55 +08:00
|
|
|
. git-sh-setup
|
|
|
|
|
2008-03-14 12:56:49 +08:00
|
|
|
valid_custom_tool()
|
|
|
|
{
|
|
|
|
browser_cmd="$(git config "browser.$1.cmd")"
|
|
|
|
test -n "$browser_cmd"
|
|
|
|
}
|
|
|
|
|
2007-12-02 13:07:55 +08:00
|
|
|
valid_tool() {
|
|
|
|
case "$1" in
|
2010-12-04 00:47:37 +08:00
|
|
|
firefox | iceweasel | chrome | google-chrome | chromium | \
|
|
|
|
konqueror | w3m | links | lynx | dillo | open | start)
|
2010-12-04 00:47:36 +08:00
|
|
|
;; # happy
|
|
|
|
*)
|
|
|
|
valid_custom_tool "$1" || return 1
|
|
|
|
;;
|
2007-12-02 13:07:55 +08:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
init_browser_path() {
|
2008-02-11 23:57:34 +08:00
|
|
|
browser_path=$(git config "browser.$1.path")
|
2008-02-09 14:11:01 +08:00
|
|
|
test -z "$browser_path" && browser_path="$1"
|
2007-12-02 13:07:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while test $# != 0
|
|
|
|
do
|
2010-12-04 00:47:36 +08:00
|
|
|
case "$1" in
|
2007-12-02 13:07:55 +08:00
|
|
|
-b|--browser*|-t|--tool*)
|
2010-12-04 00:47:36 +08:00
|
|
|
case "$#,$1" in
|
2007-12-02 13:07:55 +08:00
|
|
|
*,*=*)
|
2010-12-04 00:47:36 +08:00
|
|
|
browser=`expr "z$1" : 'z-[^=]*=\(.*\)'`
|
|
|
|
;;
|
2007-12-02 13:07:55 +08:00
|
|
|
1,*)
|
2010-12-04 00:47:36 +08:00
|
|
|
usage ;;
|
2007-12-02 13:07:55 +08:00
|
|
|
*)
|
2010-12-04 00:47:36 +08:00
|
|
|
browser="$2"
|
|
|
|
shift ;;
|
|
|
|
esac
|
|
|
|
;;
|
2008-02-02 14:32:41 +08:00
|
|
|
-c|--config*)
|
2010-12-04 00:47:36 +08:00
|
|
|
case "$#,$1" in
|
2008-02-02 14:32:41 +08:00
|
|
|
*,*=*)
|
2010-12-04 00:47:36 +08:00
|
|
|
conf=`expr "z$1" : 'z-[^=]*=\(.*\)'`
|
|
|
|
;;
|
2008-02-02 14:32:41 +08:00
|
|
|
1,*)
|
2010-12-04 00:47:36 +08:00
|
|
|
usage ;;
|
2008-02-02 14:32:41 +08:00
|
|
|
*)
|
2010-12-04 00:47:36 +08:00
|
|
|
conf="$2"
|
|
|
|
shift ;;
|
|
|
|
esac
|
|
|
|
;;
|
2007-12-02 13:07:55 +08:00
|
|
|
--)
|
2010-12-04 00:47:36 +08:00
|
|
|
break
|
|
|
|
;;
|
2007-12-02 13:07:55 +08:00
|
|
|
-*)
|
2010-12-04 00:47:36 +08:00
|
|
|
usage
|
|
|
|
;;
|
2007-12-02 13:07:55 +08:00
|
|
|
*)
|
2010-12-04 00:47:36 +08:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2007-12-02 13:07:55 +08:00
|
|
|
done
|
|
|
|
|
2008-02-02 14:32:33 +08:00
|
|
|
test $# = 0 && usage
|
|
|
|
|
2007-12-15 12:57:28 +08:00
|
|
|
if test -z "$browser"
|
2007-12-13 09:34:30 +08:00
|
|
|
then
|
2010-12-04 00:47:36 +08: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 13:07:55 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test -z "$browser" ; then
|
2010-12-04 00:47:36 +08:00
|
|
|
if test -n "$DISPLAY"; then
|
|
|
|
browser_candidates="firefox iceweasel google-chrome chrome chromium konqueror w3m links lynx dillo"
|
|
|
|
if test "$KDE_FULL_SESSION" = "true"; then
|
|
|
|
browser_candidates="konqueror $browser_candidates"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
browser_candidates="w3m links lynx"
|
2007-12-02 13:07:55 +08:00
|
|
|
fi
|
2010-12-04 00:47:36 +08: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 13:07:55 +08:00
|
|
|
fi
|
2010-12-04 00:47:36 +08: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 13:07:55 +08:00
|
|
|
else
|
2010-12-04 00:47:36 +08:00
|
|
|
valid_tool "$browser" || die "Unknown browser '$browser'."
|
2007-12-02 13:07:55 +08:00
|
|
|
|
2010-12-04 00:47:36 +08:00
|
|
|
init_browser_path "$browser"
|
2007-12-02 13:07:55 +08:00
|
|
|
|
2010-12-04 00:47:36 +08: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 13:07:55 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
case "$browser" in
|
2010-12-04 00:47:36 +08:00
|
|
|
firefox|iceweasel)
|
2007-12-02 13:07:55 +08: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 15:22:22 +08:00
|
|
|
"$browser_path" $NEWTAB "$@" &
|
2007-12-02 13:07:55 +08:00
|
|
|
;;
|
2010-12-04 00:47:36 +08:00
|
|
|
google-chrome|chrome|chromium)
|
2010-05-30 02:36:51 +08:00
|
|
|
# Actual command for chromium is chromium-browser.
|
|
|
|
# No need to specify newTab. It's default in chromium
|
|
|
|
eval "$browser_path" "$@" &
|
|
|
|
;;
|
2010-12-04 00:47:36 +08:00
|
|
|
konqueror)
|
2007-12-02 13:07:55 +08:00
|
|
|
case "$(basename "$browser_path")" in
|
2010-12-04 00:47:36 +08:00
|
|
|
konqueror)
|
2007-12-02 13:07:55 +08: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."
|
2008-02-02 14:32:33 +08:00
|
|
|
eval "$browser_path" newTab "$@"
|
2007-12-02 13:07:55 +08:00
|
|
|
;;
|
2010-12-04 00:47:36 +08:00
|
|
|
kfmclient)
|
2008-02-02 14:32:33 +08:00
|
|
|
eval "$browser_path" newTab "$@"
|
2007-12-02 13:07:55 +08:00
|
|
|
;;
|
2010-12-04 00:47:36 +08:00
|
|
|
*)
|
2008-02-10 15:22:22 +08:00
|
|
|
"$browser_path" "$@" &
|
2007-12-02 13:07:55 +08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2010-12-04 00:47:36 +08:00
|
|
|
w3m|links|lynx|open)
|
2008-02-02 14:32:33 +08:00
|
|
|
eval "$browser_path" "$@"
|
2007-12-02 13:07:55 +08:00
|
|
|
;;
|
2010-12-04 00:47:36 +08:00
|
|
|
start)
|
|
|
|
exec "$browser_path" '"web-browse"' "$@"
|
|
|
|
;;
|
|
|
|
dillo)
|
2008-02-10 15:22:22 +08:00
|
|
|
"$browser_path" "$@" &
|
2007-12-02 13:07:55 +08:00
|
|
|
;;
|
2010-12-04 00:47:36 +08:00
|
|
|
*)
|
2008-03-14 12:56:49 +08:00
|
|
|
if test -n "$browser_cmd"; then
|
2010-12-04 00:47:36 +08:00
|
|
|
( eval $browser_cmd "$@" )
|
2008-03-14 12:56:49 +08:00
|
|
|
fi
|
|
|
|
;;
|
2007-12-02 13:07:55 +08:00
|
|
|
esac
|