From: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Christian Couder <christian.couder@gmail.com>,
Jonathan Nieder <jrnieder@gmail.com>,
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Subject: [PATCHv3 6/6] web--browse: look at the BROWSER env var
Date: Mon, 6 Dec 2010 18:49:50 +0100 [thread overview]
Message-ID: <1291657790-3719-7-git-send-email-giuseppe.bilotta@gmail.com> (raw)
In-Reply-To: <1291657790-3719-1-git-send-email-giuseppe.bilotta@gmail.com>
The BROWSER environment variables is used in Debian-based systems to set
the user-preferred browser(s).
It contains a colon-separate list of commands to (try to) execute
to open a web page. Each item in the list is allowed to have a %s
placeholder to be replaced by the URL, in which case we try to run the
command as is. If no placeholder is found, we only look at the command
name to see if it matches one of our known browsers.
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
git-web--browse.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/git-web--browse.sh b/git-web--browse.sh
index b496b6c..da36ca4 100755
--- a/git-web--browse.sh
+++ b/git-web--browse.sh
@@ -164,6 +164,51 @@ then
fi
fi
+# Debian and derivatives provide a sensible-brower script that tries to
+# invoke the user or system preferred browser most appropriate for the
+# current situation (X or no X, GNOME or other/no DE).
+# We do not use the sensible-browser script directly since it doesn't
+# allow us to open pages in a new tab, but we can use the underlying
+# infrastructure to find the browser to use if the user didn't choose
+# one. This is done by looking at the BROWSER environment variable
+# first, and at the *www-browser links if the first search is
+# unsuccesful.
+
+# The BROWSER environment variable is a colon-separate list of commands
+# to (try and) execute to launch the browser. sensible-browser allows
+# each BROWSER entry to contain a %s placeholder that will be replaced
+# by the URL to be opened.
+# If an entry contains a %s we run it as-is, without doing any detection, on
+# the premise that it represents the exact way the user expects the browser to
+# be called. If the execution fails, we do not bail out, since the
+# failure might be due to the entry being for a graphical browser and
+# the GUI not being available, which is the reason why multiple entries
+# can be specified in BROWSER in the first place.
+# An entry without a %s is only taken as indication of the preferred
+# browser, so we proceed with our usual detection logic.
+if test -z "$browser" -a -n "$BROWSER"; then
+ OLDIFS="$IFS"
+ IFS=:
+ for i in $BROWSER; do
+ case "$i" in
+ *sensible-browser*)
+ ;; # skip
+ *%s*)
+ IFS="$OLDIFS"
+ cmd=$(printf "$i\n" "$*")
+ $cmd && exit 0
+ ;;
+ *)
+ prog=$(which "$i" 2> /dev/null)
+ if test -n "$prog" -a -x "$prog" && valid_browser_executable "$prog" ; then
+ break
+ fi
+ ;;
+ esac
+ done
+ IFS="$OLDIFS"
+fi
+
# Debian and derivatives use gnome-www-browser, x-www-browser or www-browser to
# set the default browser for the system. If the user did not specify a tool and
# we detect that one of the *www-browser links to a supported one, we pick it.
--
1.7.3.2.664.g294b8.dirty
next prev parent reply other threads:[~2010-12-06 17:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-06 17:49 [PATCHv3 0/6] web--browse cleanup and extensions Giuseppe Bilotta
2010-12-06 17:49 ` [PATCHv3 1/6] web--browse: coding style Giuseppe Bilotta
2010-12-06 17:49 ` [PATCHv3 2/6] web--browse: split valid_tool list Giuseppe Bilotta
2010-12-06 17:49 ` [PATCHv3 3/6] web--browse: support opera, seamonkey and elinks Giuseppe Bilotta
2010-12-06 17:49 ` [PATCHv3 4/6] web--browse: better support for chromium Giuseppe Bilotta
2010-12-07 23:38 ` Junio C Hamano
2010-12-08 7:21 ` Giuseppe Bilotta
2010-12-06 17:49 ` [PATCHv3 5/6] web--browse: use *www-browser if available Giuseppe Bilotta
2010-12-07 23:36 ` Junio C Hamano
2010-12-08 7:38 ` Giuseppe Bilotta
2010-12-06 17:49 ` Giuseppe Bilotta [this message]
2010-12-06 17:59 ` [PATCHv3 6/6] web--browse: look at the BROWSER env var Jonathan Nieder
2010-12-06 18:28 ` Giuseppe Bilotta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1291657790-3719-7-git-send-email-giuseppe.bilotta@gmail.com \
--to=giuseppe.bilotta@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).