Skip to contentSkip to conversation

web--browse cleanups and extensions

PATCH Superseded Giuseppe Bilotta 4 participants 22 messages Jun 15, 2016 Documentation

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover web--browse cleanups and extensions

This patches introduces support for Opera, Seamonkey/Iceape and elinks to git web-browse, after a little reformatting to adhere to the shell script coding guidelines (guidelines which were not explicit in the documentation, and which are made so).

The last two patches are somewhat more system-specific (AFAIK, only Debain & friends have /usr/bin/{x-,}www-browser, and not many other distributions have chromium under the chromium-browser executable name), but I believe it still makes sense to include them in the mainstream version of git.

Giuseppe Bilotta (6):
CodingGuidelines: mention whitespace preferences for shell scripts
web--browse: coding style
web--browse: split valid_tool list
web--browse: support opera, seamonkey and elinks
web--browse: use (x-)www-browser if available
web--browse: special-case chromium path

 Documentation/CodingGuidelines    |    6 +
 Documentation/git-web--browse.txt |   10 ++
 git-web--browse.sh                |  202 +++++++++++++++++++++----------------
 3 files changed, 133 insertions(+), 85 deletions(-)
Signature · 1 line
1.7.3.2.624.gec6c7.dirty
#1 lore raw

PATCH 1/6 CodingGuidelines: mention whitespace preferences for shell scripts

---
 Documentation/CodingGuidelines |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
Documentation/CodingGuidelines +6 -0
index 5aa2d34..7ecce51 100644
@@ -31,6 +31,12 @@ But if you must have a list of rules, here they are.
 
 For shell scripts specifically (not exhaustive):
 
+ - We use tabs for indentation.
+
+ - The choices in case ... esac statement are not indented with respect
+   to the the case and esac lines. The body of the choices however _is_
+   indented (by one tab).
+
  - We prefer $( ... ) for command substitution; unlike ``, it
    properly nests.  It should have been the way Bourne spelled
    it from day one, but unfortunately isn't.
Signature · 1 line
1.7.3.2.624.gec6c7.dirty
#4 lore raw

PATCH 2/6 web--browse: coding style

In reply to Giuseppe Bilotta

Retab and deindent choices in case statements.

---
 git-web--browse.sh |  166 ++++++++++++++++++++++++++--------------------------
 1 files changed, 83 insertions(+), 83 deletions(-)
git-web--browse.sh +83 -83
index 3fc4166..7c4568f 100755
@@ -31,11 +31,11 @@ valid_custom_tool()
 
 valid_tool() {
 	case "$1" in
-		firefox | iceweasel | chrome | google-chrome | chromium | konqueror | w3m | links | lynx | dillo | open | start)
-			;; # happy
-		*)
-			valid_custom_tool "$1" || return 1
-			;;
+	firefox | iceweasel | chrome | google-chrome | chromium | konqueror | w3m | links | lynx | dillo | open | start)
+		;; # happy
+	*)
+		valid_custom_tool "$1" || return 1
+		;;
 	esac
 }
 
@@ -46,139 +46,139 @@ init_browser_path() {
 
 while test $# != 0
 do
-    case "$1" in
+	case "$1" in
 	-b|--browser*|-t|--tool*)
-	    case "$#,$1" in
+		case "$#,$1" in
 		*,*=*)
-		    browser=`expr "z$1" : 'z-[^=]*=\(.*\)'`
-		    ;;
+			browser=`expr "z$1" : 'z-[^=]*=\(.*\)'`
+			;;
 		1,*)
-		    usage ;;
+			usage ;;
 		*)
-		    browser="$2"
-		    shift ;;
-	    esac
-	    ;;
+			browser="$2"
+			shift ;;
+		esac
+		;;
 	-c|--config*)
-	    case "$#,$1" in
+		case "$#,$1" in
 		*,*=*)
-		    conf=`expr "z$1" : 'z-[^=]*=\(.*\)'`
-		    ;;
+			conf=`expr "z$1" : 'z-[^=]*=\(.*\)'`
+			;;
 		1,*)
-		    usage ;;
+			usage ;;
 		*)
-		    conf="$2"
-		    shift ;;
-	    esac
-	    ;;
+			conf="$2"
+			shift ;;
+		esac
+		;;
 	--)
-	    break
-	    ;;
+		break
+		;;
 	-*)
-	    usage
-	    ;;
+		usage
+		;;
 	*)
-	    break
-	    ;;
-    esac
-    shift
+		break
+		;;
+	esac
+	shift
 done
 
 test $# = 0 && usage
 
 if test -z "$browser"
 then
-    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
+	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
 fi
 
 if test -z "$browser" ; then
-    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"
+	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"
 	fi
-    else
-	browser_candidates="w3m links lynx"
-    fi
-    # SECURITYSESSIONID indicates an OS X GUI login session
-    if test -n "$SECURITYSESSIONID" \
-	    -o "$TERM_PROGRAM" = "Apple_Terminal" ; then
-	browser_candidates="open $browser_candidates"
-    fi
-    # /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
+	# SECURITYSESSIONID indicates an OS X GUI login session
+	if test -n "$SECURITYSESSIONID" \
+		-o "$TERM_PROGRAM" = "Apple_Terminal" ; then
+		browser_candidates="open $browser_candidates"
 	fi
