* IGNORE_EOF like in bash
@ 2001-04-25 20:33 Christoph Lange
2001-04-26 3:49 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Lange @ 2001-04-25 20:33 UTC (permalink / raw)
To: zsh-users
Hi there,
last year I suggested that the IGNORE_EOF shell option should be
implemented the same way as in bash, which means that the user can determine
how many consecutive presses of ^D are ignored before he or she is logged
out.
This has not been done by now, but I found out that one can script it in
zsh-4.0.1-pre-3 (maybe in other versions later than zsh-3.1.9, too), since
the shell no longer bypasses ZLE when ^D is pressed on an empty command
line.
Here is my solution, configurable by the variable IGNOREEOF:
IGNOREEOF=3 # or something like that
bash-ctrl-d() {
if [[ $CURSOR == 0 && -z $BUFFER ]]
then
[[ -z $IGNOREEOF || $IGNOREEOF == 0 ]] && exit
[[ $LASTWIDGET == bash-ctrl-d ]] \
&& (( --__BASH_IGNORE_EOF == 0 )) \
&& exit
: ${__BASH_IGNORE_EOF=$IGNOREEOF}
zle send-break
else
zle delete-char-or-list
fi
}
zle -N bash-ctrl-d
bindkey "^D" bash-ctrl-d
Hope you find it useful,
Christoph
--
Geeks aren't interested in politics because government doesn't
double its efficiency and speed once every 18 months.
Christoph Lange, langec@gmx.de, http://www.cul.de/home/yaph/, ICQ #51191833
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: IGNORE_EOF like in bash
2001-04-25 20:33 IGNORE_EOF like in bash Christoph Lange
@ 2001-04-26 3:49 ` Bart Schaefer
2001-04-26 9:07 ` Christoph Lange
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2001-04-26 3:49 UTC (permalink / raw)
To: Christoph Lange, zsh-users
On Apr 25, 10:33pm, Christoph Lange wrote:
} Subject: IGNORE_EOF like in bash
}
} [...] I found out that one can script it in zsh-4.0.1-pre-3 [...]
} since the shell no longer bypasses ZLE when ^D is pressed on an empty
} command line.
Almost correct: It doesn't bypass ZLE on ^D provided `setopt ignoreeof'.
} Here is my solution, configurable by the variable IGNOREEOF:
}
} IGNOREEOF=3 # or something like that
}
} bash-ctrl-d() {
} if [[ $CURSOR == 0 && -z $BUFFER ]]
} then
} [[ -z $IGNOREEOF || $IGNOREEOF == 0 ]] && exit
} [[ $LASTWIDGET == bash-ctrl-d ]] \
} && (( --__BASH_IGNORE_EOF == 0 )) \
} && exit
} : ${__BASH_IGNORE_EOF=$IGNOREEOF}
} zle send-break
} else
} zle delete-char-or-list
} fi
} }
With your function, IGNOREEOF=3 will require four ^D to exit, or two ^D
and then anything else, repeated four times (because it never starts
__BASH_IGNORE_EOF over at three after the first call to this function).
I think you want:
bash-ctrl-d() {
if [[ $CURSOR == 0 && -z $BUFFER ]]
then
[[ -z $IGNOREEOF || $IGNOREEOF == 0 ]] && exit
if [[ $LASTWIDGET == bash-ctrl-d ]]
then
(( --__BASH_IGNORE_EOF <= 0 )) && exit
else
(( __BASH_IGNORE_EOF = IGNOREEOF-1 ))
fi
zle send-break
else
zle delete-char-or-list
fi
}
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: IGNORE_EOF like in bash
2001-04-26 3:49 ` Bart Schaefer
@ 2001-04-26 9:07 ` Christoph Lange
0 siblings, 0 replies; 3+ messages in thread
From: Christoph Lange @ 2001-04-26 9:07 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
> With your function, IGNOREEOF=3 will require four ^D to exit, or two ^D
> and then anything else, repeated four times (because it never starts
> __BASH_IGNORE_EOF over at three after the first call to this function).
>
> I think you want:
>
> bash-ctrl-d() {
> if [[ $CURSOR == 0 && -z $BUFFER ]]
> then
> [[ -z $IGNOREEOF || $IGNOREEOF == 0 ]] && exit
> if [[ $LASTWIDGET == bash-ctrl-d ]]
> then
> (( --__BASH_IGNORE_EOF <= 0 )) && exit
> else
> (( __BASH_IGNORE_EOF = IGNOREEOF-1 ))
> fi
> zle send-break
> else
> zle delete-char-or-list
> fi
> }
Thanks for correcting my hack. However, __BASH_IGNORE_EOF should be
initialized with the value of IGNOREEOF for a bash-like
implementation. IGNOREEOF=3 in bash means that EOF is ignored three
times. Only the 4th EOF is not ignored and exits the shell.
Christoph
--
Computer, n.: A device designed to speed and automate errors
Christoph Lange, langec@gmx.de, http://www.cul.de/home/yaph/, ICQ #51191833
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-04-26 12:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-25 20:33 IGNORE_EOF like in bash Christoph Lange
2001-04-26 3:49 ` Bart Schaefer
2001-04-26 9:07 ` Christoph Lange
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).