From f2703089da21898e9c3127615e98c1717c7ceeb5 Mon Sep 17 00:00:00 2001
From: dzwdz
Date: Mon, 8 Aug 2022 19:04:27 +0200
Subject: user/libc: cwd

---
 src/user/app/shell/builtins.c | 2 +-
 src/user/app/shell/shell.c    | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

(limited to 'src/user/app/shell')

diff --git a/src/user/app/shell/builtins.c b/src/user/app/shell/builtins.c
index 0f06482..efc427d 100644
--- a/src/user/app/shell/builtins.c
+++ b/src/user/app/shell/builtins.c
@@ -107,7 +107,7 @@ static void cmd_ls(int argc, char **argv) {
 	const size_t buflen = 4096;
 	char *buf = malloc(buflen);
 
-	DEFAULT_ARGV("/");
+	DEFAULT_ARGV(".");
 	for (int i = 1; i < argc; i++) {
 		char *path = (void*)argv[i];
 		int pathlen = strlen(path);
diff --git a/src/user/app/shell/shell.c b/src/user/app/shell/shell.c
index d96ef4c..0f97d7a 100644
--- a/src/user/app/shell/shell.c
+++ b/src/user/app/shell/shell.c
@@ -47,6 +47,11 @@ void run_args(int argc, char **argv, struct redir *redir) {
 			exit(1);
 		}
 		return;
+	} else if (!strcmp(argv[0], "cd")) {
+		if (chdir(argc > 1 ? argv[1] : "/") < 0)
+			eprintf("error");
+		// TODO strerror
+		return;
 	} else if (!strcmp(argv[0], "time")) {
 		uint64_t time = __rdtsc();
 		uint64_t div = 3000;
@@ -148,7 +153,7 @@ int main(int argc, char **argv) {
 
 	for (;;) {
 		if (f == stdin)
-			printf("$ ");
+			printf("%s $ ", getcwd(buf, sizeof buf));
 		if (!fgets(buf, 256, f))
 			return 0;
 		run(buf);
-- 
cgit v1.2.3