-    done
-    test -z "$browser" && die "No known browser available."
+	# /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."
 else
-    valid_tool "$browser" || die "Unknown browser '$browser'."
+	valid_tool "$browser" || die "Unknown browser '$browser'."
 
-    init_browser_path "$browser"
+	init_browser_path "$browser"
 
-    if test -z "$browser_cmd" && ! type "$browser_path" > /dev/null 2>&1; then
-	die "The browser $browser is not available as '$browser_path'."
-    fi
+	if test -z "$browser_cmd" && ! type "$browser_path" > /dev/null 2>&1; then
+		die "The browser $browser is not available as '$browser_path'."
+	fi
 fi
 
 case "$browser" in
-    firefox|iceweasel)
+firefox|iceweasel)
 	# 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=''
 	"$browser_path" $NEWTAB "$@" &
 	;;
-    google-chrome|chrome|chromium)
+google-chrome|chrome|chromium)
 	# Actual command for chromium is chromium-browser.
 	# No need to specify newTab. It's default in chromium
 	eval "$browser_path" "$@" &
 	;;
-    konqueror)
+konqueror)
 	case "$(basename "$browser_path")" in
-	    konqueror)
+	konqueror)
 		# 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."
 		eval "$browser_path" newTab "$@"
 		;;
-	    kfmclient)
+	kfmclient)
 		eval "$browser_path" newTab "$@"
 		;;
-	    *)
+	*)
 		"$browser_path" "$@" &
 		;;
 	esac
 	;;
-    w3m|links|lynx|open)
+w3m|links|lynx|open)
 	eval "$browser_path" "$@"
 	;;
-    start)
-        exec "$browser_path" '"web-browse"' "$@"
-        ;;
-    dillo)
+start)
+	exec "$browser_path" '"web-browse"' "$@"
+	;;
+dillo)
 	"$browser_path" "$@" &
 	;;
-    *)
+*)
 	if test -n "$browser_cmd"; then
-	    ( eval $browser_cmd "$@" )
+		( eval $browser_cmd "$@" )
 	fi
 	;;
 esac
Signature · 1 line
1.7.3.2.624.gec6c7.dirty
#5 lore raw

PATCH 3/6 web--browse: split valid_tool list

In reply to Giuseppe Bilotta

It was getting too long, and we want to add some more.

---
 git-web--browse.sh |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
git-web--browse.sh +2 -1
index 7c4568f..b20b0e0 100755
@@ -31,7 +31,8 @@ valid_custom_tool()
 
 valid_tool() {
 	case "$1" in
-	firefox | iceweasel | chrome | google-chrome | chromium | konqueror | w3m | links | lynx | dillo | open | start)
+	firefox|iceweasel|chrome|google-chrome|chromium\
+	|konqueror|w3m|links|lynx|dillo|open|start)
 		;; # happy
 	*)
 		valid_custom_tool "$1" || return 1
Signature · 1 line
1.7.3.2.624.gec6c7.dirty
#6 lore raw

Re: [PATCH 3/6] web--browse: split valid_tool list

git-web--browse.sh valid_custom_tool() · line 35

Quoted 9 lines · Giuseppe Bilotta
git-web--browse.sh +2 -1
@@ -31,7 +31,8 @@ valid_custom_tool()
 
 valid_tool() {
 	case "$1" in
-	firefox | iceweasel | chrome | google-chrome | chromium | konqueror | w3m | links | lynx | dillo | open | start)
+	firefox|iceweasel|chrome|google-chrome|chromium\
+	|konqueror|w3m|links|lynx|dillo|open|start)

micronit: I think this looks better as

	firefox|iceweasel|chrome|google-chrome|chromium| \
	konqueror|w3m|links|lynx|dillo|open|start)

, with the | on the end of the first line.

#9 lore raw

PATCH 4/6 web--browse: support opera, seamonkey and elinks

In reply to Giuseppe Bilotta

The list of supported browsers is also updated in the documentation.

---
 Documentation/git-web--browse.txt |    6 ++++++
 git-web--browse.sh                |   14 +++++++-------
 2 files changed, 13 insertions(+), 7 deletions(-)
Documentation/git-web--browse.txt +6 -0
index 51e8e0a..5d3ae07 100644
@@ -20,8 +20,14 @@ The following browsers (or commands) are currently supported:
 
 * firefox (this is the default under X Window when not using KDE)
 * iceweasel
+* seamonkey
+* iceape
+* chromium
+* google-chrome
 * konqueror (this is the default under KDE, see 'Note about konqueror' below)
+* opera
 * w3m (this is the default outside graphical environments)
+* elinks
 * links
 * lynx
 * dillo
git-web--browse.sh +7 -7
index b20b0e0..7b7f45f 100755
@@ -31,8 +31,8 @@ valid_custom_tool()
 
 valid_tool() {
 	case "$1" in
-	firefox|iceweasel|chrome|google-chrome|chromium\
-	|konqueror|w3m|links|lynx|dillo|open|start)
+	firefox|iceweasel|seamonkey|iceape|chrome|google-chrome|chromium\
+	|konqueror|opera|w3m|elinks|links|lynx|dillo|open|start)
 		;; # happy
 	*)
 		valid_custom_tool "$1" || return 1
