fix: completion garbage and 500ms TAB delay#30
Merged
Conversation
Two issues reported on bash 3.2 macOS: 1. ANSI suffix in completions, e.g. "x/dotfile/diff^[[0m" Root cause: __xsh_help (xsh.sh:705) unconditionally piped through awk that wraps every line in \033[1m...\033[0m, regardless of whether stdout is a TTY. Pipe consumers — like the completer's awk $2 — got garbage. Fix: gate the formatter on [ -t 1 ]; pass through cat otherwise. This is the standard Unix-tools convention (don't emit escapes to non-TTY). Tested: piped output is clean, terminal output still bolded. 2. ~500ms delay on every TAB press Root cause: completer ran 'xsh list "*"' on every TAB, walking every loaded library directory. Fix: cache the LPUE list in a shell-global var (_XSH_COMPLETE_LPUE_CACHE), populated lazily on first need. Helper is called directly (not via $(...)) so the assignment lands in the caller's shell rather than a lost subshell. Empirical: cold 581ms → warm 1ms (500x). Cache survives until manual unset; documented refresh after xsh load/unload/update is: unset _XSH_COMPLETE_LPUE_CACHE The defensive ANSI-strip sed in the completer is kept even though it's a no-op once the xsh.sh fix lands, so the completer stays correct during mixed-version installs / upgrades. Behavior change (very low impact): tooling that grepped ANSI bold sequences from piped 'xsh help' output now sees plain text. The old behavior was a misfeature. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #30 +/- ##
============================================
+ Coverage 63.29% 89.78% +26.49%
============================================
Files 3 1 -2
Lines 790 666 -124
============================================
+ Hits 500 598 +98
+ Misses 290 68 -222 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add error/guard-branch tests to spec/xsh_func_spec.sh: null-argument paths, git-clone/git-force-update option and failure handling, lib-manager and lib-get-cfg-property errors, __xsh_help_self cache rebuild, scripts-type util import/exec/unimport, the init runtime decorator, load cleanup-on-link-failure, and environment guards. Library line coverage rises from ~76% to ~90%. Scope kcov --include-path to xsh.sh in .shellspec. install.sh and boot run as child bash processes that kcov's bash tracer cannot instrument, so they always reported 0% despite spec/install_spec.sh exercising them end-to-end; counting them understated real coverage. They remain integration-tested, not line-counted. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two bugs in 0.6.1's bash tab completion, reported on macOS bash 3.2:
1. ANSI garbage in completion list
Hitting
<TAB>afterxshshowed entries like:Root cause:
__xsh_help(xsh.sh:705) unconditionally piped through awk that wraps each line in\033[1m...\033[0m, regardless of whether stdout is a TTY. Any pipe consumer — including the completer'sawk '{print $2}'— got the garbage. The opening\033[1mwas eaten byawk $2, but the trailing\033[0mstayed attached to the last field.Fix: Gate the formatter on
[ -t 1 ]; pass throughcatotherwise. Standard Unix-tools convention — don't emit escapes to non-TTY.2. ~500ms TAB delay
The completer ran
xsh list '*'on every TAB press, walking every loaded library directory.Fix: Cache the LPUE list in a shell-global var
_XSH_COMPLETE_LPUE_CACHE, populated lazily on first need. Helper called directly (not via$(...)) so the assignment lands in the caller's shell. Cold 581ms → warm 1ms (500x speedup).Defensive belt-and-suspenders
The completer still has a
sedANSI-strip even though thexsh.shfix makes it unnecessary. Kept because:Behavior change (very low impact)
Any tooling that grepped ANSI bold codes from piped
xsh help/xsh listoutput now sees plain text. The old behavior was a misfeature — extremely unlikely to have real consumers.Cache refresh
Cache persists for the shell session. After
xsh load/unload/update, refresh with:unset _XSH_COMPLETE_LPUE_CACHEDocumented in the completer's comment. Auto-clearing from the dispatcher is a future improvement (would require touching
xsh.sh's__xsh_load/__xsh_unload/__xsh_update).Test plan
unset _XSH_COMPLETE_LPUE_CACHEinvalidates and next call is coldxsh list '*' | headproduces clean output (no ANSI)xsh help | headproduces clean output (no ANSI)xsh helpat terminal still boldedWhen call xsh helpetc. — verifies the non-TTY path matches existing assertions)🤖 Generated with Claude Code