# # Restarts the shell if and only if it can restart without error. # emulate -LR zsh { # Some users export $ZDOTDIR, which can mess things up. local zdotdir=$ZDOTDIR unset ZDOTDIR print 'Validating...' # Try if the shell can start up without errors. Passing an empty command # ensures that the subshell exits immediately after executing all dotfiles. # We suppress standard out, since we're interested in standard error only. setopt multios local err="$(zsh --interactive --monitor --zle -c '' 2>&1 > /dev/null)" local -i ret=$? if (( ret )) || [[ -n $err ]]; then [[ -n $err ]] && print -ru2 -- "$err" print -nu2 'Validation failed' (( ret )) && print -nu2 " with exit status $ret" [[ -n $err ]] && print -nu2 '. Please fix the error(s) above' print -u2 '.' print -u2 'Restart aborted.' (( ret )) || (( ret = 64 )) # EX_DATAERR; see `man 3 sysexits`. return ret else print 'Restarting...' exec zsh fi } always { ZDOTDIR=$zdotdir }