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

Re: Why Zsh doesn't warn me again?



On Dec 9,  4:20pm, DervishD wrote:
}
}     If you have suspended or backgrounded jobs and try to exit the
} shell, zsh warns you. According to the manual, if you issue the
} 'jobs' command or just try to exit again, you are not warned again,
} the shell exits and the jobs are terminated (except nohupped and
} disowned ones, obviously). But really, it doesn't matter what command
} you issue next, if you try to exit again, you are not warned :((

The manual is a little too easy to misinterpret in this instance.

Although it says "you will be warned that `You have suspended (running)
jobs'.  You may use the jobs command to see what they are.  If you do
this or immediately try to exit again, the shell will not warn you a
second time" you don't have to get the first warning before the `jobs'
command has this effect.  ANY time the `jobs' command has just been
used, zsh will exit silently at the next prompt.

As far as I can tell, that isn't specifically documented anywhere, it's
just the behavior that was considered most logical.

The second problem is that typing the EOF character (ctrl-D) is not the
same as using `exit'.  It takes at least _two_ commands after an attempt
to exit before zsh will warn you again on an EOF.  That is:

1 zsh% sleep 600 &
2 zsh% exit
  zsh: you have running jobs
3 zsh% echo not yet
  not yet
4 zsh% echo wait for it
  wait for it
5 zsh% ^D
  zsh: you have running jobs
6 zsh%

If instead you ctrl-D at prompt (4), zsh will silently exit, no matter
what command you gave at prompt (3).  However, an `exit' command at (4)
will warn you again.

This happens because EOF is interpreted earlier in the command loop,
so zsh fails to properly decrement the attempted-to-exit counter (a
global called "stopmsg" if you look at the C source).  I'd say this
is a bug.
 
} How can I change this (without IGNORE_EOF'ing) so Zsh act like the
} doc says?

Use the "stty" command to set the EOF character to something other
than ctrl-D, and then bind ^D to a function similar to this one:

    eof-or-delete-char-or-list() {
	if (( $#BUFFER == 0 )); then
	    BUFFER=exit
	    zle accept-line
	else
	    zle delete-char-or-list
	fi
    }
    zle -N eof-or-delete-char-or-list
    bindkey \^D eof-or-delete-char-or-list

If you want to be able to use ^D as EOF in external commands, use

export STTY="eof '^D'"

(Remember to change the eof character before you freeze the tty, if you
happen to be using ttyctl.)



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