From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17621 invoked from network); 14 May 2007 15:21:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=no version=3.2.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 14 May 2007 15:21:12 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 22279 invoked from network); 14 May 2007 15:21:05 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 14 May 2007 15:21:05 -0000 Received: (qmail 1664 invoked by alias); 14 May 2007 15:21:02 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23438 Received: (qmail 1652 invoked from network); 14 May 2007 15:21:01 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 14 May 2007 15:21:01 -0000 Received: (qmail 21979 invoked from network); 14 May 2007 15:21:01 -0000 Received: from cluster-c.mailcontrol.com (168.143.177.190) by a.mx.sunsite.dk with SMTP; 14 May 2007 15:20:56 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly08c.srv.mailcontrol.com (MailControl) with ESMTP id l4EFKOu6014762 for ; Mon, 14 May 2007 16:20:50 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Mon, 14 May 2007 16:20:27 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.8/8.13.4) with ESMTP id l4EFKRHH026455 for ; Mon, 14 May 2007 16:20:27 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.8/8.13.8/Submit) with ESMTP id l4EFKRXt026452 for ; Mon, 14 May 2007 16:20:27 +0100 Message-Id: <200705141520.l4EFKRXt026452@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: better printer finding Date: Mon, 14 May 2007 16:20:27 +0100 From: Peter Stephenson X-OriginalArrivalTime: 14 May 2007 15:20:27.0795 (UTC) FILETIME=[66F57E30:01C7963B] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-07-07-05 (www.mailcontrol.com) on 10.67.0.118 This improves _printers in two ways: - the cached output is supplemented by the output from lpstat -a, if the command is available. Typically the info is in printers.conf but lpstat -a is more authoritative source. - if there's a -h [:] option, and lpstat is available, use that to find printers on the given server. The result is not cached (this would have to be done per server, but as lpstat is doing the hard work I don't think it's worth it). This is aimed at CUPS, but I think the options are chosen not to conflict with traditional Berkeley and System V printing options. I'm surely you'll let me know otherwise. Index: Completion/Unix/Type/_printers =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_printers,v retrieving revision 1.6 diff -u -r1.6 _printers --- Completion/Unix/Type/_printers 8 Jun 2005 12:45:36 -0000 1.6 +++ Completion/Unix/Type/_printers 14 May 2007 15:15:58 -0000 @@ -1,6 +1,7 @@ #compdef -value-,PRINTER,-default- -value-,LPDEST,-default- -local expl ret=1 list disp sep tmp +local expl ret=1 list disp sep tmp servopt +integer ind if (( $+commands[lsallq] )); then # Use AIX's command to list print queues @@ -10,6 +11,31 @@ zstyle -s ":completion:${curcontext}:printers" list-separator sep || sep=-- +# If we've been given a different print server on the command line, +# list printers on that. This information shouldn't be cached. +# (I) searches backwards---this is good, since some commands, such +# as lpoptions, can take multiple -h arguments and we want the last +# one before the current argument. For lpr, -h might mean something +# else and the option is -H. +if [[ $service = lpr ]]; then + servopt=-H +else + servopt=-h +fi +if (( $+commands[lpstat] )); then + ind=${words[1,CURRENT][(I)${servopt}*]} + if (( ind > 0 )); then + if [[ $words[ind] = $servopt ]]; then + tmp=-h$words[ind+1] + else + tmp=-h${words[ind][3,-1]} + fi + _wanted printers expl printer compadd "$@" - \ + ${${(f)"$(lpstat $tmp -a)"}%% *} && return + fi +fi + + if (( ! $+_lp_cache )); then local file entry names i @@ -40,6 +66,17 @@ done < $file[1] fi + if (( $+commands[lpstat] )); then + # If lpstat it exists, it's possible there are some other + # printers there, so add them. + lpstat -a | while read entry; do + entry=${entry%%[[:blank:]]*} + if (( ${_lp_cache[(I)$entry:*]} == 0 )); then + _lp_cache+=( $entry ) + fi + done + fi + if [[ $OSTYPE = solaris* ]] && (( ${+commands[ypcat]} )) && tmp=$(_call_program printers ypcat printers.conf.byname 2>/dev/null); then _lp_cache+=( ${${${(S)${(f)tmp}/(#b):*((#e)|description=([^:]#):)*/:${match[2]}|}%%|*}:#_default*} ) # If you use YP -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview