From de167c3c67f7f65292e1f98cc66ed9a91051cf3c Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 20 Oct 2022 08:21:18 +0200 Subject: [PATCH] sh: Show last command' exit status in prompt if non-zero --- apps/src/sh.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/src/sh.c b/apps/src/sh.c index 89eb3d9f..a9fdc90c 100644 --- a/apps/src/sh.c +++ b/apps/src/sh.c @@ -5,7 +5,7 @@ #include #include -static int status; +static int status = 0; typedef struct { @@ -16,7 +16,9 @@ typedef struct void show_prompt() { - printf("[%ld]> ", getpid()); + if (status) { printf("%d [%ld]> ", WEXITSTATUS(status), getpid()); } + else + printf("[%ld]> ", getpid()); } int command_matches(command* cmd, const char* string) @@ -117,8 +119,6 @@ void command_execute(command* cmd) } int exit_status = WEXITSTATUS(status); if (exit_status == -2 || exit_status == -3) printf("(PID %ld) Segmentation fault\n", result); - else if (exit_status) - printf("Exited with code %d\n", WEXITSTATUS(status)); command_clear(cmd); show_prompt(); }