Skip to content

system/readline: fill in a single match on an empty prefix - #4097

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Junbo-Zheng:nsh
Nov 21, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Junbo-Zheng:nsh

Conversation

@Junbo-Zheng

Copy link
Copy Markdown
Contributor

Summary

Path completion (added by "system/readline: add path completion for
command arguments") only filled in the sole matching entry when at
least one character of the word had been typed. Pressing TAB on an
empty word in a directory with exactly one candidate -- the common
"cd " into a directory that holds a single subdirectory -- always
took the multiple-match branch and printed the candidate as a list
instead of completing the line, even though there was nothing to
choose between.

Fill in a single match right away, regardless of the typed prefix. A
file completion ends in a space, which leaves the word empty again, so
a repeated TAB would match the same file and append it once more; to
keep that from piling up copies, a fill on an empty prefix is skipped
when the previous word on the line already holds the match. Directory
completions end in '/', so the next TAB descends into the directory
and is unaffected.

Impact

  • Users: TAB on an empty word now completes directly when the
    directory holds a single matching entry, instead of listing it.
  • Build: None.
  • Hardware: None.
  • Documentation: None.
  • Security & Compatibility: None.

Testing

Built and verified on the sim host target:

cmake -B build -DBOARD_CONFIG=sim:nsh -G Ninja
cmake --build build -j
printf 'mkdir /t6\ncd /t6\nmkdir aa\nmkdir ab\necho hi > only.txt\nls \t\nls a\t\nls aa\t\nls onl\t\nls onl\t\t\ncd \t\ncd \t\npoweroff\n' | ./build/nuttx

NSH session (lines with a leading prompt echo the filled buffer, i.e. what TAB inserted):

nsh> ls            <TAB>  -> lists aa, ab, only.txt (multiple matches)
nsh> ls a          <TAB>  -> lists aa, ab (common prefix already typed)
nsh> ls aa         <TAB>  -> fills in "ls aa/"
nsh> ls onl        <TAB>  -> fills in "ls only.txt "
nsh> ls onl        <TAB><TAB> -> second TAB adds nothing
nsh> cd            <TAB>  -> fills in "cd aa/"
nsh> cd            <TAB>  -> in aa/ (empty): no match, no action

Signed-off-by: Junbo Zheng zhengjunbo1@xiaomi.com

@Junbo-Zheng

Copy link
Copy Markdown
Contributor Author

The Linux (arm-other) failure is unrelated to this change — it's a defconfig normalization failure in qemu-armv8r-aarch32/nsh, which lives in the nuttx repo and was unnormalized when added (apache/nuttx@6e8eadd6b).

Already fixed on nuttx master (apache/nuttx@20a363b94)

@cederom

cederom commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

failed jobs restarted :-)

@GUIDINGLI

Copy link
Copy Markdown
Contributor

Please rebase your patch

Path completion only filled in the sole matching entry when at least
one character of the word was typed, so "cd <TAB>" in a directory
holding a single subdirectory printed the candidate as a list instead
of completing the line. Fill in the match right away, and make a
repeated TAB right after such a fill a no-op when the word is empty
and the previous word already holds the match.

Testing:

- Built with cmake -B build -DBOARD_CONFIG=sim:nsh and
  cmake --build build -j, then ran ./build/nuttx.
- In an NSH directory holding one file (only.txt) and one
  subdirectory (sub/):

    nsh> ls <TAB>        fills in "ls only.txt "
    nsh> cd <TAB>        fills in "cd sub/"
    nsh> ls <TAB><TAB>   fills once, the second TAB adds nothing
    nsh> ls onl<TAB>     prefix fills still work as before

- With several matching candidates, "ls a<TAB>" still lists them.

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
@Junbo-Zheng

Copy link
Copy Markdown
Contributor Author

Please rebase your patch

done

@Junbo-Zheng

Copy link
Copy Markdown
Contributor Author

The latest CI run still fails, but the failure is unrelated to this PR.

It is caused by a git.sr.ht (sourcehut) outage: the raspberrypi-4b/nxdoom
build in Linux (arm64-01) fails while cloning the external rtttl-c dependency:

  fatal: unable to access 'https://git.sr.ht/~qeef/rtttl-c/': The requested URL returned error: 503
  make[3]: *** [Makefile:34: rtttl-c] Error 128

Log: https://github.com/apache/nuttx-apps/actions/runs/44862609825/job/136719692506

@xiaoxiang781216
xiaoxiang781216 merged commit d02fadc into apache:master Nov 21, 2026
24 of 41 checks passed
@Junbo-Zheng
Junbo-Zheng deleted the nsh branch November 21, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants