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

PATCH: _compress, _pack and _lzop



This patch combines completion for uncompress, unpack, pcat etc into the
single functions (_compress and _pack) which is more consistent with
they way we're handling gzip, bzip2 etc. _arguments is also now used in
both. Arguments to compress seem to vary slightly so it may complete
flags which your compress doesn't have (or not some that it does have).

I've also added completion for lzop which, for the benefit of anyone who
hasn't heard of it is a file compressor which favours speed over
compression ratio. See http://wildsau.idv.uni-linz.ac.at/mfx/lzop.html
for more about it. Also here is a small correction for _bzip2.

Oliver

Index: Completion/User/.distfiles
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/.distfiles,v
retrieving revision 1.7
diff -u -r1.7 .distfiles
--- Completion/User/.distfiles	2000/05/01 15:26:01	1.7
+++ Completion/User/.distfiles	2000/05/05 09:56:14
@@ -4,13 +4,13 @@
     _configure _cvs _dd _diff _diff_options _dir_list _dirs
     _domains _dvi _enscript
     _find _finger _fakeroot _flex _gcc _gdb  _getconf _gprof _groups
-    _gs _gv _gzip _hosts _imagemagick _ispell _joe _killall _lp _lynx
+    _gs _gv _gzip _hosts _imagemagick _ispell _joe _killall _lp _lynx _lzop
     _mailboxes _make _man _mh _mount _mutt _my_accounts _mysql_utils _nedit
     _netscape _nslookup _other_accounts _pack _patch _pbm _pdf _perl
     _perl_basepods _perl_builtin_funcs _perl_modules _perldoc
     _ports _prcs _printers _prompt _ps _pspdf _psutils _rcs _rlogin _sh _socket
     _ssh _strip _stty _su _sudo _tar _tar_archive _telnet _tex _texi
-    _tiff _tilde_files _uncompress _unpack _urls _use_lo _user_at_host
+    _tiff _tilde_files _urls _use_lo _user_at_host
     _users _users_on _webbrowser _wget _whereis _whois _xargs _yodl _yp
     _zcat _zdump
 '
Index: Completion/User/_bzip2
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_bzip2,v
retrieving revision 1.2
diff -u -r1.2 _bzip2
--- Completion/User/_bzip2	2000/05/01 15:26:01	1.2
+++ Completion/User/_bzip2	2000/05/05 09:56:14
@@ -23,8 +23,8 @@
     '(-c)--stdout[write on standard output]' \
     '(--quiet)-q[suppress all warnings]' \
     '(-q)--quiet[suppress all warnings]' \
-    '(--verbose)*-v[verbose mode]' \
-    '(-v)*--verbose[verbose mode]' \
+    '*-v[verbose mode]' \
+    '*--verbose[verbose mode]' \
     '(--license)-L[display software license]' \
     '(-L)--license[display software license]' \
     '(--version)-V[display version number]' \
@@ -45,7 +45,7 @@
 
 if [[ "$state" = files ]]; then
   (( $+opt_args[-z] || $+opt_args[--compress] )) && decompress=no
