sh: Show last command' exit status in prompt if non-zero
This commit is contained in:
parent
cd9ecc1746
commit
de167c3c67
@ -5,7 +5,7 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static int status;
|
static int status = 0;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -16,6 +16,8 @@ typedef struct
|
|||||||
|
|
||||||
void show_prompt()
|
void show_prompt()
|
||||||
{
|
{
|
||||||
|
if (status) { printf("%d [%ld]> ", WEXITSTATUS(status), getpid()); }
|
||||||
|
else
|
||||||
printf("[%ld]> ", getpid());
|
printf("[%ld]> ", getpid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,8 +119,6 @@ void command_execute(command* cmd)
|
|||||||
}
|
}
|
||||||
int exit_status = WEXITSTATUS(status);
|
int exit_status = WEXITSTATUS(status);
|
||||||
if (exit_status == -2 || exit_status == -3) printf("(PID %ld) Segmentation fault\n", result);
|
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);
|
command_clear(cmd);
|
||||||
show_prompt();
|
show_prompt();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user