zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: Re: help with command completion
Date: Thu, 6 Jan 2000 11:56:00 +0100 (MET)	[thread overview]
Message-ID: <200001061056.LAA11896@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Tanaka Akira's message of 06 Jan 2000 02:07:02 +0900


Tanaka Akira wrote:

> In article <000001bf579b$e6e4b980$21c9ca95@mow.siemens.ru>,
>   "Andrej Borsenkow" <Andrej.Borsenkow@mow.siemens.ru> writes:
> 
> > I do not use systems with printcap myself, but termcap (and terminfo, BTW)
> > description states, that terminal aliases are separated by | with the last one
> > being the "long, user friendly, name". I believe, printcap behaves the same way.
> 
> I tested it on SunOS 4.1.  I wonder that a last entry can be used as
> printer name.  Of course spaces must be quoted in a shell.
> 
> > So, the last entry should probably be ignored. Better yet, it is the one that
> > should be presented in verbose mode :-)
> 
> I think only first entries should be completed at first since latter
> entries are aliases and they are not so important.  But they should be
> completed if first entries are not matched.

I agree with both. So...

I had a closer look at our Solaris 2.6 boxes here. They support a
`description=...' entry which should be prefered if existent, I
think.

It also seems that Solaris 2.6 supports a ~/.printers file which may
contain user-defined aliases. I haven't integrated that yet -- the
fromat is slightly different and we should then use the descriptions
taken from the main file, if possible.

Also, I haven't tried to make this AIX-compatible -- Oliver, did you
mean to say that /etc/qconfig has the printcap-format or something
else?

Bye
 Sven

diff -ru ../z.old/Completion/User/_lp Completion/User/_lp
--- ../z.old/Completion/User/_lp	Thu Jan  6 10:27:50 2000
+++ Completion/User/_lp	Thu Jan  6 11:51:10 2000
@@ -1,21 +1,62 @@
 #compdef lp lpr lpq lprm
 
-local file expl ret=1 printer list disp strs shown
+local expl ret=1 printer list disp strs shown
 
 if (( ! $+_lp_cache )); then
+  local file entry names i
+
    file=( /etc/(printcap|printers.conf)(N) )
 
-  if (( $#file )); then
-    _lp_cache=( "${(@)${(@s:|:)${(@)${(@f)$(< $file[1])}:#[    \#]*}%%:*}%%[ 	]*}" )
-  else
-    # Default value. Could probably be improved
+  _lp_cache=()
+  _lp_alias_cache=()
 
-    _lp_cache=( lp0 )
+  if (( $#file )); then
+    while read entry; do
+      if [[ "$entry" = [^[:blank:]\#\*_]*:* ]]; then
+        names=( "${(s:|:)entry%%:*}" )
+        if [[ "$entry" = *:description=* ]]; then
+          disp="${${entry##*:description=}%%:*}"
+        elif [[ $#names -gt 1 && "$names[-1]" = *\ * ]] ;then
+          disp="$names[-1]"
+        else
+          disp=''
+        fi
+        if [[ -n "$disp" ]]; then
+          _lp_cache=( "$_lp_cache[@]" "${names[1]}:${disp}" )
+  	_lp_alias_cache=( "$_lp_alias_cache[@]" "${(@)^names[2,-1]:#*\ *}:${disp}" )
+        else
+          _lp_cache=( "$_lp_cache[@]" "${names[1]}" )
+  	_lp_alias_cache=( "$_lp_alias_cache[@]" "${(@)names[2,-1]:#*\ *}" )
+        fi
+      fi
+    done < $file[1]
   fi
+  (( $#_lp_cache )) || _lp_cache( 'lp0:Guessed default printer' )
+  (( $#_lp_alias_cache )) || unset _lp_alias_cache
 fi
 
 if compset -P -P || [[ "$words[CURRENT-1]" = -P ]]; then
-  _wanted printers expl printer && compadd "$expl[@]" - "$_lp_cache[@]"
+  if _wanted printers expl printer; then
+    if zstyle -t ":completion:${curcontext}:printers" verbose; then
+      zformat -a list ' -- ' "$_lp_cache[@]"
+      disp=(-ld list)
+    else
+      disp=()
+    fi
+    compadd "$expl[@]" "$disp[@]" - "${(@)_lp_cache%%:*}" && return 0
+
+    (( $+_lp_alias_cache )) || return 1
+
+    if zstyle -t ":completion:${curcontext}:printers" verbose; then
+      zformat -a list ' -- ' "$_lp_alias_cache[@]"
+      disp=(-ld list)
+    else
+      disp=()
+    fi
+    compadd "$expl[@]" "$disp[@]" - "${(@)_lp_alias_cache%%:*}"
+  else
+    return 1
+  fi
 else
   if [[ "$words[1]" = (lpq|lprm) ]]; then
     if [[ "$words" = *-P* ]]; then

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


             reply	other threads:[~2000-01-06 10:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-06 10:56 Sven Wischnowsky [this message]
2000-01-06 11:22 ` Oliver Kiddle
2000-01-06 15:35 ` Tanaka Akira
     [not found] <200001051342.OAA10929@beta.informatik.hu-berlin.de>
2000-01-05 23:52 ` Tanaka Akira
  -- strict thread matches above, loose matches on Subject: below --
2000-01-05 15:55 Sven Wischnowsky
     [not found] <200001051437.PAA10986@beta.informatik.hu-berlin.de>
2000-01-05 15:46 ` Oliver Kiddle
2000-01-05 16:42   ` Andrej Borsenkow
2000-01-05 17:07     ` Tanaka Akira
2000-01-05 14:56 Sven Wischnowsky

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=200001061056.LAA11896@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.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).