-  (( $+opt_args[-d] || $+opt_args[--decompress] || $+opt_args[-t] || \
+  (( $+opt_args[-d] || $+opt_args[--decompress] || $+opt_args[-t] ||
       $+opt_args[--test] )) && unset decompress
   if [[ -z "$decompress" ]] ; then
     _description files expl 'compressed file'
Index: Completion/User/_compress
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_compress,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 _compress
--- Completion/User/_compress	1999/12/01 15:29:43	1.1.1.4
+++ Completion/User/_compress	2000/05/05 09:56:14
@@ -1,6 +1,45 @@
-#compdef compress
+#compdef compress uncompress
 
-local expl
+local expl state line bits common_args1 common_args2 decompress
+typeset -A opt_args
+bits=( {9..16} )
 
-_description files expl 'file to compress'
-_files "$expl[@]" -g '*~*.Z'
+common_args1=( \
+  '-n[omit compressed file header from compressed file]' \
+  '-V[display current version and compile options]' \
+  '*:files:->files')
+common_args2=( \
+  '-c[write on standard output]' \
+  '(-F)-f[force overwrite]' \
+  '(-f)-F[force overwrite]' \
+  '(-v)-q[suppress display of compression statistics]' \
+  '(-q)-v[display compression statistics]' \
+  "${common_args1[@]}" )
+
+case "${words[1]:t}" in
+  compress)
+    _arguments -s \
+      "-b[specify maximum number of bits used to replace common substring]:bits:(${bits[*]})" \
+      '-C[produce output compatible with BSD 2.0]' \
+      '(-b -C)-d[decompress]' \
+      "${common_args2[@]}"
+  ;;
+  uncompress)
+    _arguments -s "${common_args2[@]}"
+    decompress=yes
+  ;;
+  zcat)
+    _arguments -s "${common_args1[@]}"
+    decompress=yes
+  ;;
+esac
+
+if [[ "$state" = files ]]; then
+  if [[ -z "$decompress" ]] || (( $+opt_args[-d] )); then
+    _description files expl 'file to compress'
+    _files "$expl[@]" -g '*~*.Z'
+  else
+    _description files expl 'compressed file'
+    _files "$expl[@]" -g '*.Z'
+  fi
+fi
Index: Completion/User/_lzop
===================================================================
RCS file: _lzop
diff -N _lzop
--- /dev/null	Tue May  5 13:32:27 1998
+++ _lzop	Fri May  5 02:56:14 2000
@@ -0,0 +1,102 @@
+#compdef lzop
+
+local expl state line decompress disp
+typeset -A opt_args
+
+_arguments -C -s \
+  '(--to-stdout --stdout)-c[write on standard output]' \
+  '(-c --stdout)--to-stdout[write on standard output]' \
+  '(-c --to-stdout)--stdout[write on standard output]' \
+  '(--decompress --uncompress -x -extract)-d[decompress]' \
+  '(-d --uncompress -x -extract)--decompress[decompress]' \
+  '(-d --decompress -x -extract)--uncompress[decompress]' \
+  '(--extract -d --decompress --uncompress -n --name -p --path)-x[extract]' \
+  '(-x -d --decompress --uncompress -n --name -p --path)-x[extract]' \
+  '(--force)-f[force overwrite]' \
+  '(-f)--force[force overwrite]' \
+  '(--help -H)-h[display help message]' \
+  '(-h -H)--help[display help message]' \
+  '(-h --help)-H[display help message]' \
+  '(--list)-l[list compressed file contents]' \
+  '(-l)--list[list compressed file contents]' \
+  '(--license)-L[display software license]' \
+  '(-L)--license[display software license]' \
+  '(--no-name -N --name)-n[do not save or restore the original name and time stamp]' \
+  '(-n -N --name)--no-name[do not save or restore the original name and time stamp]' \
+  '(--name -n --no-name)-N[save or restore the original name and time stamp]' \
+  '(-N -n --no-name)--name[save or restore the original name and time stamp]' \
+  '--no-mode[do not restore original mode]' \
+  '--no-time[do not restore original time stamp]' \
+  '(--quiet --silent)-q[suppress all warnings]' \
+  '(-q --silent)--quiet[suppress all warnings]' \
+  '(-q --quiet)--silent[suppress all warnings]' \
+  '(--recursive)-r[operate recursively on directories]' \
+  '(-r)--recursive[operate recursively on directories]' \
+  '(--suffix)-S+[specify suffix for compressed files]:suffix:' \
+  '(-S)--suffix=[specify suffix for compressed files]:suffix:' \
+  '(--test)-t[test compressed file integrity]' \
+  '(-t)--test[test compressed file integrity]' \
+  '*-v[verbose mode]' \
+  '*--verbose[verbose mode]' \
+  '(--version)-V[display version number]' \
+  '(-V)--version[display version number]' \
+  '(       -1 -2 -3 -4 -5 -6 -7 -8 -9 --best)--fast' \
+  '(--fast    -2 -3 -4 -5 -6 -7 -8 -9 --best)-1' \
+  '(--fast -1    -3 -4 -5 -6 -7 -8 -9 --best)-2' \
+  '(--fast -1 -2    -4 -5 -6 -7 -8 -9 --best)-3' \
+  '(--fast -1 -2 -3    -5 -6 -7 -8 -9 --best)-4' \
+  '(--fast -1 -2 -3 -4    -6 -7 -8 -9 --best)-5' \
+  '(--fast -1 -2 -3 -4 -5    -7 -8 -9 --best)-6' \
+  '(--fast -1 -2 -3 -4 -5 -6    -8 -9 --best)-7' \
+  '(--fast -1 -2 -3 -4 -5 -6 -7    -9 --best)-8' \
+  '(--fast -1 -2 -3 -4 -5 -6 -7 -8    --best)-9' \
+  '(--fast -1 -2 -3 -4 -5 -6 -7 -8 -9       )--best' \
+  '--ls=[list each compressed file in a format similar to ls -ln]:ls flag:->flags' \
+  '--info[list internal header fields for each compressed file]' \
+  '(--sysinfo)-I[display information about the system]' \
+  '(-I)--sysinfo[display information about the system]' \
+  '(--outfile)-o[specify output file]:output file:_files' \
+  '(-o)--outfile=[specify output file]:output file:_files' \
+  '(--path)-p[write output files to specified directory]:directory:_files -/' \
+  '(-p)--path=[[write output files to specified directory]:directory:_files -/' \
+  '(--no-checksum)-F[do not store or verify a checksum]' \
+  '(-F)--no-checksum[do not store or verify a checksum]' \
+  "(--keep -U --unlink --delete)-k[keep (don't delete) input files]" \
+  "(-k -U --unlink --delete)--keep[keep (don't delete) input files]" \
+  '(--unlink --delete)-U[delete input files]' \
+  '(-U --delete)--unlink[delete input files]' \
+  '(-U --unlink)--delete[delete input files]' \
+  '--no-stdin[do not try to read stdin]' \
+  '--no-warn[suppress all warnings]' \
+  '--ignore-warn[suppress all warnings and never exit with status 2]' \
+  '--no-color[do not use an color escape sequences]' \
+  '--mono[assume a mono ANSI terminal]' \
+  '--color[assume a color ANSI terminal]' \
+  '--intro[display intro sequence]' \
+  '--filter=[preprocess data with a special multimedia filter]:number' \
+  '*:files:->files'
+
+case "$state" in
+  files)
+    if (( $+opt_args[-d] || $+opt_args[--decompress] ||
+	$+opt_args[--uncompress] || $+opt_args[-x] || $+opt_args[--extract] ||
+	$+opt_args[--test] || $+opt_args[-t] || $+opt_args[--list] ||
+	$+opt_args[-l] || $+opt_args[--ls] || $+opt_args[--info] )); then
+      _description files expl 'compressed file'
+      _files "$expl[@]" -g '*.[tl]zo'
+    else
+      _description files expl 'file to compress'
+      _files "$expl[@]" -g '*~*.[tl]zo'
+
+    fi
+  ;;
+  flags)
+    disp=( \
+      "F -- Append a \`*' for executable files" \
+      "G -- Inhibit display of group information" \
+      "Q -- Enclose file names in double quotes" )
+    disp=( ${disp[@]%[Z$PREFIX] -*} )
+    compset -P '[FGQ]*'
+    compadd -d disp - ${disp[@]% -*}
+  ;;
+esac
Index: Completion/User/_pack
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_pack,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 _pack
--- Completion/User/_pack	2000/01/08 16:48:21	1.1.1.3
+++ Completion/User/_pack	2000/05/05 09:56:14
@@ -1,6 +1,16 @@
-#compdef pack
+#compdef pack pcat unpack
 
