summaryrefslogtreecommitdiff
path: root/usr.bin/osh/osh.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-25 16:11:19 -0400
committerIan Moffett <ian@osmora.org>2025-07-25 16:11:19 -0400
commit967c7daef5c4259ff0a79e91a758db335872c25e (patch)
tree8af84df80c5a078e75ef560efe89f811527938fc /usr.bin/osh/osh.c
parent87f45183e415368e3a3e67c7a632269a0375cedc (diff)
usr: osh: Add "!!" to repeat last command
Introduce a mechanism to repeat the last command using the "!!" shorthand. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.bin/osh/osh.c')
-rw-r--r--usr.bin/osh/osh.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c
index 3b41747..545f95a 100644
--- a/usr.bin/osh/osh.c
+++ b/usr.bin/osh/osh.c
@@ -43,6 +43,9 @@
#define is_printable(C) ((C) >= 32 && (C) <= 126)
#define is_ascii(C) ((C) >= 0 && (C) <= 128)
+#define INPUT_SIZE 64
+
+#define REPEAT "!!"
#define COMMENT '@'
#define WELCOME \
":::::::::::::::::::::::::::::::::::::::\n" \
@@ -66,7 +69,8 @@
#define PROMPT "[%s::osmora]~ "
-static char buf[64];
+static char last_command[INPUT_SIZE];
+static char buf[INPUT_SIZE];
static int running;
static int bell_fd;
static bool bs_bell = true; /* Beep on backspace */
@@ -365,6 +369,18 @@ parse_line(char *input)
struct parse_state state = {0};
pid_t child;
+ /*
+ * If we are using the REPEAT shorthand,
+ * repeat the last command. We return -EAGAIN
+ * to indicate we did not parse a normal command
+ * so the repeat command isn't pushed into the last
+ * command buffer and we enter a recursive hell.
+ */
+ if (strcmp(input, REPEAT) == 0) {
+ parse_line(last_command);
+ return -EAGAIN;
+ }
+
/* Ensure the aux vector is zeored */
memset(argv, 0, sizeof(argv));
@@ -476,6 +492,7 @@ main(int argc, char **argv)
continue;
}
+ memcpy(last_command, buf, buf_i + 1);
buf[0] = '\0';
}
return 0;