From db2eca697e34b5a5fbea9cfd4f336ac946abb7f4 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 14 Aug 2023 14:55:23 +0300 Subject: [PATCH] Shell: '\u' in PS1 is replaced with username corresponding to euid --- userspace/Shell/main.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/userspace/Shell/main.cpp b/userspace/Shell/main.cpp index 95eba7beaf..cf43a84215 100644 --- a/userspace/Shell/main.cpp +++ b/userspace/Shell/main.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -469,6 +470,15 @@ BAN::String get_prompt() break; } + case 'u': + { + auto* passwd = getpwuid(geteuid()); + if (passwd == nullptr) + break; + MUST(prompt.append(passwd->pw_name)); + endpwent(); + break; + } case '\0': MUST(prompt.push_back('\\')); break; @@ -529,7 +539,7 @@ int main(int argc, char** argv) if (argc >= 1) setenv("SHELL", argv[0], true); - setenv("PS1", "\e[32muser@host\e[m:\e[34m\\~\e[m$ ", false); + setenv("PS1", "\e[32m\\u@host\e[m:\e[34m\\~\e[m$ ", false); tcgetattr(0, &old_termios);