@@ -104,12 +104,12 @@ fi
 
 if test -z "$browser" ; then
 	if test -n "$DISPLAY"; then
-		browser_candidates="firefox iceweasel google-chrome chrome chromium konqueror w3m links lynx dillo"
+		browser_candidates="firefox iceweasel google-chrome chrome chromium konqueror opera seamonkey iceape w3m elinks links lynx dillo"
 		if test "$KDE_FULL_SESSION" = "true"; then
 			browser_candidates="konqueror $browser_candidates"
 		fi
 	else
-		browser_candidates="w3m links lynx"
+		browser_candidates="w3m elinks links lynx"
 	fi
 	# SECURITYSESSIONID indicates an OS X GUI login session
 	if test -n "$SECURITYSESSIONID" \
@@ -140,7 +140,7 @@ else
 fi
 
 case "$browser" in
-firefox|iceweasel)
+firefox|iceweasel|seamonkey|iceape)
 	# Check version because firefox < 2.0 does not support "-new-tab".
 	vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
 	NEWTAB='-new-tab'
@@ -168,13 +168,13 @@ konqueror)
 		;;
 	esac
 	;;
-w3m|links|lynx|open)
+w3m|elinks|links|lynx|open)
 	eval "$browser_path" "$@"
 	;;
 start)
 	exec "$browser_path" '"web-browse"' "$@"
 	;;
-dillo)
+opera|dillo)
 	"$browser_path" "$@" &
 	;;
 *)
Signature · 1 line
1.7.3.2.624.gec6c7.dirty
#10 lore raw

PATCH 5/6 web--browse: use (x-)www-browser if available

In reply to Giuseppe Bilotta

Debian and derivatives have an alternatives-based default browser configuration that uses the /usr/bin/x-www-browser and /usr/bin/www-browser symlinks.

When no browser is selected by the user and the Debian alternatives are available, try to see if they are one of our recognized selection and in the affermative case use it.

---
 Documentation/git-web--browse.txt |    4 ++++
 git-web--browse.sh                |   34 +++++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 3 deletions(-)
Documentation/git-web--browse.txt +4 -0
index 5d3ae07..76b5cdc 100644
@@ -36,6 +36,10 @@ The following browsers (or commands) are currently supported:
 
 Custom commands may also be specified.
 
+If no default browser is specified, and /usr/bin/x-www-browser
+(under X) or /usr/bin/www-browser is present, they are used to determine
+the browser to use.
+
 OPTIONS
 -------
 -b <browser>::
git-web--browse.sh +31 -3
index 7b7f45f..f991dd0 100755
@@ -102,6 +102,33 @@ then
 	fi
 fi
 
+# Debian and derivatives use x-www-browser or www-browser to set
+# the default browser for the system
+if test -z "$browser" ; then
+	wwwbrowser="/usr/bin/www-browser"
+	if test -n "$DISPLAY"; then
+		wwwbrowser="/usr/bin/x-www-browser $wwwbrowser"
+	fi
+	for i in $wwwbrowser; do
+		if test -x $i ; then
+			verstring="$($i --version 2> /dev/null | head -n 1)"
+			browser="$(echo "$verstring" | cut -f1 -d' ' | tr A-Z a-z)"
+			case "$browser" in
+			mozilla)
+				browser="$(echo "$verstring" | cut -f2 -d' ' | tr A-Z a-z)"
+				;;
+			google)
+				browser="google-chrome"
+				;;
+			esac
+			if valid_tool "$browser" ; then
+				browser_path="$i"
+				break
+			fi
+		fi
+	done
+fi
+
 if test -z "$browser" ; then
 	if test -n "$DISPLAY"; then
 		browser_candidates="firefox iceweasel google-chrome chrome chromium konqueror opera seamonkey iceape w3m elinks links lynx dillo"
@@ -129,7 +156,7 @@ if test -z "$browser" ; then
 		fi
 	done
 	test -z "$browser" && die "No known browser available."
-else
+else if test -z "$browser_path"; then
 	valid_tool "$browser" || die "Unknown browser '$browser'."
 
 	init_browser_path "$browser"
@@ -137,12 +164,13 @@ else
 	if test -z "$browser_cmd" && ! type "$browser_path" > /dev/null 2>&1; then
 		die "The browser $browser is not available as '$browser_path'."
 	fi
-fi
+fi fi
 
 case "$browser" in
 firefox|iceweasel|seamonkey|iceape)
 	# Check version because firefox < 2.0 does not support "-new-tab".
-	vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
+	test -z "$verstring" && verstring="$($browser_path -version)"
+	vers=$(expr "$verstring" : '.* \([0-9][0-9]*\)\..*')
 	NEWTAB='-new-tab'
 	test "$vers" -lt 2 && NEWTAB=''
 	"$browser_path" $NEWTAB "$@" &
Signature · 1 line
1.7.3.2.624.gec6c7.dirty
#11 lore raw

Re: [PATCH 5/6] web--browse: use (x-)www-browser if available

Quoted 3 lines · Giuseppe Bilotta

Debian and derivatives have an alternatives-based default browser configuration that uses the /usr/bin/x-www-browser and /usr/bin/www-browser symlinks.

