sh: Show last command' exit status in prompt if non-zero

This commit is contained in:
apio 2022-10-20 08:21:18 +02:00
parent cd9ecc1746
commit de167c3c67

View File

@ -5,7 +5,7 @@
#include <sys/wait.h>
#include <unistd.h>
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();
}