From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27921 invoked from network); 26 Jul 2004 15:02:46 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 26 Jul 2004 15:02:46 -0000 Received: (qmail 13260 invoked from network); 26 Jul 2004 15:02:40 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 26 Jul 2004 15:02:40 -0000 Received: (qmail 21854 invoked by alias); 26 Jul 2004 13:50:58 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20199 Received: (qmail 21845 invoked from network); 26 Jul 2004 13:50:58 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by 130.225.247.90 with SMTP; 26 Jul 2004 13:50:58 -0000 Received: (qmail 35811 invoked from network); 26 Jul 2004 13:46:51 -0000 Received: from lhuumrelay3.lnd.ops.eu.uu.net (62.189.58.19) by a.mx.sunsite.dk with SMTP; 26 Jul 2004 13:46:50 -0000 Received: from MAILSWEEPER01.csr.com (mailhost1.csr.com [62.189.183.235]) by lhuumrelay3.lnd.ops.eu.uu.net (8.11.0/8.11.0) with ESMTP id i6QDknv10369 for ; Mon, 26 Jul 2004 13:46:49 GMT Received: from EXCHANGE02.csr.com (unverified [192.168.137.45]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Mon, 26 Jul 2004 14:46:04 +0100 Received: from news01.csr.com ([192.168.143.38]) by EXCHANGE02.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Mon, 26 Jul 2004 14:48:36 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.12.11/8.12.11) with ESMTP id i6QDklDC010978 for ; Mon, 26 Jul 2004 14:46:48 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.12.11/8.12.11/Submit) with ESMTP id i6QDklDr010975 for ; Mon, 26 Jul 2004 14:46:47 +0100 Message-Id: <200407261346.i6QDklDr010975@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: kfmclient and MIME type completion Date: Mon, 26 Jul 2004 14:46:47 +0100 From: Peter Stephenson X-OriginalArrivalTime: 26 Jul 2004 13:48:37.0009 (UTC) FILETIME=[4019C810:01C47317] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=-4.9 required=6.0 tests=BAYES_00 autolearn=no version=2.63 X-Spam-Hits: -4.9 This patch - adds completion for MIME types. The only place I found where this slotted into the current system, after a rather cursory inspection, was _elinks. - adds completion for kfmclient. This is the neat way of passing remote commands to konqueror (KDE's file manager and web browser). This works for most MIME types because it uses the full KDE bindings. Hence pick-web-browser becomes an alternative to the zsh MIME functions, although you have to do the aliasing by hand. - prefers kfmclient to dcop in pick-web-browser - allows mailcap and mime-types styles to include a `+' to get the default path. This works in zsh-mime-setup and _mime_types. Index: Completion/Unix/Command/_elinks =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_elinks,v retrieving revision 1.8 diff -u -r1.8 _elinks --- Completion/Unix/Command/_elinks 16 Apr 2004 15:50:02 -0000 1.8 +++ Completion/Unix/Command/_elinks 26 Jul 2004 13:34:10 -0000 @@ -11,7 +11,7 @@ '*-base-session[clone session with given ID]:ID number:' \ '*-confdir[set config dir to given string]:configuration directory:_files -/' \ '*-conffile[configuration file name]:configuration file:_files' \ - '*-default-mime-type[MIME type to assume for documents]:MIME type:' \ + '*-default-mime-type[MIME type to assume for documents]:MIME type:_mime_types' \ '*-dump[write formatted version of given URL to stdout]::boolean:(0 1)' \ '*-dump-charset[codepage to use with -dump]:codepage:' \ '*-dump-width[width of document formatted with -dump]:width:' \ Index: Completion/Unix/Type/.distfiles =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/.distfiles,v retrieving revision 1.12 diff -u -r1.12 .distfiles --- Completion/Unix/Type/.distfiles 16 Feb 2004 10:50:56 -0000 1.12 +++ Completion/Unix/Type/.distfiles 26 Jul 2004 13:34:10 -0000 @@ -10,4 +10,5 @@ _hosts _tar_archive _time_zone _file_systems _net_interfaces _terminals _locales _java_class _services _email_addresses _global_tags +_mime_types ' Index: Completion/Unix/Type/_mime_types =================================================================== RCS file: Completion/Unix/Type/_mime_types diff -N Completion/Unix/Type/_mime_types --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Completion/Unix/Type/_mime_types 26 Jul 2004 13:34:10 -0000 @@ -0,0 +1,42 @@ +#autoload + +local expl maintype +local -a default_type_files type_files match mbegin mend +integer ind + +default_type_files=(~/.mime.types /etc/mime.types) + +# This is the same style as used by zsh-mime-setup, with a different +# context. +if zstyle -a ":completion:${curcontext}:mime" mime-types type_files; then + while (( (ind = ${type_files[(I)+]}) > 0 )); do + type_files[$ind]=($default_type_files) + done +else + type_files=($default_type_files) +fi + +# +# Handle two different mime type formats; the simple +# format: +# application/x-pws-frobnicate psf pwsf +# and the extended format +# type=application/x-pws-frobnicate \ +# desc="PWS frobnicated widget" \ +# exts="pwsf,psf" +# which Netscape seems to like. +# + +if [[ $PREFIX = (#b)([^/]##)/* ]]; then + # Search for subtype. + maintype=$match[1] + compset -p $(( ${#maintype} + 1 )) + _wanted mimesubtype expl 'MIME subtype' \ + compadd -- $(sed -ne "s%^\(type=\|\)${maintype}/\([^ ]*\).*$%\2%p" \ + $type_files) +else + # Search for main type. + _wanted mimetype expl 'MIME type' \ + compadd -S/ -- $(sed -ne "s/^type=//" \ + -e "s%^\(${PREFIX:-[a-z]}[^=\"]*\)/.*$%\1%p" $type_files) +fi Index: Completion/X/Command/.distfiles =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/X/Command/.distfiles,v retrieving revision 1.9 diff -u -r1.9 .distfiles --- Completion/X/Command/.distfiles 28 May 2003 14:17:13 -0000 1.9 +++ Completion/X/Command/.distfiles 26 Jul 2004 13:34:10 -0000 @@ -3,4 +3,5 @@ _gv _netscape _xauth _xfig _mozilla _xterm _xwit _nedit _vnc _x_utils _xdvi _xmodmap _xset _xv _acroread _dcop _gqview _xloadimage _mplayer +_kfmclient ' Index: Completion/X/Command/_kfmclient =================================================================== RCS file: Completion/X/Command/_kfmclient diff -N Completion/X/Command/_kfmclient --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Completion/X/Command/_kfmclient 26 Jul 2004 13:34:10 -0000 @@ -0,0 +1,93 @@ +#compdef kfmclient + +local expl +local -a context state line +typeset -A opt_args + +_arguments \ + '--help[show help message]' \ + '--help-qt[show Qt specific options]' \ + '--help-kde[show KDE specific options]' \ + '--help-all[show all options]' \ + '--author[show author information]' \ + '-v[show version information]' \ + '--version[show version information]' \ + '--license[show license information]' \ + '--commands[show available commands]' \ + '--display=:X display:_x_display' \ + '--session=:session id for restoring application: ' \ + '--cmap[use private colormap (8-bit display)]' \ + '--ncols=:limit on number of colors (8-bit display): ' \ + '--nograb[never grab mouse or keyboard]' \ + '--dograb[override nograb in debugger]' \ + '--sync[switch to synchronous mode when debugging]' \ + '--fn=:font name:_x_font' \ + '--font=:font name:_x_font' \ + '--bg=:background color:_x_color' \ + '--background=:background color:_x_color' \ + '--fg=:foreground color:_x_color' \ + '--foreround=:foreground color:_x_color' \ + '--btn=:button color:_x_color' \ + '--button=:button color:_x_color' \ + '--name=:application name: ' \ + '--title=:application title (caption): ' \ + '--visual=:specify visual:_x_visual' \ + '--inputstyle:X input method:(onthespot overthespot offthespot root)' \ + '--im:X Input Method server: ' \ + '--noxim[disable X Input Method]' \ + '--reverse[reverse widget layout]' \ + '--caption=:name in titlebar: ' \ + '--icon=:application icon: ' \ + '--miniicon=:icon in titlebar: ' \ + '--config=:configuration file:_files' \ + '--dcopserver=:DCOP server: ' \ + '--nocrashhandler[disable crash handler, allow core dumps]' \ + '--waitforwm[Wait for a WM_NET compatible window manager]' \ + '--style=:GUI style for application: ' \ + '--geometry=:client window geometry:_x_geometry' \ + '1:client command:(openURL openProfile openProperties exec move +download copy sortDesktop configure configureDesktop)' \ + '2::args:->firstarg' \ + '3::args:->secondarg' && return 0 + +[[ $state = *arg ]] || return 1 + +# Argument to previous command. + +print $line >/tmp/tmp.out + +case $line[1] in + (openURL) + if [[ $state = secondarg ]]; then + _mime_types && return 0 + elif [[ $state = firstarg ]]; then + _urls && return 0 + fi + ;; + + (openProfile) + if [[ $state = secondarg ]]; then + _urls && return 0 + elif [[ $state = firstarg ]]; then + _wanted profile expl 'Konqueror profile' \ + compadd -- ~/.kde/share/apps/konqueror/profiles/*(:t) && return 0 + fi + ;; + + (exec) + if [[ $state = secondarg ]]; then + # TODO: could probe inside Desktop files. + _message "KDE binding" && return 0 + elif [[ $state = firstarg ]]; then + _urls && return 0 + fi + ;; + + (move|download|openProperties) + if [[ $state = firstarg ]]; then + _urls && return 0 + fi + ;; +esac + +_message "no more arguments" Index: Doc/Zsh/contrib.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v retrieving revision 1.34 diff -u -r1.34 contrib.yo --- Doc/Zsh/contrib.yo 26 Jul 2004 06:57:46 -0000 1.34 +++ Doc/Zsh/contrib.yo 26 Jul 2004 13:34:12 -0000 @@ -1045,11 +1045,13 @@ A list of files in the format of tt(~/.mime.types) and tt(/etc/mime.types) to be read during setup, replacing the default list which consists of those two files. The context is tt(:mime:). +A tt(PLUS()) in the list will be replaced by the default files. ) item(mailcap)( A list of files in the format of tt(~/.mailcap) and tt(/etc/mailcap) to be read during setup, replacing the default list which consists of those two files. The context is tt(:mime:). +A tt(PLUS()) in the list will be replaced by the default files. ) item(handler)( Specifies a handler for a suffix; the suffix is given by the context as Index: Functions/MIME/pick-web-browser =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/MIME/pick-web-browser,v retrieving revision 1.1 diff -u -r1.1 pick-web-browser --- Functions/MIME/pick-web-browser 14 Sep 2003 19:37:35 -0000 1.1 +++ Functions/MIME/pick-web-browser 26 Jul 2004 13:34:13 -0000 @@ -82,8 +82,13 @@ for browser in $xbrowsers; do if [[ $windows[(I)(#i)$browser] -ne 0 ]]; then if [[ $browser = konqueror ]]; then - # I'm sure there's documentation for this somewhere... - dcop $(dcop|grep konqueror) default openBrowserWindow $url + # 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 else # Mozilla bells and whistles are described at: # http://www.mozilla.org/unix/remote.html Index: Functions/MIME/zsh-mime-setup =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/MIME/zsh-mime-setup,v retrieving revision 1.2 diff -u -r1.2 zsh-mime-setup --- Functions/MIME/zsh-mime-setup 22 Jun 2004 14:35:05 -0000 1.2 +++ Functions/MIME/zsh-mime-setup 26 Jul 2004 13:34:13 -0000 @@ -53,14 +53,30 @@ # to handlers and their flags. typeset -A suffix_type_map type_handler_map type_flags_map +local -a default_type_files default_cap_files local -a type_files cap_files array match mbegin mend local file line type suffix exts elt flags line2 +integer ind + +default_type_files=(~/.mime.types /etc/mime.types) +default_cap_files=(~/.mailcap /etc/mailcap) # Customizable list of files to examine. -zstyle -a :mime: mime-types type_files || - type_files=(~/.mime.types /etc/mime.types) -zstyle -a :mime: mailcap cap_files || - cap_files=(~/.mailcap /etc/mailcap) +if zstyle -a :mime: mime-types type_files; then + while (( (ind = ${type_files[(I)+]}) > 0 )); do + type_files[$ind]=($default_type_files) + done +else + type_files=($default_type_files) +fi + +if zstyle -a :mime: mailcap cap_files; then + while (( (ind = ${cap_files[(I)+]}) > 0 )); do + cap_files[$ind]=($default_cap_files) + done +else + cap_files=($default_cap_files) +fi { mime-setup-add-type() { -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com **********************************************************************