Commit c0c36c5
committed
fix(_comp_initialize): complete inside $() command substitutions
Since bash 4.3, $(cmd args is treated as a single opaque word in
COMP_WORDS, so the outer command's completion function produces nothing.
Installing bash-completion makes it worse than bare readline (which
still does filename completion).
Detect when cur starts with $( in _comp_initialize, rewrite COMP_LINE /
COMP_POINT / COMP_WORDS / COMP_CWORD to describe the command line
inside the substitution, and dispatch to the inner command's completion
function via _comp_command_offset 0.
Handle nested substitutions (e.g. echo $(git describe $(ls <TAB>) by
looping: after parsing inner_line into words, scan for any word with an
unclosed $( (more $( than ) counts) and re-enter the loop from that
word onward, stripping one $( per iteration until the innermost level
is reached.
Integration tests register a simple completion function (csub_cmd) and
use assert_complete to send real keystrokes through the full pipeline:
- Single-level: echo $(csub_cmd <TAB> matches bare csub_cmd <TAB>
- Single-level partial: echo $(csub_cmd a<TAB> filters by prefix
- Nested: echo $(echo foo $(csub_cmd <TAB> dispatches through nesting
- Nested partial: echo $(echo foo $(csub_cmd b<TAB> filters in nesting
- Closed-then-open: echo $(echo hi) $(csub_cmd <TAB> skips closed $()
- Regression: csub_cmd <TAB> without $( still works
Closes #6301 parent 5bba93c commit c0c36c5
File tree
2 files changed
+106
-0
lines changed- test/t/unit
2 files changed
+106
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1626 | 1626 | | |
1627 | 1627 | | |
1628 | 1628 | | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
1629 | 1690 | | |
1630 | 1691 | | |
1631 | 1692 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
0 commit comments