From c420bb6453610ae67ac50da31c162edb7d16961e Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 1 Dec 2010 15:12:10 +0100 Subject: [PATCH] web--browse: look at the BROWSER env var The BROWSER environment variables is a widely-accepted standard way 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. --- git-web--browse.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/git-web--browse.sh b/git-web--browse.sh index 1b9c3a5675..ade15ca07c 100755 --- a/git-web--browse.sh +++ b/git-web--browse.sh @@ -166,6 +166,40 @@ then fi fi +# The BROWSER environment variable is a colon-separated list of commands +# to (try and) execute to launch the browser. Each entry can 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. -- 2.32.0.93.g670b81a890