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

Re: compinstall and command to add to the .zshrc



Vincent Lefevre wrote:
> After running compinstall, I get:
> 
> Enter file to save in (~ will be expanded), or return to abort:
> file> .zcomp
> If you want this file to be run automatically, you should add
>   . .zcomp
> to your .zshrc.  compinstall will remember the name of this file for
> future use.
> 
> But the zshbuiltins(1) man page says that the shell looks in the
> components of $path to find the directory containing the file.
> So, I don't see how this can work, unless ~ is in $path, and it
> usually isn't. Shouldn't compinstall have said ". ~/.zcomp"?

We discussed this and it's because the user entered a relative path.
The following is supposed to intercept that.  I haven't tried every
combination.

Index: Completion/compinstall
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/compinstall,v
retrieving revision 1.9
diff -u -r1.9 compinstall
--- Completion/compinstall	23 Nov 2005 11:29:21 -0000	1.9
+++ Completion/compinstall	20 Aug 2006 22:47:57 -0000
@@ -109,15 +109,23 @@
   return
 fi
 
-
 local newifile=$ifile
 if [[ $foundold = true ]]; then
-  print "I have found completion definitions in $ifile.
+  if [[ $newifile != [~/]* ]]; then
+    newifile=${ZDOTDIR:-~}/$newifile
+    print "[Existing completion definition file is not absolute path:
+updating to $newifile]"
+  fi
+  print "I have found completion definitions in $newifile.
 If you want me to read these, just hit return.  Otherwise, edit the file
 name to look for definitions somewhere else, or delete the whole line
 in order not to use existing definitions."
   vared -ch -p 'file> ' newifile
-  [[ -z $newifile ]] && foundold=false
+  if [[ -n $newifile && $newifile != [/~]* ]]; then
+    newifile=$PWD/$newifile
+    print "[Not absolute path: updating to $newifile]"
+  fi
+  [[ -z $newifile || ! -f $newfile ]] && foundold=false
 else
   print "I haven't found any existing completion definitions.
 If you have some already defined by compinstall, edit the name of the
@@ -126,6 +134,10 @@
 the line as it is, or empty, I won't search."
   while true;  do
     vared -ch -p 'file> ' newifile || break
+    if [[ -n $newifile && $newifile != [/~]* ]]; then
+      newifile=$PWD/$newifile
+      print "[Not absolute path: updating to $newifile]"
+    fi
     if [[ -n $newifile && $ifile != $newifile ]]; then
       if __ci_test_ifile $newifile; then
         foundold=true
@@ -138,7 +150,7 @@
     fi
   done
 fi
-ifile=$newifile
+ifile=${~newifile}
 
 if [[ $foundold = true ]]; then
   sed -n "/^[ 	]*$startline/,/^[ 	]*$endline/p" $ifile |
@@ -1926,6 +1938,10 @@
    print "Enter file to save in (~ will be expanded), or return to abort:"
    ifile=
    vared -ch -p 'file> ' ifile
+   if [[ $ifile != [/~]* ]]; then
+     ifile=$PWD/$ifile
+     print "[Not absolute path; updating to $ifile]"
+   fi
    ifile=${~ifile}
 fi
 
-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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