initial
[zsh.git] / .zsh / functions / logout
1 # -*- mode:sh -*-
2
3 # Process the exceptions which allow logging out while still having
4 # attached jobs.
5
6 # This is weird . . $1 seems to contain "logout" because the "logout"
7 # command has been aliased to "noglob logout" - and $0 is the noglob.
8 # I can't believe that this is what is meant to happen.
9 if [[ $1 = "logout" ]]
10 then
11 shift
12 fi
13 # If the checkjobs option is unset, just plain exit. (This option
14 # emerged in zsh 3.1.8.)
15 if [[ ! -o checkjobs ]]
16 then
17 reallyexit ${1+"$@"}
18 fi
19 # Did I type logout twice in a row? Note check for history number.
20 if [[ $history[$#history] = (exit|(logout|lo)(|\ *)) || $lastlogout = $#history ]]; then
21 reallyexit ${1+"$@"}
22 fi
23
24 # Did I type jobs, then logout?
25 if [[ $history[$#history] = (j(|obs)(|\ *)) ]]; then
26 reallyexit ${1+"$@"}
27 fi
28
29 lastlogout=$#history
30
31 # Emulate the code that protects against logout if I have
32 # attached jobs.
33 if [[ $#jobstates -gt 0 ]]; then
34 # The first listed state is good enough to be a hint of my job states.
35 echo "You have ${jobstates[${${(k)jobstates}[1]}]%%:*} jobs."
36 return
37 fi
38
39 # If we got here we're really exiting.
40 reallyexit ${1+"$@"}