diff --git a/src/builtins/set.c b/src/builtins/set.c index 86a4a3d..19f0c6e 100644 --- a/src/builtins/set.c +++ b/src/builtins/set.c @@ -50,6 +50,12 @@ int special_case(ef_t *ef, char **args) static bool handle_special_variables(ef_t *ef, char **args, char *var, int i) { + if (strcmp(var, "ignoreof") == 0) { + ef->exec_ctx->ignoreof = true; + return true; + } + if (args[i] == nullptr) + return false; if (strcmp(var, "precmd") == 0) { ef->exec_ctx->precmd = strdup(args[i]); return true; @@ -87,6 +93,8 @@ int builtins_set(ef_t *ef, char **args) { char *var = nullptr; + if (args[1] != nullptr && handle_special_variables(ef, args, args[1], 2)) + return RETURN_SUCCESS; if (my_array_len(args) < 3) return special_case(ef, args); return handle_set(ef, args, var); diff --git a/src/builtins_handler.h b/src/builtins_handler.h index 5acb245..f8fa00d 100644 --- a/src/builtins_handler.h +++ b/src/builtins_handler.h @@ -30,6 +30,7 @@ typedef struct { size_t prompt_len; char *precmd; char *cwdcmd; + bool ignoreof; } exec_ctx_t; size_t update_command(char **buffer, diff --git a/src/repl/key_control.c b/src/repl/key_control.c index 8a04d98..ca6fe35 100644 --- a/src/repl/key_control.c +++ b/src/repl/key_control.c @@ -19,8 +19,10 @@ bool handle_key_ctrl_c(readline_helper_t *rh, exec_ctx_t *ec, buff_t *buff) return false; } -bool handle_key_ctrl_d(readline_helper_t *, exec_ctx_t *, buff_t *buff) +bool handle_key_ctrl_d(readline_helper_t *, exec_ctx_t *ec, buff_t *buff) { + if (ec->ignoreof) + return false; buff->sz = 0; return true; } diff --git a/src/shell.c b/src/shell.c index 5d04d8f..a2bafcb 100644 --- a/src/shell.c +++ b/src/shell.c @@ -82,6 +82,7 @@ int shell_loop(int is_a_tty, exec_ctx_t *exec_ctx) buff_t buff = { .str = nullptr, 0, .cap = 0 }; struct termios repl_settings; + U_DEBUG_CALL(debug_env_entries, exec_ctx->env); exec_ctx->isatty = is_a_tty; tcgetattr(STDIN_FILENO, &repl_settings); exec_ctx->saved_term_settings = repl_settings; @@ -152,12 +153,12 @@ int shell(opt_t *opt, char **env_ptr) local_t local = create_local(); exec_ctx_t exec_ctx = {.env = &env, .local = &local, .opt = opt, .read_fd = get_read_fd(opt), .history = &history, .precmd = nullptr, - .history_command = cmd_history, .alias = &alias, 0, .cwdcmd = nullptr}; + .history_command = cmd_history, .alias = &alias, 0, .cwdcmd = nullptr, + .ignoreof = false }; int shell_result; if (exec_ctx.read_fd == -1 || (int)error_in_init(&exec_ctx)) return RETURN_FAILURE; - U_DEBUG_CALL(debug_env_entries, &env); shell_result = shell_loop(isatty(exec_ctx.read_fd), &exec_ctx); if (opt->cmd == NULL && isatty(exec_ctx.read_fd)) { WRITE_CONST(STDOUT_FILENO, "exit\n");