1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| | #
# 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
}
|