zsh-workers
 help / color / mirror / code / Atom feed
* Re: help with command completion
@ 2000-01-06 10:56 Sven Wischnowsky
  2000-01-06 11:22 ` Oliver Kiddle
  2000-01-06 15:35 ` Tanaka Akira
  0 siblings, 2 replies; 9+ messages in thread
From: Sven Wischnowsky @ 2000-01-06 10:56 UTC (permalink / raw)
  To: zsh-workers


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with command completion
  2000-01-06 10:56 help with command completion Sven Wischnowsky
@ 2000-01-06 11:22 ` Oliver Kiddle
  2000-01-06 15:35 ` Tanaka Akira
  1 sibling, 0 replies; 9+ messages in thread
From: Oliver Kiddle @ 2000-01-06 11:22 UTC (permalink / raw)
  To: Zsh workers

Sven Wischnowsky wrote:

> 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?

It's something else though similar enough that I thought I could adapt
the pattern to work for either. I'll probably now just use separate code
for AIX.

I had a look IRIX (5.3 only) yesterday evening and it seems that the
best way to get a list of printers there is by running lpstat -v. The
same command on AIX (and HP/UX I expect) will also work but gives very
different output so I'll probably have to check $OSTYPE for IRIX
handling.

Oliver Kiddle


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with command completion
  2000-01-06 10:56 help with command completion Sven Wischnowsky
  2000-01-06 11:22 ` Oliver Kiddle
@ 2000-01-06 15:35 ` Tanaka Akira
  1 sibling, 0 replies; 9+ messages in thread
From: Tanaka Akira @ 2000-01-06 15:35 UTC (permalink / raw)
  To: zsh-workers

