Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: help with command completion



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

Shao Zhang wrote:

> 	lpr -P[TAB] complets to a list a printer name, read from
> 	/etc/printcap.

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.


Bye
 Sven

P.S.: On top of Alexandre's _prcs.

diff -ru ../z.old/Completion/User/.distfiles Completion/User/.distfiles
--- ../z.old/Completion/User/.distfiles	Wed Jan  5 14:38:27 2000
+++ Completion/User/.distfiles	Wed Jan  5 14:38:30 2000
@@ -2,7 +2,7 @@
     .distfiles
     _a2ps _archie _bison _bunzip2 _bzip2 _chown _compress _configure _cvs
     _dd _dir_list _dirs _dvi _find _flex _gcc _gdb _gprof _groups _gs
-    _gunzip _gv _gzip _hosts _ispell _killall _lynx _mailboxes _make _man
+    _gunzip _gv _gzip _hosts _ispell _killall _lp _lynx _mailboxes _make _man
     _mh _mount _mutt _my_accounts _netscape _nslookup _other_accounts
     _pack _patch _pbm _pdf _perl_basepods _perl_builtin_funcs
     _perl_modules _perldoc _ports _prcs _prompt _ps _pspdf _rcs _rlogin _sh
diff -ru ../z.old/Completion/User/_lp Completion/User/_lp
--- ../z.old/Completion/User/_lp	Wed Jan  5 14:38:45 2000
+++ Completion/User/_lp	Wed Jan  5 14:36:18 2000
@@ -0,0 +1,58 @@
+#compdef lp lpr lpq lprm
+
+local file expl ret=1 list disp strs shown
+
+if (( ! $+_lp_cache )); then
+   file=( /etc/(printcap|printers.conf)(N) )
+
+  if (( $#file )); then
+    _lp_cache=( "${(@)${(@s:|:)${(@)${(@f)$(< $file[1])}:#[    \#]*}%%:*}%%[ 	]*}" )
+  else
+    # Default value. Could probably be improved
+
+    _lp_cache=( lp0 )
+  fi
+fi
+
+if compset -P -P || [[ "$words[CURRENT-1]" = -P ]]; then
+  _wanted printers expl printer && compadd "$expl" - "$_lp_cache[@]"
+else
+  if [[ "$words[1]" = (lpq|lprm) ]]; then
+    list=( "${(@M)${(f@)$(lpq)}:#[0-9]*}" )
+
+    if (( $#list )); then
+      _tags users jobs
+
+      while _tags; do
+        if _requested users expl user; then
+          strs=( "${(@)${(@)list##[^ 	]##[ 	]##[^ 	]##[ 	]##}%%[ 	]*}" )
+          if [[ -z "$shown" ]] &&
+             zstyle -t ":completion:${curcontext}:users" verbose; then
+            disp=(-ld list)
+  	  shown=yes
+          else
+  	  disp=()
+          fi
+          compadd "$expl[@]" "$disp[@]" - "$strs[@]" || _users && ret=0
+        fi
+        if _requested jobs expl job; then
+          strs=( "${(@)${(@)list##[^ 	]##[ 	]##[^ 	]##[ 	]##[^ 	]##[ 	]##}%%[ 	]*}" )
+          if [[ -z "$shown" ]] &&
+             zstyle -t ":completion:${curcontext}:jobs" verbose; then
+            disp=(-ld list)
+  	  shown=yes
+          else
+  	  disp=()
+          fi
+          compadd "$expl[@]" "$disp[@]" - "$strs[@]" && ret=0
+        fi
+        (( ret )) || return 0
+      done
+    else
+      _message 'no print jobs'
+    fi
+    return 1
+  else
+    _ps
+  fi
+fi
diff -ru ../z.old/Completion/User/_ps Completion/User/_ps
--- ../z.old/Completion/User/_ps	Tue Jan  4 14:57:55 2000
+++ Completion/User/_ps	Wed Jan  5 13:43:06 2000
@@ -1,4 +1,4 @@
-#compdef ps2epsi ps2pdf epsffit extractres fixdlsrps fixfmps fixmacps fixpsditps fixpspps fixscribeps fixtpps fixwfwps fixwpps fixwwps includeres psbook psmerge psnup psresize psselect pstops psmulti pswrap lpr lp
+#compdef ps2epsi ps2pdf epsffit extractres fixdlsrps fixfmps fixmacps fixpsditps fixpspps fixscribeps fixtpps fixwfwps fixwpps fixwwps includeres psbook psmerge psnup psresize psselect pstops psmulti pswrap
 
 local expl
 

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author