zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: Re: Nits in compinstall in -dev-22
Date: Tue, 11 Apr 2000 21:18:33 +0100	[thread overview]
Message-ID: <E12f779-0004gh-00.2000-04-11-21-18-23@cmailg4.svr.pol.co.uk> (raw)
In-Reply-To: ""Bart Schaefer""'s message of "Mon, 10 Apr 2000 05:16:18 -0000." <1000410051619.ZM18318@candle.brasslantern.com>

"Bart Schaefer" wrote:
> I just finished going through compinstall, hit `0' to save and exit,
> was told that my .zshrc had been backed up and successfully rewritten --
> and found nothing new in it.  It's identical to the backup.
> 
> Fortunately I enabled the settings for the current session, so I can
> just dump them where I want with "zstyle -L".
> 
> I'm sure the reason it didn't work is because I'd never used an older
> version of it, so the $endline string didn't already appear in my .zshrc;
> but I'm going to let PWS decide on the right way to fix it.

It now greps for it.

If you say no to saving in .zshrc, you can now enter another filename.

> First, I'd like to run compinstall, but I'd like to have it put its output
> somewhere other than .zshrc or .compinstall.  For that matter, I'd like to
> tell it to get its *input* from somewhere other than .zshrc.  And shouldn't
> it read an existing .compinstall file if there is one, either in preference
> to or as well as .zshrc?

The idea was that you move .compinstall where you want it, but there's no
reason you shouldn't just source it from .zshrc, I suppose.

Anyway, have a go at this.

Index: Completion/Core/compinstall
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/compinstall,v
retrieving revision 1.5
diff -u -r1.5 compinstall
--- Completion/Core/compinstall	2000/04/10 05:04:42	1.5
+++ Completion/Core/compinstall	2000/04/11 20:18:03
@@ -24,7 +24,7 @@
 
 typeset startline='# The following lines were added by compinstall'
 typeset endline='# End of lines added by compinstall'
-typeset ifile=${ZDOTDIR:-~}/.zshrc line fpath_line
+typeset ifile line fpath_line
 typeset -A styles
 typeset match mbegin mend matchers warn_unknown warn_old warn_comment
 integer lines_found
@@ -42,7 +42,38 @@
 # day I may even do that.
 #
 
-if [[ -f $ifile ]]; then
+__ci_test_ifile() {
+  [[ -f $1 ]] && grep "$endline" $1 >/dev/null 2>&1
+}
+
+local foundold=false
+ifile=${ZDOTDIR:-~}/.zshrc
+if __ci_test_ifile ${ZDOTDIR:-~}/.compinstall; then
+  ifile=${ZDOTDIR:-~}/.compinstall
+  foundold=true
+elif __ci_test_ifile $ifile; then
+  foundold=true
+fi
+
+local newifile=$ifile
+if [[ $foundold = true ]]; then
+  print "I have found completion definitions in $ifile.
+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
+else
+  print "I haven't found any existing completion definitions.
+If you have some already defined by compinstall, edit the name of the
+file where these can be found.  Note that this will only work if they
+are exactly the form in which compinstall inserted them.  If you leave
+the line as it is, or empty, I won't search."
+  vared -ch -p 'file> ' newifile
+  [[ -z $newifile || $ifile = $newifile ]] && foundold=false
+fi
+
+if [[ $foundold = true ]]; then
   sed -n "/^[   ]*$startline/,/^[       ]*$endline/p" $ifile |
   # Use the default read behaviour to handle any continuation lines.
   while read line; do
@@ -63,6 +94,8 @@
 ${match[3]}"
     elif [[ $line = [[:blank:]]#compconf* ]]; then
       warn_old=1
+    elif [[ $line == $startline || $line == $endline ]]; then
+      # no-op
     elif [[ $line = [[:blank:]]#\#* ]]; then
       warn_comment=1
     elif [[ $line != [[:blank:]]# &&
@@ -109,6 +142,9 @@
 usually returns before the end."
   fi
 fi
+print "Note that you will be given a chance to save the new setup
+somewhere else at the end."
+
 
 __ci_newline || return 1
 
@@ -1545,8 +1581,15 @@
 
   print -r "$output
 $endline" } >$tmpout
+
+if ! read -q key"?Save new settings to $ifile? "; then
+   print "Enter a different filename (~ will be expanded), or return to abort:"
+   ifile=
+   vared -ch -p 'file> ' ifile
+   ifile=${~ifile}
+fi
 
-if read -q key"?Save new settings to $ifile? "; then
+if [[ -n $ifile ]]; then
   #
   # Now use sed to update the file.
   #
@@ -1556,8 +1599,10 @@
   else
     touch $ifile
   fi
-  if sed -e "/^[ 	]*$endline/r $tmpout
-/^[ 	]*$startline/,/^[ 	]*$endline/d" $ifile >${tmpout}2 &&
+  if { { grep "$endline" $ifile >/dev/null 2>&1 &&
+         sed -e "/^[ 	]*$endline/r $tmpout
+/^[ 	]*$startline/,/^[ 	]*$endline/d" $ifile >${tmpout}2 } || 
+        cat $tmpout >>${tmpout}2 } &&
   mv ${tmpout}2 $ifile; then
     print "\nSuccessfully added compinstall lines to $ifile."
     rm -f $tmpout

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@CambridgeSiliconRadio.com
Web: http://www.pwstephenson.fsnet.co.uk


      reply	other threads:[~2000-04-11 20:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-10  4:56 Bart Schaefer
2000-04-10  5:16 ` Bart Schaefer
2000-04-11 20:18   ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E12f779-0004gh-00.2000-04-11-21-18-23@cmailg4.svr.pol.co.uk \
    --to=pws@pwstephenson.fsnet.co.uk \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).