]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
con: support tab completed directory paths for: ls, dir
authorbones_was_here <bones_was_here@xonotic.au>
Tue, 13 Aug 2024 04:25:36 +0000 (14:25 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Thu, 12 Sep 2024 15:23:10 +0000 (01:23 +1000)
If the search pattern ends in / the directory contents are listed (as if
the pattern had ended in /*).

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
fs.c

diff --git a/fs.c b/fs.c
index 2ce128e86cf61fda5e11f477381bb469a4d26f34..8f6384aa34be0d23edc76917e0f302b23e3835a9 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -3977,6 +3977,18 @@ static int FS_ListDirectory(const char *pattern, int oneperline)
        const char *name;
        char linebuf[MAX_INPUTLINE];
        fssearch_t *search;
+
+       // if the directory path ends in '/' then list its contents
+       // so commands behave as expected and directory tab completion is convenient
+       l = strlen(pattern);
+       if (pattern[l - 1] == '/' && l < (int)sizeof(linebuf) - 1)
+       {
+               memcpy(linebuf, pattern, l);
+               linebuf[l] = '*';
+               linebuf[l + 1] = '\0';
+               pattern = linebuf;
+       }
+
        search = FS_Search(pattern, true, true, NULL);
        if (!search)
                return 0;