From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1267 invoked from network); 7 Mar 2006 21:20:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 7 Mar 2006 21:20:23 -0000 Received: (qmail 24162 invoked from network); 7 Mar 2006 21:20:14 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 7 Mar 2006 21:20:14 -0000 Received: (qmail 15753 invoked by alias); 7 Mar 2006 21:20:06 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22333 Received: (qmail 15718 invoked from network); 7 Mar 2006 21:20:05 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 7 Mar 2006 21:20:05 -0000 Received: (qmail 22336 invoked from network); 7 Mar 2006 21:20:04 -0000 Received: from mta09-winn.ispmail.ntl.com (81.103.221.49) by a.mx.sunsite.dk with SMTP; 7 Mar 2006 21:20:00 -0000 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mta09-winn.ispmail.ntl.com with ESMTP id <20060307211959.DBBC23947.mta09-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com> for ; Tue, 7 Mar 2006 21:19:59 +0000 Received: from pwslaptop.csr.com ([81.105.236.124]) by aamtaout01-winn.ispmail.ntl.com with ESMTP id <20060307211958.KRXO11653.aamtaout01-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Tue, 7 Mar 2006 21:19:58 +0000 Received: from pwslaptop.csr.com (pwslaptop.csr.com [127.0.0.1]) by pwslaptop.csr.com (8.13.4/8.13.4) with ESMTP id k27LJKQn008445 for ; Tue, 7 Mar 2006 21:19:35 GMT Received: from pwslaptop.csr.com (pws@localhost) by pwslaptop.csr.com (8.13.4/8.13.4/Submit) with ESMTP id k27LJFfT008441 for ; Tue, 7 Mar 2006 21:19:20 GMT Message-Id: <200603072119.k27LJFfT008441@pwslaptop.csr.com> X-Authentication-Warning: pwslaptop.csr.com: pws owned process doing -bs From: Peter Stephenson To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: choice of commands in pick-web-browser Date: Tue, 07 Mar 2006 21:19:14 +0000 Minor addition to pick-web-browser to allow you to configure the command used to start each given browser. You might think at this point it would be simpler to invoke the browser directly, but the point of this is to be part of a MIME system that can be configured entirely with styles. I also noted it didn't detect running variants of Mozilla because the executable is has a -bin tacked on the end. Index: Doc/Zsh/contrib.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v retrieving revision 1.54 diff -u -r1.54 contrib.yo --- Doc/Zsh/contrib.yo 18 Dec 2005 20:12:29 -0000 1.54 +++ Doc/Zsh/contrib.yo 7 Mar 2006 21:14:58 -0000 @@ -1346,6 +1346,8 @@ command to an appropriate viewer. startitem() +findex(zsh-mime-setup) +findex(zsh-mime-handler) xitem(tt(zsh-mime-setup [-flv])) item(tt(zsh-mime-handler))( These two functions use the files tt(~/.mime.types) and tt(/etc/mime.types), @@ -1510,6 +1512,7 @@ ) enditem() ) +findex(pick-web-browser) item(tt(pick-web-browser))( This function is separate from the two MIME functions described above and can be assigned directly to a suffix: @@ -1518,19 +1521,19 @@ alias -s html=pick-web-browser) It is provided as an intelligent front end to dispatch a web browser. -It will check if an X Windows display is available, and if so -if there is already a browser running which can accept a remote +It will check if an X Windows display is available, and if so if there +is already a browser running on the display which can accept a remote connection. In that case, the file will be displayed in that browser; you should check explicitly if it has appeared in the running browser's -window. Otherwise, it will start a new browser according to a builtin +window. Otherwise, it will start a new browser according to a built-in set of preferences. Alternatively, tt(pick-web-browser) can be run as a zsh script. Two styles are available to customize the choice of browsers: -tt(x-browsers) when running under the X Windows System, and +tt(x-browsers) when running under the X Window System, and tt(tty-browsers) otherwise. These are arrays in decreasing order -of preference consiting of the command name under which to start the +of preference consisting of the command name under which to start the browser. They are looked up in the context tt(:mime:) (which may be extended in future, so appending `tt(*)' is recommended). For example, @@ -1540,6 +1543,18 @@ specifies that tt(pick-web-browser) should first look for a runing instance of Opera, Konqueror or Netscape, in that order, and if it fails to find any should attempt to start Opera. + +In addition, the style tt(command), if set, is used to pick the command +used to open a page for a browser. The context is +tt(:mime:browser:new:$browser:) to start a new browser or +tt(:mime:browser:running:$browser:) to open a URL in a browser already +runing on the current X display. The escape sequence tt(%b) in the +style's value will be replaced by the browser, while tt(%u) will be +replaced by the URL. If the style is not set, the default for all new +instances is equivalent to tt(%b %u) and the defaults for using running +browsers are equivalent to the values tt(kfmclient openURL %u) for +Konqueror, tt(firefox -new-tab %u) for Firefox and tt(%b -remote +"openUrl(%u)") for all others. ) enditem() Index: Functions/MIME/pick-web-browser =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/MIME/pick-web-browser,v retrieving revision 1.3 diff -u -r1.3 pick-web-browser --- Functions/MIME/pick-web-browser 19 Feb 2006 21:20:43 -0000 1.3 +++ Functions/MIME/pick-web-browser 7 Mar 2006 21:14:58 -0000 @@ -22,6 +22,8 @@ emulate -L zsh setopt extendedglob cbases nonomatch +zmodload -i zsh/zutil + local -a xbrowsers ttybrowsers # X Windows browsers which might be running and can accept @@ -38,7 +40,7 @@ litc="-_./" local -a windows remoteargs match mbegin mend -local url browser +local url browser command url=$1 if [[ -f $url ]]; then @@ -80,22 +82,31 @@ # Is any browser we've heard of running? for browser in $xbrowsers; do - if [[ $windows[(I)(#i)$browser] -ne 0 ]]; then - if [[ $browser = konqueror ]]; then - # kfmclient is less hairy and better supported than direct - # use of dcop. Run kfmclient --commands - # for more information. Note that as konqueror is a fully - # featured file manager, this will actually do complete - # MIME handling, not just web pages. - kfmclient openURL $url || - dcop $(dcop|grep konqueror) default openBrowserWindow $url - elif [[ $browser = firefox ]]; then - # open in new tab: should make this customizable - $browser -new-tab $url + # Some browser executables call themselves -bin + if [[ $windows[(I)(#i)$browser(|[.-]bin)] -ne 0 ]]; then + if zstyle -s ":mime:browser:running:${browser}:" command command; then + # The (q)'s here and below are pure paranoia: no browser + # name is going to include metacharacters, and we already + # converted difficult characters in the URL to hex. + zformat -f command $command b:${(q)browser} u:${(q)url} + eval $command else - # Mozilla bells and whistles are described at: - # http://www.mozilla.org/unix/remote.html - $browser -remote "openURL($url)" + if [[ $browser = konqueror ]]; then + # kfmclient is less hairy and better supported than direct + # use of dcop. Run kfmclient --commands + # for more information. Note that as konqueror is a fully + # featured file manager, this will actually do complete + # MIME handling, not just web pages. + kfmclient openURL $url || + dcop $(dcop|grep konqueror) default openBrowserWindow $url + elif [[ $browser = firefox ]]; then + # open in new tab + $browser -new-tab $url + else + # Mozilla bells and whistles are described at: + # http://www.mozilla.org/unix/remote.html + $browser -remote "openURL($url)" + fi fi return fi @@ -104,8 +115,13 @@ # Start our preferred X Windows browser in the background. for browser in $xbrowsers; do if eval "[[ =$browser != \\=$browser ]]"; then - # The following is to make the job text more readable. - eval ${(q)browser} ${(q)url} "&" + if zstyle -s ":mime:browser:new:${browser}:" command command; then + zformat -f command $command b:${(q)browser} u:${(q)url} + eval $command "&" + else + # The following is to make the job text more readable. + eval ${(q)browser} ${(q)url} "&" + fi break fi done @@ -113,7 +129,12 @@ # Start up dumb terminal browser. for browser in $ttybrowsers; do if eval "[[ =$browser != \\=$browser ]]"; then - $browser $url + if zstyle -s ":mime:browser:new:${browser}" command command; then + zformat -f command $command b:${(q)browser} u:${(q)url} + eval $command + else + $browser $url + fi break fi done -- Peter Stephenson Web page still at http://www.pwstephenson.fsnet.co.uk/