On Sun, Sep 20, 2015 at 07:09:28PM +0200, Per Olofsson wrote:

> Den 2015-09-20 kl. 16:02, skrev Jeff King:
> > The patch for my suggested behavior actually turns out to be quite
> > trivial. Here's what I came up with:
> 
> Thank you for your patch. Unfortunately it is not quite that trivial.
> The problem is that xdg-open sets $BROWSER to a default value if it is
> not set. So users who had not set $BROWSER themselves would get
> xdg-open's default value, instead of xdg-open trying to use the
> mimeapps.list default which the user might have set himself (e.g., using
> the "make default" button in the browser).

Ah, you're right. I tested only for my use case, not the "normal" one.

I guess something like this would work, but it does feel a little hacky.

---
diff --git a/scripts/xdg-open.in b/scripts/xdg-open.in
index 13d352c..fe2eb20 100644
--- a/scripts/xdg-open.in
+++ b/scripts/xdg-open.in
@@ -311,7 +311,7 @@ open_generic()
         fi
     fi
 
-    if [ -n "$DISPLAY" ]; then
+    if [ -n "$DISPLAY" ] && ! $user_defined_browser; then
         open_generic_xdg_x_scheme_handler "$1"
     fi
 
@@ -342,6 +342,10 @@ open_generic()
         fi
     done
 
+    if [ -n "$DISPLAY" ] && $user_defined_browser; then
+        open_generic_xdg_x_scheme_handler "$1"
+    fi
+
     exit_failure_operation_impossible "no method available for opening '$1'"
 }
 
@@ -404,6 +408,12 @@ fi
 
 DEBUG 2 "Selected DE $DE"
 
+if test -z "$BROWSER"; then
+    user_defined_browser=false
+else
+    user_defined_browser=true
+fi
+
 # sanitize BROWSER (avoid caling ourselves in particular)
 case "${BROWSER}" in
     *:"xdg-open"|"xdg-open":*)

Reply via email to