summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorczjstmax <jstmaxlol@disroot.org>2026-03-22 21:06:00 +0100
committerczjstmax <jstmaxlol@disroot.org>2026-03-22 21:06:00 +0100
commitdab9c9f247de874c153ceaebe21c0932792ebbb8 (patch)
tree4362e3333bc8c9fd26c2705f7ed702b83f1ca658
parent04241e4cf33094ceac836e7435f5cb5b64e401e6 (diff)
added fallback for empty `cd` -> goto `HOME`
Signed-off-by: czjstmax <jstmaxlol@disroot.org>
-rw-r--r--nm.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/nm.c b/nm.c
index 455fd0e..ffe2605 100644
--- a/nm.c
+++ b/nm.c
@@ -29,6 +29,9 @@ int main(void)
char *USER = getenv("USER");
if (!USER)
USER = "god";
+ char *HOME = getenv("HOME");
+ if (!HOME)
+ HOME = ".";
while (true) {
char prompt[strlen(USER) + strlen("$ ") + 1];
@@ -67,7 +70,8 @@ int main(void)
}
else if (strcmp(p.we_wordv[0], "cd") == 0) {
if (p.we_wordc <= 1) {
- printf("nsh+! cd: no arguments were given.\n");
+ if (chdir(HOME))
+ perror("nsh+! ERROR: cannot retrieve HOME, failed to change directory");
FreeAll();
continue;
}