Confirm `Ctrl-D` to exit with `y/n` prompt like iPython?

When using the REPL, is there a way to have an ipython-style confirmation when pressing Ctrl-D to exit? Currently Julia does this:

julia> Type ^D again to exit.


I’m not a fan of this because I think it’ll just train me to double-tap Ctrl-D, which can be destructive if using a Julia shell that’s not using my startup.jl (since it’ll exit the shell).

I’d much prefer ipython’s style:

In [1]:                                                                                                 
Do you really want to exit ([y]/n)? 

It is possible to get this in Julia?


It is very hard to type “CTRL-D” by accident.

You have to hold down the control key and hold down the D key at the same time. Do you regularly press ctrl-D by accident regularly?

1 Like

It’s certainly conceivable — it’s purely a REPL user-interface feature, so it wouldn’t be breaking. You could submit a PR to modify this code to implement it.

I’m not sure whether it would be accepted — I don’t have strong feelings either way myself — but it’s certainly a reasonable proposal.

Umm, that code seems to have already implemented the feature. There appears to be an option to turn it on somewhere.

I don’t follow you — that’s the code that prints Type ^D again to exit. I’m not seeing an option for Exit? ([y]/n) or similar?

What you can do already is to turn off (or on) the “ctrl-D twice” confirmation feature, so that typing ^D only once causes you to exit, via:

atreplinit() do repl
    repl.options.confirm_exit = false

in your ~/.julia/config/startup.jl file.

1 Like

Ah, I misread the thread.

Julia doesn’t do this by default, what version of Julia are you on?


You also misread this.

They want.

Do you really want to exit ([y]/n)? 

I was reading this

The issue isn’t that I’d accidentally press ctrl-D — I’d almost certainly ever press it intentionally — but rather that I’d have some old REPL session open in terminal that I hadn’t used in a while, I’d come across it and say “I don’t need this anymore, let me exit out” and then as soon as I did I’d say “oh shoot I did still want something from that REPL”. The confirmation prompt is to give me a chance to think twice.

Coming from Stata, I am so used to CTRL-D for executing lines of code that I have created a shortcut in VScode that does it. I exit Julia by accident every time I update my system and forget to setup my shortcuts. I would love this feature.

I think it’ll just train me to double-tap Ctrl-D, which can be destructive if using a Julia shell that’s not using my startup.jl

That might be an argument in favor of having the confirm_exit option on by default.
Also, you can also press Ctrl-D twice in ipython to exit, so I actually never press Ctrl-D followed by y<Enter>, because it’s less direct than double Ctrl-D. So having the option to type y doesn’t help me in avoiding risking quitting the shell.

I would be fine having the same UI as ipython (where double Crtl-D is a hidden option), but would be reluctant to remove the possibility to type Ctrl-D twice to exit.

Sure, I’d be fine with that

vim users might also relate. especially if you run the REPL inside terminal mode.