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

Re: PATCH: newuser system



Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Sorry, my obfuscation was incomplete. :-)
> 
>       PWD=$zd eval 'zdmsg=${(%):-%~}'

I don't think that works... I think it's because the internal variable
doesn't get set when you change PWD, rather PWD is set as a normal variable
when you change directory.

Trying this showed up another problem which I'll patch separately.

> } [...] maybe I could set the initial [keymap] state to "Recommended"
> } and the default so that it picks "bindkey -e" unless you explicitly
> } tell it not to?
> 
> Sounds like the right idea.

This changes that, and also fixes the fact that actually if you didn't edit
the recommended settings then they weren't saved.  It also fixes the
problem noticed by Wayne: if compinstall has been run and returned status
0, I assume there's nothing more to do.  There are a few minor fixes,
including skipping the initial explanatory screen if the user explicitly
ran the function with the -f argument.

Index: Functions/Newuser/zsh-newuser-install
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Newuser/zsh-newuser-install,v
retrieving revision 1.3
diff -u -r1.3 zsh-newuser-install
--- Functions/Newuser/zsh-newuser-install	24 Nov 2005 11:46:47 -0000	1.3
+++ Functions/Newuser/zsh-newuser-install	25 Nov 2005 10:15:16 -0000
@@ -56,6 +56,7 @@
 
 install_state[history]=Recommended
 install_state[completion]=Recommended
+install_state[bindkey]=Recommended
 
 # Don't save anything if interrupted.
 trap 'save=0' HUP INT QUIT
@@ -344,6 +345,11 @@
   displays=("${display_lines[@]}")
   outputs=("${output_lines[@]}")
 
+  if [[ -n ${states[(r)not yet saved]} ]]; then
+    # default should be installed, unless user says otherwise
+    (( changes++ ))
+  fi
+
   while true; do
     clear
     print -r $1
@@ -531,7 +537,8 @@
       # Also save any lines suitably marked to parsed_* and state_*
       # by rerunning __zni_parse_lines on each such line.
       for (( i = 1; i <= ${#output_lines}; i++ )); do
-	if [[ $state_lines[$i] = ("set but not saved"|"not to be saved") ]]
+	if [[ $state_lines[$i] = \
+	  ("set but not saved"|"not to be saved"|"not yet saved") ]]
 	then
 	  __zni_parse_lines $state_lines[$i] $output_lines[$i]
 	fi
@@ -659,6 +666,15 @@
       (vi)
       lines+=("bindkey -v")
       ;;
+
+      (none)
+      ;;
+
+      (*)
+      print -r "\
+*** Internal error: bad type $parsed_keymaps[main] for keymap ***" >&2
+      read -k key'?--- Type a key in forlorn hope --- '
+      ;;
     esac
   fi
   # Now bindings.
@@ -753,8 +769,12 @@
 	;;
 
 	(2)
-	compinstall
-	install_state[completion]="Configured"
+	if compinstall; then
+	  install_state[completion]="Configured"
+	  # compinstall has done it's thing, so we don't need
+	  # to write anything.
+	  completion_lines=()
+	fi
 	;;
 
 	(0)
@@ -772,7 +792,7 @@
 }
 
 __zni_bindkey_config() {
-  __zni_apply_defaults -B none "Change default editing configuration"
+  __zni_apply_defaults -B emacs "Change default editing configuration"
 
   if __zni_display_and_edit "Default editing configuration" \
     "The keys in the shell's line editor can be made to behave either" \
@@ -838,53 +858,54 @@
 fi
 
 
-clear
-print -r "This is the Z Shell configuration function for new users, $myname."
+# skip initial screen if the function was deliberately run by the user.
 if [[ $1 != -f ]]; then
-  print -r "You are seeing this message because you have no zsh startup files
+  clear
+  print -r "This is the Z Shell configuration function for new users, $myname.
+You are seeing this message because you have no zsh startup files
 (the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
 $zdmsg).  This function can help you with a few settings that should
-make your use of the shell easier."
-fi
+make your use of the shell easier.
 
-print -r "
 You can:
 
 (q)  Quit and do nothing.  The function will be run again next time."
-if [[ ! -f $zd/.zshrc ]]; then
-  print -r "
+  if [[ ! -f $zd/.zshrc ]]; then
+    print -r "
 (0)  Exit, creating the file $zdmsg/.zshrc containing just a comment.
      That will prevent this function being run again."
-fi
-print -r "
+  fi
+  print -r "
 (1)  Continue to main menu.
 "
 
-read -k key$longprompt
-print
+  read -k key$longprompt
+  print
 
-case $key in
-  ([qQ])
-  return 0
-  ;;
+  case $key in
+    ([qQ])
+    return 0
+    ;;
 
-  (0)
-  print -r $msg >$zd/.zshrc
-  return 0
-  ;;
+    (0)
+    print -r $msg >$zd/.zshrc
+    return 0
+    ;;
 
-  (1)
-  ;;
+    (1)
+    ;;
 
-  (*)
-  print -r "Aborting."
-  if [[ $1 != -f ]]; then
-    print "The function will be run again next time.  To prevent this, execute:
+    (*)
+    print -r "Aborting."
+    if [[ $1 != -f ]]; then
+      print "\
+The function will be run again next time.  To prevent this, execute:
   touch $zdmsg/.zshrc"
-  fi
-  return 1
-  ;;
-esac
+    fi
+    return 1
+    ;;
+  esac
+fi
 
 while true; do
   clear
@@ -903,7 +924,8 @@
   print -r " the new completion system.\
 ${install_state[completion]:+  ($install_state[completion].)}
 
-(3)  Configure how keys behave when editing command lines.
+(3)  Configure how keys behave when editing command lines.\
+${install_state[bindkey]:+  ($install_state[bindkey].)}
 
 (4)  Pick some of the more common shell options.  These are simple on
      or off switches controlling the shell's features.  \
@@ -954,7 +976,7 @@
     if (( save )); then
       if [[ -f $zd/.zshrc ]]; then
 	cp $zd/.zshrc $zd/.zshrc.zni &&
-	print -r "Copied old '$zdd/.zshrc' to '$zdd/.zshrc.zni'.
+	print -r "Copied old '$zdmsg/.zshrc' to '$zdmsg/.zshrc.zni'.
 "
       fi
 



-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com



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