From 52c19136f2f3f9777783eb11111f2cc4b9843acd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 28 Oct 2018 01:08:01 +0200 Subject: [PATCH] Give the shell a nice, colorful prompt. The cwd looks like crap, I need to write some code to strip out ".." and extra slashes from the path string. --- Userland/sh.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/sh.cpp b/Userland/sh.cpp index 7fb929dfdc..faed58e715 100644 --- a/Userland/sh.cpp +++ b/Userland/sh.cpp @@ -6,13 +6,14 @@ #include char* g_cwd = nullptr; +char g_hostname[32]; static void prompt() { if (getuid() == 0) printf("# "); else - printf("$ "); + printf("\033[32;1m%s\033[0m:\033[34;1m%s\033[0m$> ", g_hostname, g_cwd); } static int sh_pwd(int, const char**) @@ -114,6 +115,10 @@ static int runcmd(char* cmd) int main(int, char**) { + int rc = gethostname(g_hostname, sizeof(g_hostname)); + if (rc < 0) + perror("gethostname"); + char linebuf[128]; int linedx = 0; linebuf[0] = '\0';