Skip to content

Commit c39e93f

Browse files
committed
fix(spec): harden bash completion mock for non-tty runs
The mock never had a real terminal to fall back to, so two latent bash-completion quirks surfaced as test failures: - Interactive bash expanded `!` in `_filedir`'s xspec, breaking the extension filter for `apply --file ...`. - An unset `COLUMNS` collapsed `__cli1_format_comp_descriptions` into bare names, so `-e dev ""` lost its description columns. Disable history expansion, default `COLUMNS` to a wide value, and patch `_filedir` to handle the empty-`cur` case the way real bash does via `complete -o default`.
1 parent 3e876ae commit c39e93f

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/tabular/shell/bash.ecr

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
1+
# History expansion turns the `!` in `_filedir`'s xspec into a syntax error and
2+
# leaves descriptions unformatted when `COLUMNS` is unset, so harden both up
3+
# front before any completion machinery is loaded.
4+
set +H
5+
export COLUMNS="${COLUMNS:-200}"
6+
17
<% {% if flag?(:darwin) %} -%>
28
init="/opt/homebrew/etc/profile.d/bash_completion.sh"
39
<% {% end %} -%>
410
<% {% if flag?(:linux) %} -%>
511
init="/etc/profile.d/bash_completion.sh"
612
<%- {% end %} -%>
713
[[ -f "${init}" ]] && . "${init}"
14+
15+
# Patch `_filedir` so an empty `cur` still expands extension filters. Stock
16+
# bash-completion routes empty cur through `_quote_readline_by_ref`, which
17+
# yields the literal `''` and then matches no files; real bash papers over
18+
# this with `complete -o default`, but the mock has no shell to fall back to.
19+
if declare -F _filedir >/dev/null 2>&1; then
20+
eval "__tabular_orig_filedir() $(declare -f _filedir | tail -n +2)"
21+
_filedir() {
22+
if [[ -z ${cur-} && -n ${1-} && ${1-} != "-d" ]]; then
23+
local __xspec="!*.@(${1}|${1^^})"
24+
local __reset
25+
__reset=$(shopt -po noglob)
26+
set -o noglob
27+
COMPREPLY+=( $(compgen -f -X "$__xspec" -o plusdirs -- "") )
28+
$__reset
29+
(( ${#COMPREPLY[@]} > 0 )) && compopt -o filenames 2>/dev/null
30+
return 0
31+
fi
32+
__tabular_orig_filedir "$@"
33+
}
34+
fi
35+
836
<% completers.each do |comp| -%>
937
eval "$(<%= comp %> completion <%= bin %>)"
1038
<% end %>

0 commit comments

Comments
 (0)