diff --git a/apps/src/sh.c b/apps/src/sh.c index e212b29c..18f5198c 100644 --- a/apps/src/sh.c +++ b/apps/src/sh.c @@ -1,6 +1,7 @@ #include <assert.h> #include <errno.h> #include <luna.h> +#include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -8,6 +9,7 @@ #include <unistd.h> static int status = 0; +static char* username = NULL; typedef struct { @@ -76,9 +78,19 @@ void shell_execvp(char* pathname, char* const argv[]) void show_prompt() { - if (WEXITSTATUS(status)) { printf("%d [%ld]> ", WEXITSTATUS(status), getpid()); } + if (!username) + { + struct passwd* user = getpwuid(getuid()); + if (!user) + { + if (errno) perror("getpwuid"); + username = "??"; + } + else { username = user->pw_name; } + } + if (WEXITSTATUS(status)) { printf("%d [%s]> ", WEXITSTATUS(status), username); } else - printf("[%ld]> ", getpid()); + printf("[%s]> ", username); } int command_matches(command* cmd, const char* string)