-
Notifications
You must be signed in to change notification settings - Fork 1
added optimized auto completion script #340
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
Open
sker65
wants to merge
3
commits into
main
Choose a base branch
from
optimized-auto-completion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| ###-begin-octomind-completion-### | ||
| # | ||
| # Octomind CLI - Fast Context-Aware Completion Script | ||
| # ==================================================== | ||
| # | ||
| # INSTALLATION: | ||
| # ------------- | ||
| # Replace the default tabtab-generated completion script with this optimized version: | ||
| # | ||
| # cp scripts/octomind.zsh ~/.config/tabtab/octomind.zsh | ||
| # | ||
| # Then reload your shell or source the file: | ||
| # | ||
| # source ~/.config/tabtab/octomind.zsh | ||
| # | ||
| # BENEFITS: | ||
| # --------- | ||
| # This completion script provides significant performance improvements over the standard | ||
| # tabtab-generated completion: | ||
| # | ||
| # 1. Context-Sensitive Caching: Completions are cached per test target and subcommand, | ||
| # providing instant results for repeated operations. Cache automatically refreshes | ||
| # after 1 minute in the background. | ||
| # | ||
| # 2. Intelligent Fallback: When no CLI-specific completions are available, automatically | ||
| # falls back to standard file completion, making it useful for file path arguments. | ||
| # | ||
| # 3. Faster Response Time: Initial completions are served from cache, eliminating the | ||
| # delay of spawning the CLI process on every tab press. | ||
| # | ||
| _fast_octomind_completion() { | ||
| local cli_path=$(command -v octomind) | ||
| [[ -z "$cli_path" ]] && return | ||
|
|
||
| local cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/octomind_cli_cache" | ||
| mkdir -p "$cache_dir" | ||
|
|
||
| local config_file="$HOME/.config/octomind.json" | ||
| local context_id="default" | ||
| [[ -f "$config_file" ]] && context_id=$(grep -o '"testTargetId": "[^"]*"' "$config_file" | cut -d'"' -f4) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the grep could yield empty or multiple, maybe we should safeguard? |
||
|
|
||
| local current_subcommand="${words[2]:-base}" | ||
| local cache_file="$cache_dir/cache_${context_id}_${current_subcommand}.txt" | ||
|
|
||
| local -a results | ||
| local si=$IFS | ||
| IFS=$'\n' | ||
|
|
||
| # 1. Attempt to get results (Cache or CLI) | ||
| if [[ -f "$cache_file" && -s "$cache_file" ]]; then | ||
| results=($(cat "$cache_file")) | ||
|
|
||
| if [[ -n $(find "$cache_file" -mmin +1 2>/dev/null) ]]; then | ||
| (COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" \ | ||
| "$cli_path" completion -- "${words[@]}" > "$cache_file" 2>/dev/null &) | ||
| fi | ||
| else | ||
| local raw_output | ||
| raw_output=$(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" \ | ||
| "$cli_path" completion -- "${words[@]}") | ||
|
|
||
| if [[ -n "$raw_output" ]]; then | ||
| echo "$raw_output" > "$cache_file" | ||
| results=(${(f)raw_output}) | ||
| fi | ||
| fi | ||
| IFS=$si | ||
|
|
||
| # 2. Logic Switch: CLI results vs. File Fallback | ||
| if (( ${#results} > 0 )); then | ||
| # We have CLI-specific strings, show them | ||
| _describe 'values' results | ||
| else | ||
| # No CLI results found? Fallback to standard Zsh file completion | ||
| _message "no matching commands; falling back to files" | ||
| _files | ||
| fi | ||
| } | ||
|
|
||
| if type compdef &>/dev/null; then | ||
| compdef _fast_octomind_completion octomind | ||
| fi | ||
| ###-end-octomind-completion-### | ||
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.
Uh oh!
There was an error while loading. Please reload this page.