Skip to content
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

Run automatically #1

Open
Myzel394 opened this issue Apr 7, 2024 · 0 comments
Open

Run automatically #1

Myzel394 opened this issue Apr 7, 2024 · 0 comments

Comments

@Myzel394
Copy link
Owner

Myzel394 commented Apr 7, 2024

So I tried to let copilot run automatically, but wasn't successful to do so. I used the TRAPALRM function with TMOUT to run a function every few seconds to detect whether the user finished typing. While this worked, showing suggestions or changing the BUFFER does not seem to be allowed by zsh. I tried calling the widget to let it handle the situation, but was unable to find a solution.

If someone knows a way how to do this, I'd be happy about PRs.

Here's the code I used:

# Global variables
local last_input_hash=""
# This is the hash to which the last suggestion happened against. This is used to prevent multiple suggestions for the same input
local last_suggested_input_hash=""

TMOUT=2
TRAPALRM() {
    if [[ "$BUFFER" == "" ]]; then
        last_input_hash=""
        return
    fi

    # content plus length
    local hash=$(echo "$BUFFER-${#BUFFER}")

    if [[ "$hash" == "$last_suggested_input_hash" ]]; then
        return
    fi


    if [[ "$hash" != "$last_input_hash" ]]; then
        # User is still typing
        last_input_hash="$hash"
    else
        if [[ $is_suggesting == 'false' ]]; then
            _suggest_ai
            last_suggested_input_hash="$hash"
        fi
    fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant