Skip to content

feat(api): expand_shell_words — the shell-expand-line expansion tail - #2426

Merged
caomengxuan666 merged 1 commit into
masterfrom
feat/expand-shell-words
Nov 1, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
feat/expand-shell-words

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Adds Session::expand_shell_words, the engine face the niubash M-C-e host widget (niubash#767) needs after its history/alias legs.

GNU shell_expand_line (bashline.c:2982) runs alias_expand, then expand_word over the whole line, then string_list. expand_word performs word splitting (subst.c word_list_split) but never filename globbing — subst.c is explicit: "filename globbing is NOT done for word or string expansion, just when the shell is expanding a command."

The new entry:

  • splits the line into shell words with quote information preserved (same splitter the alias/word paths use),
  • expands each through the existing engine expand_word,
  • field-splits unquoted results on IFS,
  • rejoins with single spaces.

Pinned against the bash 5.3.20 oracle (M-C-e then C-x C-e to dump the readline buffer):

  • VAR='a b'; echo $VAR → echo a b
  • VAR='a b'; echo "$VAR" → echo a b (quotes removed, spacing kept)
  • echo * → echo *
  • echo $'x\ty' → one field with the tab

Six unit tests added (expand_shell_words_tests).

The companion niubash change consumes this API; it should merge after this PR.

GNU shell_expand_line (bashline.c:2982) runs alias_expand, then
expand_word over the whole line, then string_list. expand_word
performs word splitting (subst.c word_list_split) but never filename
globbing ("globbing is *NOT* done for word or string expansion").

Add Session::expand_shell_words for the niubash M-C-e host widget
(niubash#767): quote-aware word split, engine expansion per word, IFS
field split for unquoted results, single-space rejoin. Pinned against
the bash 5.3.20 oracle: unquoted `a  b` -> `a b`, quoted stays
`a  b` with quotes removed, `*` stays literal, `$'x\ty'` stays one
field.
@caomengxuan666
caomengxuan666 merged commit c7f7dc9 into master Nov 1, 2026
13 checks passed
@caomengxuan666
caomengxuan666 deleted the feat/expand-shell-words branch November 1, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant