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

Re: Refactoring _bsd_pkg



In message <2419.1041518512@xxxxxxxxxxxxxxxxxxxx>
on Thu, Jan 02, 2003 at 03:41:52PM +0100, Oliver Kiddle wrote:
> Is there any chance that you could merge your OpenBSD functions into
> the _bsd_pkg HEAD and then submit a patch to the zsh-workers list. They
> can then be committed to cvs without upsetting FreeBSD users. It should
> just be a matter of sticking an `openbsd*)' section in the various `case
> "$OSTYPE" in' parts of the function.

Yes, that's fine, I have attached a diff for the beast, only improving
pkd_delete, and pkg_info. I also replaced tabs with spaces since the
file seemed to have a mixture, and that's made the patch a bit large.
This is just a heads-up and I don't really intent on anyone feeling
willing to commit this verbatim -- it's night-time here and I'll have
another look at it tomorrow. (And the person with the CC of my post is
the OpenBSD port maintainer for zsh, so he may have something useful to
add.)

pkg_add still doesn't work quite right because it always has some
directories (those matching the pattern /*) in the completion list,
even if my current directory is not /.

PS. I replaced '\'' with '', but maybe that's not portable? Also, I
noticed that in my own script, I had an error for the -l option (I
suspect it's an option that's never used in an interactive shell,
let alone used with a completion mechanism).

Index: _bsd_pkg
OpenBSD compatability for pkg_delete and pkg_info options.
OpenBSD compatability for pkg_add packages list.
Detabbed.
Allow symlinks to directories in addition to directories.
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/BSD/Command/_bsd_pkg,v
retrieving revision 1.5
diff -u -r1.5 _bsd_pkg
--- _bsd_pkg	26 Sep 2002 10:30:01 -0000	1.5
+++ _bsd_pkg	2 Jan 2003 15:31:42 -0000
@@ -6,15 +6,19 @@
 
   case $OSTYPE in
   netbsd*)
-    portsdir=/usr/pkgsrc
+    portsdir=${PORTSDIR:-/usr/pkgsrc}
+    pkgsdir=${PACKAGES:-$portsdir/packages}/All
+    ;;
+  openbsd*)
+    portsdir=${PORTSDIR:-/usr/ports}
+    pkgsdir=${PACKAGES:-$portsdir/packages}/$(arch -s)/All
     ;;
   *)
     portsdir=${PORTSDIR:-/usr/ports}
+    pkgsdir=${PACKAGES:-$portsdir/packages}/All
     ;;
   esac
 
-  pkgsdir=${PACKAGES:-$portsdir/packages}/All
-
   paths=( "${(@)${(@s.:.)PKG_PATH}:#}" )
   _files "$@" -g '*.t[bg]z' && ret=0
   (( $#path )) && _files "$@" -W paths -g '*.t[bg]z' && ret=0
@@ -25,7 +29,7 @@
 
 (( $+functions[_bsd_pkg_pkgs] )) ||
 _bsd_pkg_pkgs() {
-  compadd "$@" - ${PKG_DBDIR:-/var/db/pkg}/*(/:t)
+  compadd "$@" - ${PKG_DBDIR:-/var/db/pkg}/*(-/:t)
 }
 
 (( $+functions[_bsd_pkg_pkgs_and_files] )) ||
@@ -48,11 +52,11 @@
   pkg_add)
     flags=(
       '-f[force installation]'
-      '-I[don'\''t execute installation scripts]'
+      '-I[don''t execute installation scripts]'
       '-M[run in master mode]'
-      '-n[don'\''t really install packages]'
+      '-n[don''t really install packages]'
       '-p[specify prefix]:prefix directory:_files -/'
-      '-R[don'\''t record]'
+      '-R[don''t record]'
       '-S[run in slave mode]'
       '-t[specify mktemp template]:mktemp template:_files -/'
       '-v[be verbose]'
@@ -67,9 +71,9 @@
       ;;
     netbsd*)
       flags=(
-	$flags[@]
-	'-u[update]'
-	'-V[show version and exit]'
+        $flags[@]
+        '-u[update]'
+        '-V[show version and exit]'
       )
       ;;
     esac
@@ -83,37 +87,37 @@
     case "$OSTYPE" in
     freebsd*)
       flags=(
-	'-f[specify plist file]:plist file:_files'
-	'(-b)-c[specify comment file]:comment file:_files'
-	'(-b)-d[specify descr file]:descr file:_files'
-	'-Y[assume YES for any questions asked]'
-	'-N[assume NO for any questions asked]'
-	'(-b)-O[packing list only mode]'
-	'-v[be verbose]'
-	'-h[force tar to follow symlinks]'
-	'(-b)-i[specify pre-install script]:pre-install script:_files'
-	'(-b)-I[specify post-install script]:post-install script:_files'
-	'(-b)-P[specify initial dependencies]:dependencies:_bsd_pkg_pkgs'
-	'(-b)-p[specify prefix]:prefix directory:_files -/'
-	'(-b)-k[specify deinstall script]:deinstall script:_files'
-	'(-b)-K[specify post-deinstall script]:post-deinstall script:_files'
-	'(-b)-r[specify req script]:req script:_files'
-	'(-b)-s[specify source directory]:source directory:_files -/'
-	'(-b)-t[specify mktemp template]:mktemp template:_files'
-	'(-b)-X[specify exclude file]:exclude file for tar:_files'
-	'(-b)-D[specify message file]:message file:_files'
-	'(-b)-m[specify mtree file]:mtree file:_files'
-	'(-b)-o[specify origin]:origin:_files -W ${PORTSDIR\:-/usr/ports} -/'
-	'-j[use bzip2]'
-	'-z[use gzip]'
-	'(-c -d -O -i -I -P -p -k -K -r -s -t -X -D -m -o)-b[specify pkgname]:pkgname:_bsd_pkg_pkgs'
-	'*:package file name:_files'
+        '-f[specify plist file]:plist file:_files'
+        '(-b)-c[specify comment file]:comment file:_files'
+        '(-b)-d[specify descr file]:descr file:_files'
+        '-Y[assume YES for any questions asked]'
+        '-N[assume NO for any questions asked]'
+        '(-b)-O[packing list only mode]'
+        '-v[be verbose]'
+        '-h[force tar to follow symlinks]'
+        '(-b)-i[specify pre-install script]:pre-install script:_files'
+        '(-b)-I[specify post-install script]:post-install script:_files'
+        '(-b)-P[specify initial dependencies]:dependencies:_bsd_pkg_pkgs'
+        '(-b)-p[specify prefix]:prefix directory:_files -/'
+        '(-b)-k[specify deinstall script]:deinstall script:_files'
+        '(-b)-K[specify post-deinstall script]:post-deinstall script:_files'
+        '(-b)-r[specify req script]:req script:_files'
+        '(-b)-s[specify source directory]:source directory:_files -/'
+        '(-b)-t[specify mktemp template]:mktemp template:_files'
+        '(-b)-X[specify exclude file]:exclude file for tar:_files'
+        '(-b)-D[specify message file]:message file:_files'
+        '(-b)-m[specify mtree file]:mtree file:_files'
+        '(-b)-o[specify origin]:origin:_files -W ${PORTSDIR\:-/usr/ports} -/'
+        '-j[use bzip2]'
+        '-z[use gzip]'
+        '(-c -d -O -i -I -P -p -k -K -r -s -t -X -D -m -o)-b[specify pkgname]:pkgname:_bsd_pkg_pkgs'
+        '*:package file name:_files'
       )
       ;;
     netbsd*)
       # NetBSD users, improve me!
       flags=(
-	'*:package name:_bsd_pkg_pkgs'
+        '*:package name:_bsd_pkg_pkgs'
       )
       ;;
     esac
@@ -124,10 +128,10 @@
 
   pkg_delete)
     flags=(
-      '-D[don'\''t execute deinstallation scripts]'
+      '-D[don''t execute deinstallation scripts]'
       '-d[remove empty directories]'
       '-f[force deinstallation]'
-      '-n[don'\''t really deinstall packages]'
+      '-n[don''t really deinstall packages]'
       '-p[specify prefix]:prefix directory:_files -/'
       '-v[be verbose]'
     )
@@ -136,35 +140,43 @@
     freebsd*)
       flags=(
         $flags[@]
-	'(:)-a[delete all installed packages]'
+        '(:)-a[delete all installed packages]'
         '-G[do not expand glob patterns]'
-	'-i[be interactive]'
+        '-i[be interactive]'
         '-r[delete recursively]'
         '-x[use regular expression]'
       )
       ;;
     netbsd*)
       flags=(
-	$flags[@]
-	'(:)-a[delete all installed packages]'
-	'-F[specify each package by an installed file]'
-	'-i[be interactive]'
-	'-O[only delete the package'\''s entries]'
+        $flags[@]
+        '(:)-a[delete all installed packages]'
+        '-F[specify each package by an installed file]'
+        '-i[be interactive]'
+        '-O[only delete the package''s entries]'
         '-R[delete upward recursively]'
         '-r[delete recursively]'
-	'-V[show version and exit]'
+        '-V[show version and exit]'
       )
       ;;
     esac
 
-    _arguments -s \
-      $flags[@] \
-      '(-a)*:package name:_bsd_pkg_pkgs_and_files'
+    case "$OSTYPE" in
+    openbsd*)
+      _arguments -s \
+        $flags[@] \
+        '*:installed package name:_bsd_pkg_pkgs'
+      ;;
+    *)
+      _arguments -s \
+        $flags[@] \
+        '(-a)*:package name:_bsd_pkg_pkgs_and_files'
+      ;;
+    esac
     ;;
 
   pkg_info)
     flags=(
-      '(:)-a[show all installed packages]'
       '-c[show comment fields]'
       '-D[show install-message files]'
       '-d[show long descriptions]'
@@ -188,30 +200,41 @@
       flags=(
         $flags[@]
         '-G[do not expand glob patterns]'
-	'-g[show files that'\''s modified]'
-	'-o[show origin]'
-	'-s[show total size occupied by each package]'
-	'-t[specify mktemp template]:mktemp template:_files -/'
-	'*-W[show which package the file belongs to]:file:_files'
-	'-x[use regular expression]'
+        '-g[show files that are modified]'
+        '-o[show origin]'
+        '-s[show total size occupied by each package]'
+        '-t[specify mktemp template]:mktemp template:_files -/'
+        '*-W[show which package the file belongs to]:file:_files'
+        '-x[use regular expression]'
       )
       ;;
     netbsd*)
       flags=(
-	$flags[@]
-	'-B[show build information]'
-	'-b[show RCS Id strings]'
-	'-F[specify each package by an installed file]'
-	'-S[show total size occupied by each package and its dependents]'
-	'-s[show total size occupied by each package]'
-	'-V[show version and exit]'
+        $flags[@]
+        '-B[show build information]'
+        '-b[show RCS Id strings]'
+        '-F[specify each package by an installed file]'
+        '-S[show total size occupied by each package and its dependents]'
+        '-s[show total size occupied by each package]'
+        '-V[show version and exit]'
       )
       ;;
     esac
 
-    _arguments -s \
-      $flags[@] \
-      '(-a)*:package name:_bsd_pkg_pkgs_and_files'
+    case "$OSTYPE" in
+    openbsd*)
+      _arguments -s \
+        '(* -)-a[show all installed packages]' \
+        $flags[@] \
+        '*:installed package name:_bsd_pkg_pkgs'
+      ;;
+    *)
+      _arguments -s \
+        '(:)-a[show all installed packages]' \
+        $flags[@] \
+        '(-a)*:package name:_bsd_pkg_pkgs_and_files'
+      ;;
+    esac
     ;;
   esac
 }


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