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

PATCH: pws-25: old shell functions again



Andrej Borsenkow wrote:
> I just realised, that it may be better to save the whole directory (in
> functions.old probably). Moving files to *.old has potential problem, that 
> if anybody autloads whole $fpath, he will suddenly get a lot of fn.old
> functions.

I was thinking about this too, but there may be other local files in the
functions hierarchy --- in fact, that's rather the intention.  This patch
is the latest idea.  (The claimed effect of the old patch has disappeared
from my copy of the source. Strange.)  If the function already exists and
is different, it gets moved into a corresponding place under functions.old
(for example, ..../functions/User/_rcs -> ..../functions.old/User/_rcs).
Then when uninstalling these all get moved back.  Thus old functions are
out of the load path, but functions not being installed are unaffected.

One slight hiccup here is that when uninstalling, files which existed
before but were unchanged are deleted.  That's because it seems pointless
to save identical files, but we then lose the memory of whether they were
there before.  This could be fixed by saving a date stamp at the start of
installation and only deleting files modified after on uninstallation.  I
haven't the strength to do that at the moment, but now installfns.sh is a
script it should be a bit more doable.

Oliver Kiddle wrote:
> One thing which I would like changed is for compinit to add directories
> to the end of $fpath instead of the beginning. This way, I can override
> the zsh supplied completions with my own.

Yes, I was wondering about that.  This changes it.

> I would also be tempted to prefix the zsh completion
> directories with a 'Z' so that compinit would put other directories in
> /usr/local/share/zsh/functions (such as one named 'Local') first in
> $fpath.

As we're already inside the zsh hierarchy, it seems a bit redundant to keep
adding more Z's.  You can have directories AALocal or 1Local, of course.

> A result of the latest compinstall seems to be that I get the Core
> directory duplicated in my $fpath. The compinstall created .zshrc adds
> it so that it can autoload compinit and compinit then adds it in again.

It was supposed to check, but there was a typo.