Mm, maybe it will be time to look into adding xdg-open support soon, too.

#13 lore raw

Re: [PATCH 5/6] web--browse: use (x-)www-browser if available

In reply to Giuseppe Bilotta

Hi,

git-web--browse.sh then · line 115

Quoted 12 lines · Giuseppe Bilotta
git-web--browse.sh +11 -0
+# Debian and derivatives use x-www-browser or www-browser to set
+# the default browser for the system
+if test -z "$browser" ; then
+       wwwbrowser="/usr/bin/www-browser"
+       if test -n "$DISPLAY"; then
+               wwwbrowser="/usr/bin/x-www-browser $wwwbrowser"
+       fi
+       for i in $wwwbrowser; do
+               if test -x $i ; then
+                       verstring="$($i --version 2> /dev/null | head -n 1)"
+                       browser="$(echo "$verstring" | cut -f1 -d' ' | tr A-Z a-z)"

Stupid questions:

Did you check that all the browser we support accept the --version option? What if we add support for a new one that doesn't ?
Shouldn't we add something like :

test -z "$browser" && browser="$(echo $i | cut -f1 -d' ' | tr A-Z a-z)"

And are you sure that when they support --version, the first word of the output is
better than "$(echo $i | cut -f1 -d' ' | tr A-Z a-z)"? What if we add support for a new one?

Quoted 9 lines

+                       case "$browser" in
+                       mozilla)
+                               browser="$(echo "$verstring" | cut -f2 -d' ' | tr A-Z a-z)"
+                               ;;
+                       google)
+                               browser="google-chrome"
+                               ;;
+                       esac
+                       if valid_tool "$browser" ; then

valid_tool "$browser" is called once here...

Quoted 16 lines

+                               browser_path="$i"
+                               break
+                       fi
+               fi
+       done

(quoted diff) +2 -0
+fi
+

 if test -z "$browser" ; then
       if test -n "$DISPLAY"; then
               browser_candidates="firefox iceweasel google-chrome chrome chromium konqueror opera seamonkey iceape w3m elinks links lynx dillo"

(quoted diff) +0 -0
@@ -129,7 +156,7 @@ if test -z "$browser" ; then

               fi
       done
       test -z "$browser" && die "No known browser available."

git-web--browse.sh +1 -1
-else
+else if test -z "$browser_path"; then
Quoted 1 line

       valid_tool "$browser" || die "Unknown browser '$browser'."

...valid_tool "$browser" is called again here if it failed above, and here we die,
so isn't it clearer to die as soon as we call it and it fails?

Thanks,
Christian.

#14 lore raw

Re: [PATCH 5/6] web--browse: use (x-)www-browser if available

Quoted 19 lines · Christian Couder

Hi,

git-web--browse.sh then · line 115

Quoted 12 lines · Giuseppe Bilotta
git-web--browse.sh +11 -0
+# Debian and derivatives use x-www-browser or www-browser to set
+# the default browser for the system
+if test -z "$browser" ; then
+       wwwbrowser="/usr/bin/www-browser"
+       if test -n "$DISPLAY"; then
+               wwwbrowser="/usr/bin/x-www-browser $wwwbrowser"
+       fi
+       for i in $wwwbrowser; do
+               if test -x $i ; then
+                       verstring="$($i --version 2> /dev/null | head -n 1)"
+                       browser="$(echo "$verstring" | cut -f1 -d' ' | tr A-Z a-z)"

Stupid questions:

Quoted 5 lines

Did you check that all the browser we support accept the --version option? What if we add support for a new one that doesn't ?
Shouldn't we add something like :

test -z "$browser" && browser="$(echo $i | cut -f1 -d' ' | tr A-Z a-z)"

Sorry I mean:

test -z "$browser" && browser="$(readlink $i)"

Quoted 3 lines

And are you sure that when they support --version, the first word of the output is
better than "$(echo $i | cut -f1 -d' ' | tr A-Z a-z)"?

and: "$(readlink $i)"

Thanks,
Christian.

#15 lore raw

Re: [PATCH 5/6] web--browse: use (x-)www-browser if available

In reply to Christian Couder
Quoted 19 lines · Christian Couder

Hi,

git-web--browse.sh then · line 115

Quoted 12 lines · Giuseppe Bilotta
git-web--browse.sh +11 -0
+# Debian and derivatives use x-www-browser or www-browser to set
+# the default browser for the system
+if test -z "$browser" ; then
+       wwwbrowser="/usr/bin/www-browser"
+       if test -n "$DISPLAY"; then
+               wwwbrowser="/usr/bin/x-www-browser $wwwbrowser"
+       fi
+       for i in $wwwbrowser; do
+               if test -x $i ; then
+                       verstring="$($i --version 2> /dev/null | head -n 1)"
+                       browser="$(echo "$verstring" | cut -f1 -d' ' | tr A-Z a-z)"

Stupid questions:

Quoted 1 line

Did you check that all the browser we support accept the --version option?

I don't have all of them readily available, so I checked with Mozilla-based browsers, Opera, Chromium, elinks, lynx, w3m. I'm missing konqueror and dillo.

Quoted 1 line

What if we add support for a new one that doesn't ?

I think that the worse issue would be (x-)www-browser linking to something that doesn't support --version regardless of wether we support it or not.

