Check-in [3a7e3e427d]
Not logged in
Overview

SHA1 Hash:3a7e3e427d19e9b1ab1c4d8017d53c5a58122091
Date: 2009-07-29 13:09:22
User: drh
Comment:On unix with the "fossil ui" command, try to open the webbrowser with "xdg-open" and "gnome-open" prior to resorting to "firefox". Ticket 8bc2549cedcd599556bbaf131f03b96588701f20
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/main.c from [828c799fea] to [9b1a2a10f7].

@@ -702,10 +702,34 @@
 void cmd_test_http(void){
   login_set_capabilities("s");
   cmd_http();
 }
 
+
+#if !defined(__DARWIN__) && !defined(__APPLE__)
+/*
+** Search for an executable on the PATH environment variable.
+** Return true (1) if found and false (0) if not found.
+*/
+static int binaryOnPath(const char *zBinary){
+  const char *zPath = getenv("PATH");
+  char *zFull;
+  int i;
+  int bExists;
+  while( zPath && zPath[0] ){
+    while( zPath[0]==':' ) zPath++;
+    for(i=0; zPath[i] && zPath[i]!=':'; i++){}
+    zFull = mprintf("%.*s/%s", i, zPath, zBinary);
+    bExists = access(zFull, X_OK);
+    free(zFull);
+    if( bExists==0 ) return 1;
+    zPath += i;
+  }
+  return 0;
+}
+#endif
+
 /*
 ** COMMAND: server
 ** COMMAND: ui
 **
 ** Usage: %fossil server ?-P|--port TCPPORT? ?REPOSITORY?
@@ -745,11 +769,22 @@
   }
 #ifndef __MINGW32__
   /* Unix implementation */
   if( g.argv[1][0]=='u' ){
 #if !defined(__DARWIN__) && !defined(__APPLE__)
-    zBrowser = db_get("web-browser", "firefox");
+    zBrowser = db_get("web-browser", 0);
+    if( zBrowser==0 ){
+      static char *azBrowserProg[] = { "xdg-open", "gnome-open", "firefox" };
+      int i;
+      zBrowser = "echo";
+      for(i=0; i<sizeof(azBrowserProg)/sizeof(azBrowserProg[0]); i++){
+        if( binaryOnPath(azBrowserProg[i]) ){
+          zBrowser = azBrowserProg[i];
+          break;
+        }
+      }
+    }
 #else
     zBrowser = db_get("web-browser", "open");
 #endif
     zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
   }