-local expl
+local expl state line
 
-_description files expl 'file to compress'
-_files "$expl[@]" -g '*~*.z'
+case ${words[1]:t} in
+  pack)
+    _arguments -C \
+      '-f[force packing even for files which will not benefit]' \
+      '-[show statistics for files]' \
+      '*:file to compress:_files -g \*\~\*.z'
+  ;;
+  pcat|unpack)
+    _description files expl 'compressed file'
+    _files "$expl[@]" -g '*.z'
+  ;;
+esac
Index: Completion/User/_uncompress
===================================================================
RCS file: _uncompress
diff -N _uncompress
--- /tmp/cvsQPnghk	Fri May  5 02:56:15 2000
+++ /dev/null	Tue May  5 13:32:27 1998
@@ -1,6 +0,0 @@
-#compdef uncompress zmore
-
-local expl
-
-_description files expl 'compressed file'
-_files "$expl[@]" -g '*.Z'
Index: Completion/User/_unpack
===================================================================
RCS file: _unpack
diff -N _unpack
--- /tmp/cvseahtWH	Fri May  5 02:56:15 2000
+++ /dev/null	Tue May  5 13:32:27 1998
@@ -1,6 +0,0 @@
-#compdef unpack pcat
-
-local expl
-
-_description files expl 'compressed file'
-_files "$expl[@]" -g '*.z'
Index: Completion/User/_zcat
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_zcat,v
retrieving revision 1.1
diff -u -r1.1 _zcat
--- Completion/User/_zcat	2000/04/26 08:39:24	1.1
+++ Completion/User/_zcat	2000/05/05 09:56:14
@@ -15,6 +15,5 @@
 then
   _gzip "$@"
 else
-  _description files expl 'compressed file'
-  _files "$expl[@]" -g '*.Z'
+  _compress "$@"
 fi



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