aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--repl.c17
1 files 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 <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);
}