From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: better printer finding
Date: Mon, 14 May 2007 16:20:27 +0100 [thread overview]
Message-ID: <200705141520.l4EFKRXt026452@news01.csr.com> (raw)
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 <server>[:<port>] 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 <pws@csr.com> 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
reply other threads:[~2007-05-14 15:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200705141520.l4EFKRXt026452@news01.csr.com \
--to=pws@csr.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).