From 1b4f48b92c23a3bb17b131523eb93139fe988096 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 11 Apr 2023 22:45:33 +0200 Subject: [PATCH] sh: Display the working directory as part of the prompt --- apps/sh.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/sh.cpp b/apps/sh.cpp index b827bbff..09fcf06c 100644 --- a/apps/sh.cpp +++ b/apps/sh.cpp @@ -74,7 +74,17 @@ int main(int argc, char** argv) while (1) { - if (file == "-") fputs(getuid() == 0 ? "sh# " : "sh$ ", stdout); + if (file == "-") + { + char* cwd = getcwd(NULL, 0); + if (!cwd) + { + perror("getcwd"); + return 1; + } + printf("sh %s%c ", cwd, getuid() == 0 ? '#' : '$'); + free(cwd); + } char cmd[4096]; char* rc = fgets(cmd, sizeof(cmd), f);