Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Re: Nits in compinstall in -dev-22
- X-seq: zsh-workers 10669
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: Re: Nits in compinstall in -dev-22
- Date: Tue, 11 Apr 2000 21:18:33 +0100
- In-reply-to: ""Bart Schaefer""'s message of "Mon, 10 Apr 2000 05:16:18 -0000." <1000410051619.ZM18318@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
"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@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxxxxxxxxxxxxxxxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk
Messages sorted by:
Reverse Date,
Date,
Thread,
Author