From nobody Mon Jun 19 17:28:21 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QlGvB0SSNz4fWHT; Mon, 19 Jun 2023 17:28:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QlGv973KWz4LvH; Mon, 19 Jun 2023 17:28:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687195702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6nwhBf2945KrqanAdCyYT8HIjXIuGvQt9hxtqONRmdM=; b=Z+ws+sP82S2hlTPNvGV5XIsOJguEm0do7GuxdEfwJrZRJa7VRTo+pYMfPY6l1v7DYWBFxf rj2HNPWhCpq5c/ThLrXn61GcC5in/r9/4HEtHb/FcpwbqkVqPYpQA7nmZudozF7LxVqoRB At525Bi5PZ3laWWuS5TSF2z1sMqswhEE/J/F8jzqHtG+qgf19Sj02SPIwLvNY4RhWY9ZVy mXdYekq9Vv9TirgIQGLfIhnKn8a4iixuBanNmRdVSQouebtkWxoq/9uihPi96lDczogw7g EqC6y2P2Gd8YcukXb7ZZOsHIurgXTFptLUlXXvgdr4iamHd8AQwGgVmOLXdu0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687195702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6nwhBf2945KrqanAdCyYT8HIjXIuGvQt9hxtqONRmdM=; b=H6YorIiXwKF9Jzd7KN+fAth9z1AjZtVBgvHGth1UneB3EuTWs9Q5NnY4NpWHn+moUjwerM /Fj0jcudviXli+WftgYX0dputNR6PX5De9N8+VmCSZqSupEGnUJi5y/0bsv/CFi/d4Ah5U 2UZuxxNfc7ldFe0yBRhPNDT1mPKuPspapV2Hjw9D+S+vWY0wrtL/Gvj5bwD2hmAjdzpeIV /o83WTfy3E388Wv/WBrEoRckLIow2x4izbetHyBS/4jx8WkhkhTI4nDThd23iOF1cJls0M Wk1vuQJ5O0cWZKoslVQY1H/+jLsrwMk4X81wPpOE3MQ+rs0BHEmsuV6FwQSXMQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687195702; a=rsa-sha256; cv=none; b=jPHQ872fqkH7qnsVVDpxUjpNbKeZ6SelIhU37OdAIsU95KaGoOv0FZ2mmsz73U0cLrHs9G ThEItOo/8ohD1HZblF8CEmsigf/eT4zolTw9Waa+umHLgZ7aLEjqdf4wdE79fiwsmBce7A ei8g+bg1SBQ7M852v5n5/IFGhkNIRE63004NhY5sh9E833FzlFgJwKouICZ8MUSmWSdsvh EnHtLC126Mp0pKCtDy1rY7Q1uyKwEt2NH0OI5VmsF0FTFt7ToEifCrTzbRFaRXihI4Qv4R RnkaDOEonIhzH6STKFh/Jlky3COFUp+MSwPneLXf/pyMEI3DYHkl5Hk/eASCjg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QlGv95lhdzQnP; Mon, 19 Jun 2023 17:28:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 35JHSLXl065352; Mon, 19 Jun 2023 17:28:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35JHSLL5065351; Mon, 19 Jun 2023 17:28:21 GMT (envelope-from git) Date: Mon, 19 Jun 2023 17:28:21 GMT Message-Id: <202306191728.35JHSLL5065351@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Pawel Stefaniak Subject: git: 14dd001235f9 - main - sh: also auto-complete built-ins List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pstef X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 14dd001235f993f2c58d8ceddb5b0ac23db02367 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=14dd001235f993f2c58d8ceddb5b0ac23db02367 commit 14dd001235f993f2c58d8ceddb5b0ac23db02367 Author: Piotr Pawel Stefaniak AuthorDate: 2023-04-29 15:53:58 +0000 Commit: Piotr Pawel Stefaniak CommitDate: 2023-06-19 17:27:20 +0000 sh: also auto-complete built-ins Reported in a comment in PR 261728. Reported by: Oleg Reviewed by: jilles (previous version), bapt Differential Revision: https://reviews.freebsd.org/D39839 --- bin/sh/histedit.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c index 07a344ebd17b..e13f38548a40 100644 --- a/bin/sh/histedit.c +++ b/bin/sh/histedit.c @@ -594,6 +594,20 @@ comparator(const void *a, const void *b, void *thunk) *(char *const *)b + curpos)); } +static char +**add_match(char **matches, size_t i, size_t *size, char *match_copy) +{ + if (match_copy == NULL) + return (NULL); + matches[i] = match_copy; + if (i >= *size - 1) { + *size *= 2; + matches = reallocarray(matches, *size, sizeof(matches[0])); + } + + return (matches); +} + /* * This function is passed to libedit's fn_complete2(). The library will use * it instead of its standard function that finds matching files in current @@ -605,7 +619,7 @@ static char { char *free_path = NULL, *path; const char *dirname; - char **matches = NULL; + char **matches = NULL, **rmatches; size_t i = 0, size = 16, uniq; size_t curpos = end - start, lcstring = -1; @@ -631,7 +645,6 @@ static char } while ((entry = readdir(dir)) != NULL) { struct stat statb; - char **rmatches; if (strncmp(entry->d_name, text, curpos) != 0) continue; @@ -642,11 +655,8 @@ static char continue; } else if (entry->d_type != DT_REG) continue; - matches[++i] = strdup(entry->d_name); - if (i < size - 1) - continue; - size *= 2; - rmatches = reallocarray(matches, size, sizeof(matches[0])); + rmatches = add_match(matches, ++i, &size, + strdup(entry->d_name)); if (rmatches == NULL) { closedir(dir); goto out; @@ -655,6 +665,14 @@ static char } closedir(dir); } + for (const unsigned char *bp = builtincmd; *bp != 0; bp += 2 + bp[0]) { + if (curpos > bp[0] || memcmp(bp + 2, text, curpos) != 0) + continue; + rmatches = add_match(matches, ++i, &size, strndup(bp + 2, bp[0])); + if (rmatches == NULL) + goto out; + matches = rmatches; + } out: free(free_path); if (i == 0) {