F/lshell completion upgrade#283
Closed
amirimatin wants to merge 1 commit into
Closed
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
- add prefix history search on arrow keys and incremental Ctrl+R/Ctrl+S bindings - improve completion rendering with contextual headers, sorting, and deduplication - normalize and deduplicate persisted history entries through shared helpers - extend functional and regression coverage for completion and history behavior
4f55ebc to
bfb3dbe
Compare
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
This PR adds a safe,
lshell-owned set of interactive usability improvements inspired by commonzshworkflows, while keeping command completion, path visibility, and history behavior under existinglshellpolicy enforcement.The work is focused on three areas:
Main Changes
1. Prefix-based history navigation on
Up/DownInteractive history navigation now supports prefix search on the current input line.
Behavior:
echo aand pressesUp,lshellsearches backward through history for entries that start with that exact prefix.Upcontinues moving through older matching entries.Downmoves forward through the same filtered match set.Downagain, the original typed line is restored.Implementation details:
lshell/shellcmd.py.history-beginning-searchbehavior directly insidelshell.Key code references:
lshell/shellcmd.py:486-576test/test_session_interaction_functional.py:162-205test/test_history_size_unit.py:192-2342. Incremental history search with
Ctrl+RandCtrl+SInteractive history search now exposes standard readline incremental search bindings.
Behavior:
Ctrl+Rstarts reverse incremental history searchCtrl+Sstarts forward incremental history searchThis is wired through readline bindings only. The search operates on the shell history already managed by
lshell; it does not introduce any new execution path or external completion engine.Key code references:
lshell/shellcmd.py:29-34lshell/shellcmd.py:486-510test/test_history_size_unit.py:193-2203. Context-aware completion display
Completion output is now rendered with an
lshell-specific display hook instead of relying on the default raw readline listing.Behavior:
Allowed commandsAllowed sudo commandsAllowed directoriesAllowed pathsThis makes
Tab/Tab-Tabbehavior easier to review during interactive use, especially when the same completion path can return many entries.Key code references:
lshell/shellcmd.py:161-166lshell/shellcmd.py:578-617lshell/shellcmd.py:793-798test/test_completion.py:71-1454. Improved allowed-command completion matching
Allowed-command completion now performs a case-insensitive fallback when a case-sensitive prefix match returns nothing.
Behavior:
./tool.shThis improves interactive usability without expanding the completion source beyond the configured
allowedlist.Key code references:
lshell/completion.py:18-48test/test_parser_jobs_unit.py:303-3135. Centralized history normalization and persistence policies
History cleanup logic has been extracted into a dedicated helper module so interactive history state and persisted history follow the same rules.
New behavior:
historycommand now writes prepared history before reading it back for display, so on-screen history reflects the same cleanup rules as the saved history fileThis makes history behavior consistent across:
historyoutputKey code references:
lshell/history.py:1-105lshell/shellcmd.py:618-625lshell/shellcmd.py:711-712lshell/shellcmd.py:727-739lshell/builtincmd.py:107-1196. History safety fixes in interactive edge cases
While wiring the new history behavior, two important edge cases were fixed so history normalization only touches real user-entered readline input.
Fixes:
Ctrl+D/EOFexit no longer risks persisting the synthetic line value"EOF"into historycmdqueueentries are no longer treated as fresh interactive readline history and therefore are not normalized as if the user had typed themThese fixes keep history cleanup limited to genuine interactive input.
Key code references:
lshell/shellcmd.py:656-712test/test_history_size_unit.py:115-190test/test_session_interaction_functional.py:238-269Review Guide
The fastest review path is:
lshell/shellcmd.pylshell/history.pylshell/completion.pylshell/builtincmd.pyhistorycommand persistence consistencyTests
test/test_history_size_unit.pytest/test_session_interaction_functional.pytest/test_completion.pytest/test_command_execution.pytest/test_parser_jobs_unit.pyTest Coverage Added and Updated
Unit coverage
EOFand queued commandsFunctional coverage
Up/Downprefix-based history recallhistoryoutput after normalization and deduplicationCtrl+Dhistory persistence regression coverage~/...directory completionls ~/...file completionls -l ~/...argument-aware path completion./commandallowed-command completionInteractive test harness hardening
Interactive
pexpectsuites now sanitize inheritedLSHELL_ARGSandLPS1so spawnedlshellsessions behave deterministically across environments and review runs.Scope of Changed Files
lshell/shellcmd.pylshell/history.pylshell/completion.pylshell/builtincmd.pytest/test_history_size_unit.pytest/test_session_interaction_functional.pytest/test_completion.pytest/test_command_execution.pytest/test_parser_jobs_unit.py