-
-
Notifications
You must be signed in to change notification settings - Fork 22
Enhanced ZSH suffix management & Script optimizations #1142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 16667954420Details
💛 - Coveralls |
|
I'll have a look at this, but handling the suffix internally has been rather intentional. |
|
Hello, I just pushed another change because I realized the ZSH snippet would call About prefix being handled internally: this PR does not really put this principle into question: only the application itself knows when suffices should trigger some sort of no-space behavior. The thing is, there are in fact many different types of no-space behavior, and the application code alone cannot devise nor tell ZSH how to remove the suffix. I've performed a bit of println-based benchmarking, and the added loop (Go code) for reclassifying values according to their suffix character class is negligible. As well, my last commit ensure ZSH does not have to perform many resource intensive operations. The result is very good: between others, slash management for files is handled just like ZSH handles them natively. Failing tests: the 5 failing tests might be because of the changes in the first 5-10 lines of the ZSH snippet (removal of using sed/xargs), so changing these lines like I did might not be much needed... |
This pull request introduces a significant enhancement to the Zsh completion engine, completely overhauling how completion suffixes are managed. The new system delegates suffix handling to Zsh's native completion facilities, providing a more robust, intuitive, and consistent user experience for suffixes like the default trailing space, directory slashes (
/), and other separators (,,:, etc.). This PR addresses the topic raised in issue #666.Key Changes
internal/shell/zsh/action.go):mydir/is separated into the core valuemydrand the suffix/.Zsh Snippet Deep Dive
The core of this enhancement lies in the complete rewrite of the completion processing loop within the Zsh snippet (
internal/shell/zsh/snippet.go). The script is now more efficient and uses idiomatic Zsh features.1. Efficient Data Parsing
The script now uses direct array initialization instead of multiple
readcommands, which is cleaner and more performant.2. Grouping Completions by Suffix
Completions received from the Go binary are first grouped in an associative array based on their suffix type. This allows us to apply different
compaddoptions to each group. A default value is used for completions with no suffix.3. Unified Group Display
To prevent
_describefrom creating a new visual group for each suffix type, a "first call" flag ensures the group title is only printed once.4. Nuanced Suffix Removal
The script uses a robust
if/elif/elsestructure to apply specific removal rules based on the suffix type, providing a highly intuitive user experience./,,, or:, the suffix is removed only if the user types another space.=), the suffix is kept if the user continues typing letters or numbers.Performance Refactor
The initial block of the Zsh script, which handles complex shell quoting, has been refactored for performance and clarity.
sedandxargswithin a series ofif/elifstatements. These have been removed.${words[1,-2]}) to manipulate the command-line words directly in memory, which is significantly faster than forking external processes.carapacebinary is no longer repeated. The correct input string is determined first and stored in a variable, leading to a single, clean invocation.