From 6eeb8861e78608564b1e2307abd89ecc95f4f751 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 4 Jan 2021 09:45:34 +0100 Subject: [PATCH] Add `exit` bind function Currently binding `exit` to a key checks too late that it's exitted, so it leaves the shell hanging around until the user does an execute or similar. As I understand it, the `exit` builtin is supposed to only exit the current "thread" (once that actually becomes a thing), and the bindings would probably run in a dedicated one, so the simplest solution here is to just add an `exit` bind function. Fixes #7604. --- doc_src/cmds/bind.rst | 2 ++ src/input.cpp | 1 + src/input_common.h | 1 + src/reader.cpp | 7 +++++++ 4 files changed, 11 insertions(+) diff --git a/doc_src/cmds/bind.rst b/doc_src/cmds/bind.rst index 4bb2096b7..4c5be95f7 100644 --- a/doc_src/cmds/bind.rst +++ b/doc_src/cmds/bind.rst @@ -126,6 +126,8 @@ The following special input functions are available: - ``execute``, run the current commandline +- ``exit``, exit the shell + - ``forward-bigword``, move one whitespace-delimited word to the right - ``forward-char``, move one character to the right diff --git a/src/input.cpp b/src/input.cpp index bcac349c5..cd3c22eba 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -152,6 +152,7 @@ static const input_function_metadata_t input_function_metadata[] = { {readline_cmd_t::func_or, L"or"}, {readline_cmd_t::expand_abbr, L"expand-abbr"}, {readline_cmd_t::delete_or_exit, L"delete-or-exit"}, + {readline_cmd_t::exit, L"exit"}, {readline_cmd_t::cancel_commandline, L"cancel-commandline"}, {readline_cmd_t::cancel, L"cancel"}, {readline_cmd_t::undo, L"undo"}, diff --git a/src/input_common.h b/src/input_common.h index 99c5041c9..09fe9dba6 100644 --- a/src/input_common.h +++ b/src/input_common.h @@ -75,6 +75,7 @@ enum class readline_cmd_t { func_or, expand_abbr, delete_or_exit, + exit, cancel_commandline, cancel, undo, diff --git a/src/reader.cpp b/src/reader.cpp index eb50ffcba..42e907d9a 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -3076,6 +3076,13 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat delete_char(); break; } + case rl::exit: { + // This is by definition a successful exit, override the status + parser().set_last_statuses(statuses_t::just(STATUS_CMD_OK)); + exit_loop_requested = true; + check_exit_loop_maybe_warning(this); + break; + } case rl::delete_or_exit: case rl::delete_char: { // Remove the current character in the character buffer and on the screen using