Fossil SCM

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]

drh 2009-07-29 13:09 trunk
Commit 3a7e3e427d19e9b1ab1c4d8017d53c5a58122091
1 file changed +36 -1
+36 -1
--- src/main.c
+++ src/main.c
@@ -702,10 +702,34 @@
702702
void cmd_test_http(void){
703703
login_set_capabilities("s");
704704
cmd_http();
705705
}
706706
707
+
708
+#if !defined(__DARWIN__) && !defined(__APPLE__)
709
+/*
710
+** Search for an executable on the PATH environment variable.
711
+** Return true (1) if found and false (0) if not found.
712
+*/
713
+static int binaryOnPath(const char *zBinary){
714
+ const char *zPath = getenv("PATH");
715
+ char *zFull;
716
+ int i;
717
+ int bExists;
718
+ while( zPath && zPath[0] ){
719
+ while( zPath[0]==':' ) zPath++;
720
+ for(i=0; zPath[i] && zPath[i]!=':'; i++){}
721
+ zFull = mprintf("%.*s/%s", i, zPath, zBinary);
722
+ bExists = access(zFull, X_OK);
723
+ free(zFull);
724
+ if( bExists==0 ) return 1;
725
+ zPath += i;
726
+ }
727
+ return 0;
728
+}
729
+#endif
730
+
707731
/*
708732
** COMMAND: server
709733
** COMMAND: ui
710734
**
711735
** Usage: %fossil server ?-P|--port TCPPORT? ?REPOSITORY?
@@ -745,11 +769,22 @@
745769
}
746770
#ifndef __MINGW32__
747771
/* Unix implementation */
748772
if( g.argv[1][0]=='u' ){
749773
#if !defined(__DARWIN__) && !defined(__APPLE__)
750
- zBrowser = db_get("web-browser", "firefox");
774
+ zBrowser = db_get("web-browser", 0);
775
+ if( zBrowser==0 ){
776
+ static char *azBrowserProg[] = { "xdg-open", "gnome-open", "firefox" };
777
+ int i;
778
+ zBrowser = "echo";
779
+ for(i=0; i<sizeof(azBrowserProg)/sizeof(azBrowserProg[0]); i++){
780
+ if( binaryOnPath(azBrowserProg[i]) ){
781
+ zBrowser = azBrowserProg[i];
782
+ break;
783
+ }
784
+ }
785
+ }
751786
#else
752787
zBrowser = db_get("web-browser", "open");
753788
#endif
754789
zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
755790
}
756791
--- src/main.c
+++ src/main.c
@@ -702,10 +702,34 @@
702 void cmd_test_http(void){
703 login_set_capabilities("s");
704 cmd_http();
705 }
706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
707 /*
708 ** COMMAND: server
709 ** COMMAND: ui
710 **
711 ** Usage: %fossil server ?-P|--port TCPPORT? ?REPOSITORY?
@@ -745,11 +769,22 @@
745 }
746 #ifndef __MINGW32__
747 /* Unix implementation */
748 if( g.argv[1][0]=='u' ){
749 #if !defined(__DARWIN__) && !defined(__APPLE__)
750 zBrowser = db_get("web-browser", "firefox");
 
 
 
 
 
 
 
 
 
 
 
751 #else
752 zBrowser = db_get("web-browser", "open");
753 #endif
754 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
755 }
756
--- src/main.c
+++ src/main.c
@@ -702,10 +702,34 @@
702 void cmd_test_http(void){
703 login_set_capabilities("s");
704 cmd_http();
705 }
706
707
708 #if !defined(__DARWIN__) && !defined(__APPLE__)
709 /*
710 ** Search for an executable on the PATH environment variable.
711 ** Return true (1) if found and false (0) if not found.
712 */
713 static int binaryOnPath(const char *zBinary){
714 const char *zPath = getenv("PATH");
715 char *zFull;
716 int i;
717 int bExists;
718 while( zPath && zPath[0] ){
719 while( zPath[0]==':' ) zPath++;
720 for(i=0; zPath[i] && zPath[i]!=':'; i++){}
721 zFull = mprintf("%.*s/%s", i, zPath, zBinary);
722 bExists = access(zFull, X_OK);
723 free(zFull);
724 if( bExists==0 ) return 1;
725 zPath += i;
726 }
727 return 0;
728 }
729 #endif
730
731 /*
732 ** COMMAND: server
733 ** COMMAND: ui
734 **
735 ** Usage: %fossil server ?-P|--port TCPPORT? ?REPOSITORY?
@@ -745,11 +769,22 @@
769 }
770 #ifndef __MINGW32__
771 /* Unix implementation */
772 if( g.argv[1][0]=='u' ){
773 #if !defined(__DARWIN__) && !defined(__APPLE__)
774 zBrowser = db_get("web-browser", 0);
775 if( zBrowser==0 ){
776 static char *azBrowserProg[] = { "xdg-open", "gnome-open", "firefox" };
777 int i;
778 zBrowser = "echo";
779 for(i=0; i<sizeof(azBrowserProg)/sizeof(azBrowserProg[0]); i++){
780 if( binaryOnPath(azBrowserProg[i]) ){
781 zBrowser = azBrowserProg[i];
782 break;
783 }
784 }
785 }
786 #else
787 zBrowser = db_get("web-browser", "open");
788 #endif
789 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
790 }
791

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button