In article <200001061056.LAA11896@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> +  (( $#_lp_cache )) || _lp_cache( 'lp0:Guessed default printer' )

Typo fix.

Index: Completion/User/_lp
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_lp,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 _lp
--- Completion/User/_lp	2000/01/06 14:10:17	1.1.1.4
+++ Completion/User/_lp	2000/01/06 15:28:22
@@ -31,7 +31,7 @@
       fi
     done < $file[1]
   fi
-  (( $#_lp_cache )) || _lp_cache( 'lp0:Guessed default printer' )
+  (( $#_lp_cache )) || _lp_cache=( 'lp0:Guessed default printer' )
   (( $#_lp_alias_cache )) || unset _lp_alias_cache
 fi
 
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with command completion
       [not found] <200001051342.OAA10929@beta.informatik.hu-berlin.de>
@ 2000-01-05 23:52 ` Tanaka Akira
  0 siblings, 0 replies; 9+ messages in thread
From: Tanaka Akira @ 2000-01-05 23:52 UTC (permalink / raw)
  To: zsh-workers

In article <200001051342.OAA10929@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> +  _wanted printers expl printer && compadd "$expl" - "$_lp_cache[@]"

"$expl" should be "$expl[@]".

Index: Completion/User/_lp
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_lp,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 _lp
--- Completion/User/_lp	2000/01/05 15:00:19	1.1.1.2
+++ Completion/User/_lp	2000/01/05 23:45:16
@@ -15,7 +15,7 @@
 fi
 
 if compset -P -P || [[ "$words[CURRENT-1]" = -P ]]; then
-  _wanted printers expl printer && compadd "$expl" - "$_lp_cache[@]"
+  _wanted printers expl printer && compadd "$expl[@]" - "$_lp_cache[@]"
 else
   if [[ "$words[1]" = (lpq|lprm) ]]; then
     if [[ "$words" = *-P* ]]; then
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with command completion
  2000-01-05 16:42   ` Andrej Borsenkow
@ 2000-01-05 17:07     ` Tanaka Akira
  0 siblings, 0 replies; 9+ messages in thread
From: Tanaka Akira @ 2000-01-05 17:07 UTC (permalink / raw)
  To: Zsh workers

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.
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: help with command completion
  2000-01-05 15:46 ` Oliver Kiddle
@ 2000-01-05 16:42   ` Andrej Borsenkow
  2000-01-05 17:07     ` Tanaka Akira
  0 siblings, 1 reply; 9+ messages in thread
From: Andrej Borsenkow @ 2000-01-05 16:42 UTC (permalink / raw)
  To: Oliver Kiddle, Zsh workers

>
> I am a little unsure what format the /etc/printcap file is supposed to
> be in - printcap(5) suggests that | separates alternate names for the
> queues but the only printcap file I have access to has entries like
> lp|Generic dot-matrix printer entry:\
>
> What are the possible queue names in this case - just lp, lp and Generic
> or lp and Generic\ dot-matrix\ printer\ entry? My tests imply that it is
> just lp.

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.

So, the last entry should probably be ignored. Better yet, it is the one that
should be presented in verbose mode :-)

/andrej


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with command completion
@ 2000-01-05 15:55 Sven Wischnowsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Wischnowsky @ 2000-01-05 15:55 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> Sven Wischnowsky wrote:
> 
> > Then we can just start generating the printer names in this `if'. One
> > possibility is something like:
> > 
> >   compadd - "${(@)${(@s:|:)${(@)${(@f)$(< /etc/printcap)}:#[    \#]*}%%:*}%%[   ]*}"
> 
> I was just looking into trying to adapt this to work on AIX aswell. AIX
> lists the print queues in /etc/qconfig.
> 
> The following works there:
> _lp_cache=( ${${(f)"$(</etc/qconfig)"}%%[:\*[:blank:]]*} )
> 
> I am a little unsure what format the /etc/printcap file is supposed to
> be in - printcap(5) suggests that | separates alternate names for the
> queues but the only printcap file I have access to has entries like
> lp|Generic dot-matrix printer entry:\
> 
> What are the possible queue names in this case - just lp, lp and Generic
> or lp and Generic\ dot-matrix\ printer\ entry? My tests imply that it is
> just lp. Sven's pattern would imply the answer is lp and Generic. I
> can't properly test it because there aren't any real printers attached
> to the one Linux machine I have access to. Does anyone know the answer
> to this? The following pattern will work for AIX and I think it behaves
> the same as Sven's pattern under Linux:
> ${(s:|:)${${(f)"$(<$file[1])"}%%[:\#\*[:blank:]]*}}
> 
> I'll not send a patch to _lp though until I've looked at IRIX at home
> and established what Linux does about those spaces.

Urgh, I almost feared that this would cause trouble. Maybe we should
only use the first name for each entry? (I can't really test it either 
because my printcap lists only one printer with the names lp0, 0, and lp.)

Bye
 Sven


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with command completion
       [not found] <200001051437.PAA10986@beta.informatik.hu-berlin.de>
@ 2000-01-05 15:46 ` Oliver Kiddle
  2000-01-05 16:42   ` Andrej Borsenkow
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Kiddle @ 2000-01-05 15:46 UTC (permalink / raw)
  To: Zsh workers

Sven Wischnowsky wrote:

> Then we can just start generating the printer names in this `if'. One
> possibility is something like:
> 
>   compadd - "${(@)${(@s:|:)${(@)${(@f)$(< /etc/printcap)}:#[    \#]*}%%:*}%%[   ]*}"

I was just looking into trying to adapt this to work on AIX aswell. AIX
lists the print queues in /etc/qconfig.

The following works there:
_lp_cache=( ${${(f)"$(</etc/qconfig)"}%%[:\*[:blank:]]*} )

I am a little unsure what format the /etc/printcap file is supposed to
be in - printcap(5) suggests that | separates alternate names for the
queues but the only printcap file I have access to has entries like
lp|Generic dot-matrix printer entry:\

What are the possible queue names in this case - just lp, lp and Generic
or lp and Generic\ dot-matrix\ printer\ entry? My tests imply that it is
just lp. Sven's pattern would imply the answer is lp and Generic. I
can't properly test it because there aren't any real printers attached
to the one Linux machine I have access to. Does anyone know the answer
to this? The following pattern will work for AIX and I think it behaves
the same as Sven's pattern under Linux:
${(s:|:)${${(f)"$(<$file[1])"}%%[:\#\*[:blank:]]*}}

I'll not send a patch to _lp though until I've looked at IRIX at home
and established what Linux does about those spaces.

Oliver Kiddle


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with command completion
@ 2000-01-05 14:56 Sven Wischnowsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Wischnowsky @ 2000-01-05 14:56 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> [ This one moved to zsh-workers... ]

Ouch. But this time I really did that...

> Here is _lp for lpr, lp, lpq, and lprm. Could definitely be improved,
> but I don't know how (non-)standard the options supported by my lpr
> are.

I'm an idiot.

Bye
 Sven

diff -ru ../z.old/Completion/User/_lp Completion/User/_lp
--- ../z.old/Completion/User/_lp	Wed Jan  5 15:43:57 2000
+++ Completion/User/_lp	Wed Jan  5 15:53:36 2000
@@ -1,6 +1,6 @@
 #compdef lp lpr lpq lprm
 
-local file expl ret=1 list disp strs shown
+local file expl ret=1 printer list disp strs shown
 
 if (( ! $+_lp_cache )); then
    file=( /etc/(printcap|printers.conf)(N) )
@@ -18,7 +18,12 @@
   _wanted printers expl printer && compadd "$expl" - "$_lp_cache[@]"
 else
   if [[ "$words[1]" = (lpq|lprm) ]]; then
-    list=( "${(@M)${(f@)$(lpq)}:#[0-9]*}" )
+    if [[ "$words" = *-P* ]]; then
+      printer=(-P "${${words##*-P( |)}%% *}")
+    else
+      printer=()
+    fi
+    list=( ${(M)"${(f@)$(lpq $printer 2> /dev/null)}":#[0-9]*} )
 
     if (( $#list )); then
       _tags users jobs
diff -ru ../z.old/Doc/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- ../z.old/Doc/Zsh/compsys.yo	Tue Jan  4 14:57:28 2000
+++ Doc/Zsh/compsys.yo	Wed Jan  5 15:45:11 2000
@@ -565,6 +565,9 @@
 item(tt(prefixes))(
 for prefixes (like those of an URL)
 )
+item(tt(printers))(
+for printer names
+)
 item(tt(processes))(
 for process identifiers
 )

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2000-01-06 15:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-06 10:56 help with command completion Sven Wischnowsky
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

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).