From 8e5c53af831bd180af0c59f2d96c67ab9da59590 Mon Sep 17 00:00:00 2001 From: Piotr Pawel Stefaniak Date: Sun, 30 Apr 2023 18:31:52 +0200 Subject: [PATCH] sh: also auto-complete functions Differential Revision: https://reviews.freebsd.org/D40619 --- bin/sh/histedit.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c index 0d40e1c9ec1a..842c166159bc 100644 --- a/bin/sh/histedit.c +++ b/bin/sh/histedit.c @@ -51,6 +51,7 @@ static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95"; * Editline and history functions (and glue). */ #include "alias.h" +#include "exec.h" #include "shell.h" #include "parser.h" #include "var.h" @@ -621,6 +622,7 @@ static char char **matches = NULL, **rmatches; size_t i = 0, size = 16, uniq; size_t curpos = end - start, lcstring = -1; + struct cmdentry e; in_command_completion = false; if (start > 0 || memchr("/.~", text[0], 3) != NULL) @@ -680,6 +682,16 @@ static char goto out; matches = rmatches; } + for (const void *a = NULL; (a = itercmd(a, &e)) != NULL;) { + if (e.cmdtype != CMDFUNCTION) + continue; + if (strncmp(e.cmdname, text, curpos) != 0) + continue; + rmatches = add_match(matches, ++i, &size, strdup(e.cmdname)); + if (rmatches == NULL) + goto out; + matches = rmatches; + } out: free(free_path); if (i == 0) {