Quoted 3 lines

Shouldn't we add something like :

test -z "$browser" && browser="$(readlink $i)"

My first idea was to go for something like browser="$(basename $(readlink $i))" (not sure why you would need test -z before). Since it would need special-casing anyway (e.g. chromium-browser -> chromium), I opted out for the --version way so that (1) we could catch one of our friendly cases even if the binary was called something else and (2) some invocation paths try to get the version anyway, so we could do it once and for all.

Quoted 3 lines

And are you sure that when they support --version, the first word of the output is
better than "$(readlink $i)"?

Probably depends on the metric used for 'better' ;-)

Quoted 1 line

What if we add support for a new one?

Then when adding it we should also look at its --version output and see if it needs special treatment.

Quoted 12 lines
Quoted 9 lines

+                       case "$browser" in
+                       mozilla)
+                               browser="$(echo "$verstring" | cut -f2 -d' ' | tr A-Z a-z)"
+                               ;;
+                       google)
+                               browser="google-chrome"
+                               ;;
+                       esac
+                       if valid_tool "$browser" ; then

valid_tool "$browser" is called once here...

Quoted 7 lines
Quoted 3 lines
git-web--browse.sh +1 -1
-else
+else if test -z "$browser_path"; then

       valid_tool "$browser" || die "Unknown browser '$browser'."

...valid_tool "$browser" is called again here if it failed above, and here we die,
so isn't it clearer to die as soon as we call it and it fails?

We allow valid_tool to be false in the x-www-browser case, in which case we test www-browser, and if it's still not valid we go on and use the previous paths. So we cannot die in case of an invalid (x-)www-browser. But there's a bug in the www-brower testing, it needs an else that resets browser to the empty string.

Signature · 1 line
Giuseppe "Oblomov" Bilotta
#21 lore raw

PATCH 6/6 web--browse: special-case chromium path

In reply to Giuseppe Bilotta

On Debian-based distributions, Chromium the browser is available under the name chromium-browser rather than chromium, to prevent conflicts with the Chromium B.S.U. game.

---
 git-web--browse.sh |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
git-web--browse.sh +3 -0
index f991dd0..9cd66e4 100755
@@ -42,6 +42,9 @@ valid_tool() {
 
 init_browser_path() {
 	browser_path=$(git config "browser.$1.path")
+	if test "$1" = chromium ; then
+		type chromium-browser > /dev/null 2>&1 && browser_path=chromium-browser
+	fi
 	test -z "$browser_path" && browser_path="$1"
 }
 
Signature · 1 line
1.7.3.2.624.gec6c7.dirty
#2 lore raw

Re: [PATCH 1/6] CodingGuidelines: mention whitespace preferences for shell scripts

In reply to Giuseppe Bilotta
Quoted 10 lines · Giuseppe Bilotta
---
 Documentation/CodingGuidelines |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
Documentation/CodingGuidelines +0 -0
index 5aa2d34..7ecce51 100644

Documentation/CodingGuidelines But if you must have a list of rules, here they are. · line 34

Quoted 4 lines
Documentation/CodingGuidelines +1 -0
@@ -31,6 +31,12 @@ But if you must have a list of rules, here they are.
 
 For shell scripts specifically (not exhaustive):
 
+ - We use tabs for indentation.

Ok.

Documentation/CodingGuidelines But if you must have a list of rules, here they are. · line 39

Quoted 4 lines
Documentation/CodingGuidelines +4 -0
+ - The choices in case ... esac statement are not indented with respect
+   to the the case and esac lines. The body of the choices however _is_
+   indented (by one tab).
+

Nit; "choices" are called "case arms".

I don't think there is any need to emphasize your surprise that case body is indented with "however _is_", which implies "against common sense or normal convention" or somesuch. The thing is, there is no single _right_ convention, and we want people to folow the one just picked---we should just describe what it is without being emotional nor emphatic.

Thanks.

#3 lore raw

Re: [PATCH 1/6] CodingGuidelines: mention whitespace preferences for shell scripts

Quoted 19 lines · Junio C Hamano
Quoted 13 lines · Giuseppe Bilotta

---
 Documentation/CodingGuidelines |    6 ++++++

 1 files changed, 6 insertions(+), 0 deletions(-)
Documentation/CodingGuidelines +0 -0
index 5aa2d34..7ecce51 100644
@@ -31,6 +31,12 @@ But if you must have a list of rules, here they are.
 

 For shell scripts specifically (not exhaustive):

Quoted 1 line

+ - We use tabs for indentation.

Ok.

Quoted 6 lines
Quoted 4 lines

+ - The choices in case ... esac statement are not indented with respect
+   to the the case and esac lines. The body of the choices however _is_
+   indented (by one tab).
+

Nit; "choices" are called "case arms".

I'll rephrase.

Quoted 5 lines

I don't think there is any need to emphasize your surprise that case body is indented with "however _is_", which implies "against common sense or normal convention" or somesuch.  The thing is, there is no single _right_ convention, and we want people to folow the one just picked---we should just describe what it is without being emotional nor emphatic.

Good point, I'll resend with a shorter commit message. Would you be ok with me adding an example, or do you think it's unnecessary?

Signature · 1 line
Giuseppe "Oblomov" Bilotta
#7 lore raw

Re: [PATCH 3/6] web--browse: split valid_tool list

In reply to Jonathan Nieder
Quoted 14 lines · Jonathan Nieder

git-web--browse.sh valid_custom_tool() · line 35

Quoted 9 lines · Giuseppe Bilotta
git-web--browse.sh +2 -1
@@ -31,7 +31,8 @@ valid_custom_tool()
 
 valid_tool() {
 	case "$1" in
-	firefox | iceweasel | chrome | google-chrome | chromium | konqueror | w3m | links | lynx | dillo | open | start)
+	firefox|iceweasel|chrome|google-chrome|chromium\
+	|konqueror|w3m|links|lynx|dillo|open|start)

