From 52de48b60f103d5c74c5b093457f8a926178f844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 21 Jun 2021 14:47:09 +0200 Subject: Support special !cd command --- repl.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/repl.c b/repl.c index 1f439b1..8bd1354 100644 --- a/repl.c +++ b/repl.c @@ -1,11 +1,12 @@ +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include -#include +#include void handle_int() { /* handle ctrl-c */ printf("\n"); @@ -52,6 +53,11 @@ int main(int argc, char *argv[]) { int size = strlen(argv[argc-1]) + 1 + strlen(input) + 1; char *command = malloc(size); if (command == NULL) err(1, NULL); + if (strncmp(input, "!cd ", 4) == 0) { + if (chdir(input + 4) == -1) + warn(NULL); + goto next; + } if (input[0] == '!') snprintf(command, size, "%s", input + 1); else if (append) @@ -61,6 +67,7 @@ int main(int argc, char *argv[]) { system(command); +next: free(input); free(command); } -- cgit v1.2.3