From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11244 invoked from network); 6 Jan 2000 10:56:17 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 6 Jan 2000 10:56:17 -0000 Received: (qmail 25558 invoked by alias); 6 Jan 2000 10:56:02 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9242 Received: (qmail 25550 invoked from network); 6 Jan 2000 10:56:02 -0000 Date: Thu, 6 Jan 2000 11:56:00 +0100 (MET) Message-Id: <200001061056.LAA11896@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: Tanaka Akira's message of 06 Jan 2000 02:07:02 +0900 Subject: Re: help with command completion Tanaka Akira wrote: > In article <000001bf579b$e6e4b980$21c9ca95@mow.siemens.ru>, > "Andrej Borsenkow" 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