micronit: I think this looks better as

Quoted 4 lines
	firefox|iceweasel|chrome|google-chrome|chromium| \
	konqueror|w3m|links|lynx|dillo|open|start)

, with the | on the end of the first line.

Yes, and with one SP around all "|".

Thanks.

#8 lore raw

Re: [PATCH 3/6] web--browse: split valid_tool list

In reply to Jonathan Nieder
Quoted 14 lines · Jonathan Nieder
Quoted 9 lines · Giuseppe Bilotta
git-web--browse.sh +0 -0
@@ -31,7 +31,8 @@ valid_custom_tool()
 
  valid_tool() {

      case "$1" in
-     firefox | iceweasel | chrome | google-chrome | chromium | konqueror | w3m | links | lynx | dillo | open | start)
+     firefox|iceweasel|chrome|google-chrome|chromium\
+     |konqueror|w3m|links|lynx|dillo|open|start)

micronit: I think this looks better as

Quoted 4 lines

       firefox|iceweasel|chrome|google-chrome|chromium| \
       konqueror|w3m|links|lynx|dillo|open|start)

, with the | on the end of the first line.

I opted for the | at the beginning of the line to give a better idea of the continuation, but I don't have a strong preference in that direction, so I can fix it up as you suggested, unless there are specific indications from the 'higher ups' ;-)

Signature · 1 line
Giuseppe "Oblomov" Bilotta
#12 lore raw

Re: [PATCH 5/6] web--browse: use (x-)www-browser if available

In reply to Jonathan Nieder
Quoted 8 lines · Jonathan Nieder
Quoted 3 lines · Giuseppe Bilotta

Debian and derivatives have an alternatives-based default browser configuration that uses the /usr/bin/x-www-browser and /usr/bin/www-browser symlinks.

Mm, maybe it will be time to look into adding xdg-open support soon, too.

That's probably a good idea, although I think there is no way with xdg-open to say "open in a new tab".

Signature · 1 line
Giuseppe "Oblomov" Bilotta
#16 lore raw

Re: [PATCH 5/6] web--browse: use (x-)www-browser if available

In reply to Giuseppe Bilotta
Quoted 33 lines · Giuseppe Bilotta
Quoted 19 lines · Christian Couder

Hi,

git-web--browse.sh then · line 115

Quoted 12 lines · Giuseppe Bilotta
git-web--browse.sh +11 -0
+# Debian and derivatives use x-www-browser or www-browser to set
+# the default browser for the system
+if test -z "$browser" ; then
+       wwwbrowser="/usr/bin/www-browser"
+       if test -n "$DISPLAY"; then
+               wwwbrowser="/usr/bin/x-www-browser $wwwbrowser"
+       fi
+       for i in $wwwbrowser; do
+               if test -x $i ; then
+                       verstring="$($i --version 2> /dev/null | head -n 1)"
+                       browser="$(echo "$verstring" | cut -f1 -d' ' | tr A-Z a-z)"

Stupid questions:

Quoted 1 line

Did you check that all the browser we support accept the --version option?

I don't have all of them readily available, so I checked with Mozilla-based browsers, Opera, Chromium, elinks, lynx, w3m. I'm missing konqueror and dillo.

Quoted 1 line

What if we add support for a new one that doesn't ?

I think that the worse issue would be (x-)www-browser linking to something that doesn't support --version regardless of wether we support it or not.

Quoted 6 lines
Quoted 3 lines

Shouldn't we add something like :

test -z "$browser" && browser="$(readlink $i)"

My first idea was to go for something like browser="$(basename $(readlink $i))" (not sure why you would need test -z before).

We would need "test -z" before if we add it after:

browser="$(echo "$verstring" | cut -f1 -d' ' | tr A-Z a-z)"

so that we have a fallback if it doesn't support "--version".

Quoted 38 lines

Since
it would need special-casing anyway (e.g. chromium-browser -> chromium), I opted out for the --version way so that (1) we could catch one of our friendly cases even if the binary was called something else and (2) some invocation paths try to get the version anyway, so we could do it once and for all.

Quoted 3 lines

And are you sure that when they support --version, the first word of the output is
better than "$(readlink $i)"?

Probably depends on the metric used for 'better' ;-)

Quoted 1 line

What if we add support for a new one?

Then when adding it we should also look at its --version output and see if it needs special treatment.

Quoted 12 lines
Quoted 9 lines