--- Completion/Core/compinit.finst	Thu Jul  8 10:38:51 1999
+++ Completion/Core/compinit	Fri Jul  9 14:11:57 1999
@@ -314,10 +314,10 @@
     fi
     for _i_line in {1..$#i_addfiles}; do
       _i_file=${_i_addfiles[$_i_line]}
-      [[ -d $_i_file && -z ${fpath[(r)$_i_$file]} ]] ||
+      [[ -d $_i_file && -z ${fpath[(r)$_i_file]} ]] ||
         _i_addfiles[$_i_line]=
     done
-    fpath=($_i_addfiles $fpath)
+    fpath=($fpath $_i_addfiles)
     _i_files=( ${^~fpath:/.}/_(|*[^~])(N:t) )
   fi
 fi
--- Config/funcinst.mk.finst	Sun Jul  4 15:02:19 1999
+++ Config/funcinst.mk	Fri Jul  9 14:23:09 1999
@@ -29,33 +29,19 @@
 
 install.fns:
 	if test x$(fndir) != x && test x$(fndir) != xno; then \
-	  $(sdir_top)/mkinstalldirs $(fndir) || exit 1; \
-	  for file in $(FUNCTIONS_INSTALL); do \
-	    if test -f $$file; then \
-	      if test x$(FUNCTIONS_SUBDIRS) != x -a \
-	      x$(FUNCTIONS_SUBDIRS) != xno; then \
-	        subdir="`echo $$file | sed -e 's%/.*%%'`"; \
-	        $(sdir_top)/mkinstalldirs $(fndir)/$$subdir || exit 1; \
-	        $(INSTALL_DATA) $$file $(fndir)/$$subdir || exit 1; \
-	      else \
-	        $(INSTALL_DATA) $$file $(fndir) || exit 1; \
-	      fi; \
-	    fi; \
-	  done; \
+	  sdir_top="$(sdir_top)" fndir="$(fndir)" \
+	  FUNCTIONS_INSTALL="$(FUNCTIONS_INSTALL)" \
+	  FUNCTIONS_SUBDIRS="$(FUNCTIONS_SUBDIRS)" \
+	  INSTALL_DATA="$(INSTALL_DATA)" \
+	  $(SHELL) $(sdir_top)/Config/installfns.sh || exit 1; \
 	fi; \
 	exit 0
 
 uninstall.fns:
 	if test x$(fndir) != x && test x$(fndir) != xno; then \
-	  for file in $(FUNCTIONS_INSTALL); do \
-	    if test -f $$file; then \
-	      if test x$(FUNCTIONS_SUBDIRS) != x -a \
-	      x$(FUNCTIONS_SUBDIRS) != xno; then \
-	        rm -f $(fndir)/$$file; \
-	      else \
-	        rm -f "$(fndir)/`echo $$file | sed -e 's%^.*/%%'`"; \
-	      fi; \
-	    fi; \
-	  done; \
+	  fndir="$(fndir)" \
+	  FUNCTIONS_INSTALL="$(FUNCTIONS_INSTALL)" \
+	  FUNCTIONS_SUBDIRS="$(FUNCTIONS_SUBDIRS)" \
+	  $(SHELL) $(sdir_top)/Config/uninstallfns.sh || exit 1; \
 	fi; \
 	exit 0
--- Config/installfns.sh.finst	Fri Jul  9 14:04:42 1999
+++ Config/installfns.sh	Fri Jul  9 13:52:28 1999
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+if test -d $fndir.old; then
+  add_old=1
+fi
+
+$sdir_top/mkinstalldirs $fndir || exit 1;
+
+for file in $FUNCTIONS_INSTALL; do
+  if test -f $file; then
+    if test x$FUNCTIONS_SUBDIRS != x -a x$FUNCTIONS_SUBDIRS != xno; then
+      subfile="$file"
+      subdir="`echo $file | sed -e 's%/[^/]*$%%'`"
+      olddir="$fndir.old/$subdir"
+      instdir="$fndir/$subdir"
+    else
+      subfile="`echo $file | sed -e 's%^.*/%%'`"
+      olddir="$fndir.old"
+      instdir="$fndir"
+    fi
+    if test -f $fndir/$subfile; then
+      if cmp $fndir/$subfile $file >/dev/null; then :; else
+	$sdir_top/mkinstalldirs $olddir
+        mv $fndir/$subfile $olddir
+        : ${add_old:=1}
+      fi
+    fi
+    $sdir_top/mkinstalldirs $instdir || exit 1
+    $INSTALL_DATA $file $instdir || exit 1
+  fi
+done
+
+if test x$add_old != x1; then
+  rm -rf $fndir.old
+fi
+
+exit 0
--- Config/uninstallfns.sh.finst	Fri Jul  9 14:04:45 1999
+++ Config/uninstallfns.sh	Fri Jul  9 13:58:05 1999
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+for file in $FUNCTIONS_INSTALL; do
+  if test -f $file; then
+    if test x$FUNCTIONS_SUBDIRS != x -a x$FUNCTIONS_SUBDIRS != xno; then
+      rm -f $fndir/$file;
+    else
+      rm -f "$fndir/`echo $file | sed -e 's%^.*/%%'`"; \
+    fi
+  fi
+done
+
+if test -d $fndir.old; then
+  for f in $fndir.old/*; do
+    if test -d $f; then
+      for f2 in $f/*; do
+	mv $f2 $fndir/"`echo $f | sed -e 's%^.*/%%'`"
+      done
+    else
+      mv $f $fndir
+    fi
+  done
+  rm -rf $fndir.old
+fi
+
+exit 0
--- INSTALL.finst	Wed Jul  7 14:13:53 1999
+++ INSTALL	Fri Jul  9 14:10:29 1999
@@ -256,12 +256,16 @@
 directory, i.e. `Core/*' files will be installed into `FNDIR/Core', and so
 on. This also initialises $fpath/$FPATH appropriately.
 
-An existing installed shell function which differs from the one to be
-installed will be moved to a file with the suffix `.old', and restored to
-the original name on `make uninstall'.  However, an existing shell function
-identical to the one to be installed will simply be deleted on `make
-uninstall'.  If the old functions came unchanged from a previous zsh
-distribution, the `.old' files may simply be deleted by hand.
+On installation, any completion function which already exists but is
+different from the new version will be moved to a corresponding place in
+FNDIR.old; for example, if a different version of User/_rcs exists when
+installing into /usr/local/share/zsh/functions/User, the old one will be
+moved into /usr/local/share/zsh/functions.old/User.  The installer is
+responsible for recovering or deleting old functions which have been moved
+in this way.  On uninstallation, any newly installed functions (including
+those which existed before but were unchanged) will be deleted and the
+files in the FNDIR.old hierarchy moved back into FNDIR.  To preserve the
+entire old hierarchy, you should move or copy it before installation.
 
 Support for large files and integers
 ------------------------------------

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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