From 4261212913b3c453de2ffa55d864506f85a31cc0 Mon Sep 17 00:00:00 2001 From: Daniel Hammer Date: Tue, 16 Jun 2026 18:41:56 +0200 Subject: [PATCH] feat: add support for shell builtins to command completion --- kernel/src/Api/BuildNo.hpp | 2 +- programs/src/shell/main.cpp | 2 ++ programs/src/shell/shell.h | 15 +++++++++++++++ programs/src/shell/tabcompletion.cpp | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/kernel/src/Api/BuildNo.hpp b/kernel/src/Api/BuildNo.hpp index 958144b..3b58095 100644 --- a/kernel/src/Api/BuildNo.hpp +++ b/kernel/src/Api/BuildNo.hpp @@ -12,4 +12,4 @@ #pragma once -#define MONTAUK_BUILD_NUMBER 79 +#define MONTAUK_BUILD_NUMBER 82 diff --git a/programs/src/shell/main.cpp b/programs/src/shell/main.cpp index f27f346..9ad4348 100644 --- a/programs/src/shell/main.cpp +++ b/programs/src/shell/main.cpp @@ -436,6 +436,8 @@ extern "C" void _start() { if (ev.scancode == SC_TAB) { line[pos] = '\0'; + if (pos == 0) continue; + char* table[128] = { }; int n = get_completions(line, table, 128); diff --git a/programs/src/shell/shell.h b/programs/src/shell/shell.h index e457e61..b775065 100644 --- a/programs/src/shell/shell.h +++ b/programs/src/shell/shell.h @@ -130,3 +130,18 @@ int exec_external(const char* cmd, const char* args); // ---- Tab completion (tabcompletion.cpp) ---- int get_completions(char* string, char** array, int arrayMax); + +// ---- Shell builtins ---- + +constexpr const char* shell_builtins[] = { + "help", + "ls", + "cd", + "pwd", + "echo", + "set", + "unset", + "true", + "false", + "exit" +}; \ No newline at end of file diff --git a/programs/src/shell/tabcompletion.cpp b/programs/src/shell/tabcompletion.cpp index 8b220e3..9942d88 100644 --- a/programs/src/shell/tabcompletion.cpp +++ b/programs/src/shell/tabcompletion.cpp @@ -6,6 +6,7 @@ #include #include +#include "shell.h" #define RD_MAX 128 @@ -58,6 +59,7 @@ int get_completions( // returns no. of results int arrayMax ) { + // --- System commands (0:/os/*.elf) ---- const char* names[RD_MAX] = { }; int n = montauk::readdir("0:/os", names, RD_MAX); @@ -89,5 +91,19 @@ int get_completions( // returns no. of results } } + // ---- Shell builtins ---- + + size_t builtins_count = sizeof(shell_builtins) / sizeof(const char*); + + for (size_t i = 0; i < builtins_count; i++) { + if (montauk::starts_with(shell_builtins[i], (const char*)string)) { + if (r > arrayMax) + break; + + array[r] = (char *)shell_builtins[i]; + r++; + } + } + return r; }