]> git.ipfire.org Git - thirdparty/git.git/blame - git-browse-help.sh
git.spec.in: remove python_path
[thirdparty/git.git] / git-browse-help.sh
CommitLineData
5d6491c7
CC
1#!/bin/sh
2#
3# This program launch a web browser on the html page
4# describing a git command.
5#
6# Copyright (c) 2007 Christian Couder
7# Copyright (c) 2006 Theodore Y. Ts'o
8#
9# This file is heavily stolen from git-mergetool.sh, by
10# Theodore Y. Ts'o (thanks) that is:
11#
12# Copyright (c) 2006 Theodore Y. Ts'o
13#
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
16# git maintainer.
17#
18
19USAGE='[--browser=browser|--tool=browser] [cmd to display] ...'
20SUBDIRECTORY_OK=Yes
21OPTIONS_SPEC=
22. git-sh-setup
23
24# Install data.
25html_dir="@@HTMLDIR@@"
26
27test -f "$html_dir/git.html" || die "No documentation directory found."
28
29valid_tool() {
30 case "$1" in
31 firefox | iceweasel | konqueror | w3m | links | lynx | dillo)
32 ;; # happy
33 *)
34 return 1
35 ;;
36 esac
37}
38
39init_browser_path() {
40 browser_path=`git config browser.$1.path`
41 test -z "$browser_path" && browser_path=$1
42}
43
44while test $# != 0
45do
46 case "$1" in
47 -b|--browser*|-t|--tool*)
48 case "$#,$1" in
49 *,*=*)
50 browser=`expr "z$1" : 'z-[^=]*=\(.*\)'`
51 ;;
52 1,*)
53 usage ;;
54 *)
55 browser="$2"
56 shift ;;
57 esac
58 ;;
59 --)
60 break
61 ;;
62 -*)
63 usage
64 ;;
65 *)
66 break
67 ;;
68 esac
69 shift
70done
71
72if test -z "$browser"; then
d3a866bc
CC
73 for opt in "help.browser" "web.browser"
74 do
75 browser="`git config $opt`"
76 test -z "$browser" || break
77 done
5d6491c7 78 if test -n "$browser" && ! valid_tool "$browser"; then
d3a866bc 79 echo >&2 "git config option $opt set to unknown browser: $browser"
5d6491c7
CC
80 echo >&2 "Resetting to default..."
81 unset browser
82 fi
83fi
84
85if 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"
90 fi
91 else
92 browser_candidates="w3m links lynx"
93 fi
94 echo "browser candidates: $browser_candidates"
95 for i in $browser_candidates; do
96 init_browser_path $i
97 if type "$browser_path" > /dev/null 2>&1; then
98 browser=$i
99 break
100 fi
101 done
102 test -z "$browser" && die "No known browser available."
103else
104 valid_tool "$browser" || die "Unknown browser '$browser'."
105
106 init_browser_path "$browser"
107
108 if ! type "$browser_path" > /dev/null 2>&1; then
109 die "The browser $browser is not available as '$browser_path'."
110 fi
111fi
112
113pages=$(for p in "$@"; do echo "$html_dir/$p.html" ; done)
114test -z "$pages" && pages="$html_dir/git.html"
115
116case "$browser" in
117 firefox|iceweasel)
118 # Check version because firefox < 2.0 does not support "-new-tab".
119 vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
120 NEWTAB='-new-tab'
121 test "$vers" -lt 2 && NEWTAB=''
122 nohup "$browser_path" $NEWTAB $pages &
123 ;;
124 konqueror)
125 case "$(basename "$browser_path")" in
126 konqueror)
127 # It's simpler to use kfmclient to open a new tab in konqueror.
128 browser_path="$(echo "$browser_path" | sed -e 's/konqueror$/kfmclient/')"
129 type "$browser_path" > /dev/null 2>&1 || die "No '$browser_path' found."
130 eval "$browser_path" newTab $pages
131 ;;
132 kfmclient)
133 eval "$browser_path" newTab $pages
134 ;;
135 *)
136 nohup "$browser_path" $pages &
137 ;;
138 esac
139 ;;
140 w3m|links|lynx)
141 eval "$browser_path" $pages
142 ;;
143 dillo)
144 nohup "$browser_path" $pages &
145 ;;
146esac