diff options
| author | czjstmax <jstmaxlol@disroot.org> | 2026-03-22 21:06:00 +0100 |
|---|---|---|
| committer | czjstmax <jstmaxlol@disroot.org> | 2026-03-22 21:06:00 +0100 |
| commit | dab9c9f247de874c153ceaebe21c0932792ebbb8 (patch) | |
| tree | 4362e3333bc8c9fd26c2705f7ed702b83f1ca658 | |
| parent | 04241e4cf33094ceac836e7435f5cb5b64e401e6 (diff) | |
added fallback for empty `cd` -> goto `HOME`
Signed-off-by: czjstmax <jstmaxlol@disroot.org>
| -rw-r--r-- | nm.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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; } |