+                       case "$browser" in
+                       mozilla)
+                               browser="$(echo "$verstring" | cut -f2 -d' ' | tr A-Z a-z)"
+                               ;;
+                       google)
+                               browser="google-chrome"
+                               ;;
+                       esac
+                       if valid_tool "$browser" ; then

valid_tool "$browser" is called once here...

Quoted 7 lines
Quoted 3 lines
git-web--browse.sh +1 -1
-else
+else if test -z "$browser_path"; then

       valid_tool "$browser" || die "Unknown browser '$browser'."

...valid_tool "$browser" is called again here if it failed above, and here we die,
so isn't it clearer to die as soon as we call it and it fails?

Quoted 4 lines

We allow valid_tool to be false in the x-www-browser case, in which case we test www-browser, and if it's still not valid we go on and use the previous paths. So we cannot die in case of an invalid (x-)www-browser.

Yeah, you are right, but we could die after the "for i in $wwwbrowser" loop if both are invalid.

Quoted 2 lines

But there's a bug in the www-brower testing, it needs an else that resets browser to the empty string.

I thought it was by design that you did not reset it...
So yeah it is clearer and nicer for the user if you either reset browser or just die if both (x-)www-browser are invalid. If you decide to reset browser, perhaps a warning or an information message telling that both are unknown would be nice.

Thanks,
Christian.

#17 lore raw

Re: [PATCH 5/6] web--browse: use (x-)www-browser if available

Quoted 39 lines · Christian Couder
Quoted 37 lines · Giuseppe Bilotta
Quoted 19 lines · Christian Couder

Hi,

git-web--browse.sh then · line 115

Quoted 12 lines · Giuseppe Bilotta
git-web--browse.sh +11 -0
+# Debian and derivatives use x-www-browser or www-browser to set
+# the default browser for the system
+if test -z "$browser" ; then
+       wwwbrowser="/usr/bin/www-browser"
+       if test -n "$DISPLAY"; then
+               wwwbrowser="/usr/bin/x-www-browser $wwwbrowser"
+       fi
+       for i in $wwwbrowser; do
+               if test -x $i ; then
+                       verstring="$($i --version 2> /dev/null | head -n 1)"
+                       browser="$(echo "$verstring" | cut -f1 -d' ' | tr A-Z a-z)"

Stupid questions:

Quoted 1 line

Did you check that all the browser we support accept the --version option?

I don't have all of them readily available, so I checked with Mozilla-based browsers, Opera, Chromium, elinks, lynx, w3m. I'm missing konqueror and dillo.

Quoted 1 line

What if we add support for a new one that doesn't ?

I think that the worse issue would be (x-)www-browser linking to something that doesn't support --version regardless of wether we support it or not.

Quoted 3 lines

Shouldn't we add something like :

test -z "$browser" && browser="$(readlink $i)"

Quoted 8 lines
Quoted 2 lines

My first idea was to go for something like browser="$(basename $(readlink $i))" (not sure why you would need test -z before).

We would need "test -z" before if we add it after:

browser="$(echo "$verstring" | cut -f1 -d' ' | tr A-Z a-z)"

so that we have a fallback if it doesn't support "--version".

Oh, I see what you mean here. I thought you wanted to use it as an alternative to the --version.

Quoted 7 lines
Quoted 4 lines

We allow valid_tool to be false in the x-www-browser case, in which case we test www-browser, and if it's still not valid we go on and use the previous paths. So we cannot die in case of an invalid (x-)www-browser.

Yeah, you are right, but we could die after the "for i in $wwwbrowser" loop if both are invalid.

Why? If both are invalid, proceeding with the previous strategy of looking for a browser we _should_ be looking for any browser we know about, even if it's not set as the default system browser.

Quoted 8 lines
Quoted 2 lines

But there's a bug in the www-brower testing, it needs an else that resets browser to the empty string.

I thought it was by design that you did not reset it...
So yeah it is clearer and nicer for the user if you either reset browser or just die if both (x-)www-browser are invalid. If you decide to reset browser, perhaps a warning or an information message telling that both are unknown would be nice.

I can do that. Should it be a warning about reporting the lack of support to us, or just a warning that we are not going to use it even if it's defined?

While we're at it: I was considering adding support for the BROWSER env var (a colon-separated list of browsers executables or "browser %s" strings).

All of this is going to make the web--browse script very similar to the sensible-browser script in Debian, with the difference that we go at length to ensure that stuff is opened in a new tab, whereas Debian's sensible-browser doesn't. Should we just support sensible-browser instead of (x-)www-browser/BROWSER, and let it open anything?

Signature · 1 line
Giuseppe "Oblomov" Bilotta
#18 lore raw

Re: [PATCH 5/6] web--browse: use (x-)www-browser if available

Quoted 9 lines · Giuseppe Bilotta
Quoted 7 lines · Christian Couder
Quoted 4 lines · Giuseppe Bilotta

We allow valid_tool to be false in the x-www-browser case, in which case we test www-browser, and if it's still not valid we go on and use the previous paths. So we cannot die in case of an invalid (x-)www-browser.

Quoted 6 lines
Quoted 2 lines

Yeah, you are right, but we could die after the "for i in $wwwbrowser" loop if both are invalid.

Why? If both are invalid, proceeding with the previous strategy of looking for a browser we _should_ be looking for any browser we know about, even if it's not set as the default system browser.

