diff options
author | John Ankarström <john@ankarstrom.se> | 2021-06-21 14:47:09 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-06-21 14:47:09 +0200 |
commit | 52de48b60f103d5c74c5b093457f8a926178f844 (patch) | |
tree | 7b6afbb69aa3738df5c35f730d53541368748fbc | |
parent | 213d5d27adae538c594dc09c9974ff62797994d2 (diff) | |
download | repl-master.tar.gz |
-rw-r--r-- | repl.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -1,11 +1,12 @@ +#include <err.h> +#include <readline/history.h> +#include <readline/readline.h> +#include <signal.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> -#include <stdbool.h> -#include <signal.h> #include <string.h> -#include <err.h> -#include <readline/readline.h> -#include <readline/history.h> +#include <unistd.h> 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); } |