diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | Functions/Newuser/zsh-newuser-install | 94 | ||||
-rw-r--r-- | Src/exec.c | 36 |
3 files changed, 101 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog index 9cb50b880..7cd17e0f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-11-25 Peter Stephenson <pws@csr.com> + + * 22028: Src/exec.c: WARN_GLOBAL_CREATE warned when temporarily + altering a global in the environment of a builtin or shell + function. + + * 22027: Functions/Newuser/zsh-newuser-install: fix multiple + compinstall lines; suggest selecting emacs keymap slightly + more forcefully; ensure recommended selections are saved + if not edited; trap bad keymap names; don't show initial + explanatory screen if rerun explicitly by user; fix message + about copying old .zshrc. + 2005-11-25 Oliver Kiddle <opk@zsh.org> * 22022: Completion/Debian/Command/_dchroot: completion for dchroot diff --git a/Functions/Newuser/zsh-newuser-install b/Functions/Newuser/zsh-newuser-install index d8fd437ed..6304a8dd4 100644 --- a/Functions/Newuser/zsh-newuser-install +++ b/Functions/Newuser/zsh-newuser-install @@ -56,6 +56,7 @@ integer save lines_found 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 @@ __zni_display_and_edit() { 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 @@ Type: # 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 @@ __zni_save() { (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 @@ You can: ;; (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 @@ You can: } __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 @@ if compinstall -d; then 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 @@ ${install_state[history]:+ ($install_state[history].)} 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 @@ ${install_state[options]:+ ($install_state[options].)} 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 diff --git a/Src/exec.c b/Src/exec.c index 663cb6ab7..58fc476bc 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -30,6 +30,17 @@ #include "zsh.mdh" #include "exec.pro" +/* Flags for last argument of addvars */ + +enum { + /* Export the variable for "VAR=val cmd ..." */ + ADDVAR_EXPORT = 1 << 0, + /* Apply restrictions for variable */ + ADDVAR_RESTRICT = 1 << 1, + /* Variable list is being restored later */ + ADDVAR_RESTORE = 1 << 2 +}; + /* used to suppress ERREXIT and trapping of SIGZERR, SIGEXIT. */ /**/ @@ -1644,7 +1655,7 @@ addfd(int forked, int *save, struct multio **mfds, int fd1, int fd2, int rflag, /**/ static void -addvars(Estate state, Wordcode pc, int export) +addvars(Estate state, Wordcode pc, int addflags) { LinkList vl; int xtr, isstr, htok = 0; @@ -1655,7 +1666,14 @@ addvars(Estate state, Wordcode pc, int export) wordcode ac; local_list1(svl); - flags = (locallevel > 0 && isset(WARNCREATEGLOBAL)) ? + /* + * Warn when creating a global without using typeset -g in a + * function. Don't do this if there is a list of variables marked + * to be restored after the command, since then the assignment + * is implicitly scoped. + */ + flags = (!(addflags & ADDVAR_RESTORE) && + locallevel > 0 && isset(WARNCREATEGLOBAL)) ? ASSPM_WARN_CREATE : 0; xtr = isset(XTRACE); if (xtr) { @@ -1708,8 +1726,8 @@ addvars(Estate state, Wordcode pc, int export) quotedzputs(val, xtrerr); fputc(' ', xtrerr); } - if (export && !strchr(name, '[')) { - if (export < 0 && isset(RESTRICTED) && + if ((addflags & ADDVAR_EXPORT) && !strchr(name, '[')) { + if ((addflags & ADDVAR_RESTRICT) && isset(RESTRICTED) && (pm = (Param) paramtab->removenode(paramtab, name)) && (pm->flags & PM_RESTRICTED)) { zerr("%s: restricted", pm->nam, 0); @@ -2520,7 +2538,13 @@ execcmd(Estate state, int input, int output, int how, int last1) /* Export this if the command is a shell function, * but not if it's a builtin. */ - addvars(state, varspc, is_shfunc); + int flags = 0; + if (is_shfunc) + flags |= ADDVAR_EXPORT; + if (restorelist) + flags |= ADDVAR_RESTORE; + + addvars(state, varspc, flags); if (errflag) { if (restorelist) restore_params(restorelist, removelist); @@ -2597,7 +2621,7 @@ execcmd(Estate state, int input, int output, int how, int last1) } if (type == WC_SIMPLE) { if (varspc) { - addvars(state, varspc, -1); + addvars(state, varspc, ADDVAR_EXPORT|ADDVAR_RESTRICT); if (errflag) _exit(1); } |