From 967c7daef5c4259ff0a79e91a758db335872c25e Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 25 Jul 2025 16:11:19 -0400 Subject: usr: osh: Add "!!" to repeat last command Introduce a mechanism to repeat the last command using the "!!" shorthand. Signed-off-by: Ian Moffett --- usr.bin/osh/osh.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'usr.bin') 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; -- cgit v1.2.3