fix: ensure tab completion is not reliant on single-digit volume number
This commit is contained in:
@@ -12,4 +12,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MONTAUK_BUILD_NUMBER 76
|
||||
#define MONTAUK_BUILD_NUMBER 79
|
||||
|
||||
@@ -26,6 +26,20 @@ bool is_executable(const char* path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int find_first_slash_pos(const char* string) {
|
||||
int i = 0;
|
||||
|
||||
while (string[i] != '\0') {
|
||||
if (string[i] == '/') {
|
||||
return i;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
i.e., "shell.elf" => "shell"
|
||||
*/
|
||||
@@ -51,19 +65,23 @@ int get_completions( // returns no. of results
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
/*
|
||||
Shift by 3 characters (names[i] + 3):
|
||||
Shift by n characters (names[i] + n),
|
||||
n = position of first slash in path + 1:
|
||||
|
||||
"os/shell.elf" => "shell.elf"
|
||||
|
||||
This is somewhat of a workaround.
|
||||
*/
|
||||
if (montauk::starts_with(names[i] + 3, (const char*)string)) {
|
||||
int inc = find_first_slash_pos(names[i]) + 1;
|
||||
|
||||
if (montauk::starts_with(names[i] + inc, (const char*)string)) {
|
||||
if (r > arrayMax)
|
||||
break;
|
||||
|
||||
if (!is_executable(names[i]))
|
||||
continue;
|
||||
|
||||
char* p = (char *)names[i] + 3;
|
||||
char* p = (char *)names[i] + inc;
|
||||
strip_elf_extension(p);
|
||||
|
||||
array[r] = (char *)p;
|
||||
|
||||
Reference in New Issue
Block a user