Currently we have:

97 if test -n "$browser" && ! valid_tool "$browser"; then
98 echo >&2 "git config option $opt set to unknown browser: $browser"
99 echo >&2 "Resetting to default..."
100 unset browser
101 fi

So if we want to be consistent with that behavior, we should probably do the same thing if (x-)www-browser is set but we don't support it.

Quoted 9 lines
Quoted 8 lines
Quoted 2 lines

But there's a bug in the www-brower testing, it needs an else that resets browser to the empty string.

I thought it was by design that you did not reset it...
So yeah it is clearer and nicer for the user if you either reset browser or just die if both (x-)www-browser are invalid. If you decide to reset browser, perhaps a warning or an information message telling that both are unknown would be nice.

Quoted 3 lines

I can do that. Should it be a warning about reporting the lack of support to us, or just a warning that we are not going to use it even if it's defined?

I think it should be a warning that we are not going to use it even if it's defined, to be consistent with the code pasted above.

If you think of something better or want to remove the warnings, please do it in another patch.

Quoted 10 lines

While we're at it: I was considering adding support for the BROWSER env var (a colon-separated list of browsers executables or "browser %s" strings).

All of this is going to make the web--browse script very similar to the sensible-browser script in Debian, with the difference that we go at length to ensure that stuff is opened in a new tab, whereas Debian's sensible-browser doesn't. Should we just support sensible-browser instead of (x-)www-browser/BROWSER, and let it open anything?

I think most users prefer to open stuff in a new tab if possible.

Thanks,
Christian.

#19 lore raw

Re: [PATCH 5/6] web--browse: use (x-)www-browser if available

Quoted 20 lines · Christian Couder
Quoted 9 lines · Giuseppe Bilotta
Quoted 7 lines · Christian Couder
Quoted 4 lines · Giuseppe Bilotta

We allow valid_tool to be false in the x-www-browser case, in which case we test www-browser, and if it's still not valid we go on and use the previous paths. So we cannot die in case of an invalid (x-)www-browser.

Quoted 6 lines
Quoted 2 lines

Yeah, you are right, but we could die after the "for i in $wwwbrowser" loop if both are invalid.

Why? If both are invalid, proceeding with the previous strategy of looking for a browser we _should_ be looking for any browser we know about, even if it's not set as the default system browser.

Currently we have:

Quoted 8 lines

97     if test -n "$browser" && ! valid_tool "$browser"; then
98         echo >&2 "git config option $opt set to unknown browser: $browser" 99         echo >&2 "Resetting to default..."
100         unset browser
101     fi

So if we want to be consistent with that behavior, we should probably do the same thing if (x-)www-browser is set but we don't support it.

The (x-)www-browser code is used when the user did _not_ define a browser. It is not a browser option (git web--browse --tool=www-browser).
IOW, this is not about the user selecting an unsupported browser, but about the system default browser not being a supported one. I don't think it should be treated the same way.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines

But there's a bug in the www-brower testing, it needs an else that resets browser to the empty string.

I thought it was by design that you did not reset it...
So yeah it is clearer and nicer for the user if you either reset browser or just die if both (x-)www-browser are invalid. If you decide to reset browser, perhaps a warning or an information message telling that both are unknown would be nice.

Quoted 6 lines
Quoted 3 lines

I can do that. Should it be a warning about reporting the lack of support to us, or just a warning that we are not going to use it even if it's defined?

I think it should be a warning that we are not going to use it even if it's defined, to be consistent with the code pasted above.

Ok.

Quoted 2 lines

If you think of something better or want to remove the warnings, please do it in another patch.

I think the warning is fine.

Quoted 4 lines
Quoted 4 lines

While we're at it: I was considering adding support for the BROWSER env var (a colon-separated list of browsers executables or "browser %s" strings).

Quoted 8 lines
Quoted 6 lines

All of this is going to make the web--browse script very similar to the sensible-browser script in Debian, with the difference that we go at length to ensure that stuff is opened in a new tab, whereas Debian's sensible-browser doesn't. Should we just support sensible-browser instead of (x-)www-browser/BROWSER, and let it open anything?

I think most users prefer to open stuff in a new tab if possible.

I will look into adding support for the BROWSER environment variable to select the browser if no browser is defined, then, but not consider sensible-browser.

Signature · 1 line
Giuseppe "Oblomov" Bilotta
#20 lore raw

Re: [PATCH 5/6] web--browse: use (x-)www-browser if available

Quoted 2 lines · Giuseppe Bilotta

I will look into adding support for the BROWSER environment variable to select the browser if no browser is defined

Thanks, that sounds excellent.

BTW, the semantics of quoting characters/shell metacharacters in $BROWSER are not well defined (well, they're well defined in one way by the original spec, which is ignored by xdg-open and some other tools). xdg-open's semantics are probably the most reliable standard here but thought I should give a heads up.

Thinking out loud: longer term, it would be nice to just use xdg-utils and drop most of this logic from git. Presumably the ideal behavior for most apps opening web pages is already "new tab", so the cases of "new window" not explicitly configured that way by the user are bugs. Otherwise a request to [email protected] (subscription required) for xdg-open --new-tab/--new-window might be useful.

Regards,
Jonathan