Page MenuHomeFreeBSD

sh: auto-complete functions and aliases
ClosedPublic

Authored by pstef on Jun 20 2023, 8:36 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sep 23 2024, 10:12 PM
Unknown Object (File)
Sep 23 2024, 1:10 AM
Unknown Object (File)
Sep 19 2024, 11:00 PM
Unknown Object (File)
Sep 19 2024, 10:36 PM
Unknown Object (File)
Sep 19 2024, 3:47 AM
Unknown Object (File)
Sep 18 2024, 7:34 PM
Unknown Object (File)
Sep 16 2024, 12:20 PM
Unknown Object (File)
Sep 8 2024, 11:16 PM
Subscribers

Details

Summary

This differential combines 4 commits that I intend to commit separately:

sh: also auto-complete functions

sh: introduce a function to iterate over all hashed commands

While aliases and built-ins are opportunistically stored in cmdtable, each
function will be added to it immediately on definition.

Factor out the hashing function, write the iterator function and make it use
the hashing function.

Add the cmdname pointer to struct cmdentry so that the command name can be
exposed that way.

sh: tab-complete aliases

sh: introduce a function to iterate over all aliases

Currently the data structure holding alias information is opaque for
consumers outside alias.c and there is no way to iterate over all
aliases, which will become needed by a future commit.

The new function "iteralias" takes a null pointer to return the first
alias or an existing alias to return the next one, unless there is
no alias to return, in which case it returns a null pointer.

I slightly changed the static function hashalias so that it returns the
index into the array holding link heads, and not the link head directly.
In this form it's easier to use by iteralias and the slight adjustment
in the three existing callers doesn't look too bad.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

pstef requested review of this revision.Jun 20 2023, 8:36 AM
bin/sh/exec.c
600 ↗(On Diff #123474)

Style: this brace should be on its own line.

bin/sh/exec.h
77 ↗(On Diff #123474)

Please add these final newlines, as in other files.

bin/sh/histedit.c
680 ↗(On Diff #123474)

Aliases don't work if quoted, but I'm not sure whether we care here. The completion in zsh doesn't appear to.

Address comments from Jilles.

This revision was not accepted when it landed; it landed in state Needs Review.Sep 12 2023, 4:43 PM
This revision was automatically updated to reflect the committed changes.