zsh-users / zsh-autosuggestions

Fish-like autosuggestions for zsh
MIT License
30.95k stars 1.86k forks source link

How to make my source code customizations portable #569

Closed blueray453 closed 3 years ago

blueray453 commented 3 years ago

I have changed the source code in two places. From:

(( ! ${+ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS} )) && {
    typeset -ga ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS
    ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
        forward-word
        emacs-forward-word
        vi-forward-word
        vi-forward-word-end
        vi-forward-blank-word
        vi-forward-blank-word-end
        vi-find-next-char
        vi-find-next-char-skip
    )
}

(( ! ${+ZSH_AUTOSUGGEST_ACCEPT_WIDGETS} )) && {
    typeset -ga ZSH_AUTOSUGGEST_ACCEPT_WIDGETS
    ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
        forward-char
        end-of-line
        vi-forward-char
        vi-end-of-line
        vi-add-eol
    )
}

To:

(( ! ${+ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS} )) && {
    typeset -ga ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS
    ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
        forward-char
        end-of-line
        forward-word
        emacs-forward-word
        vi-forward-word
        vi-forward-word-end
        vi-forward-blank-word
        vi-forward-blank-word-end
        vi-find-next-char
        vi-find-next-char-skip
    )
}

(( ! ${+ZSH_AUTOSUGGEST_ACCEPT_WIDGETS} )) && {
    typeset -ga ZSH_AUTOSUGGEST_ACCEPT_WIDGETS
    ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
        vi-forward-char
        vi-end-of-line
        vi-add-eol
    )
}

Now my concern is that, every time I download updates, I have to remember to change these codes.

Is there any way I can put something in my .zshrc so that I do not have to touch the original source code. I mean, is there any way I can override any function or something so that my selected widgets accept the entire suggestion.

ericfreese commented 3 years ago

Yes put something like this in your .zshrc after zsh-autosuggestions is sourced.

To add a widget: ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS+=(forward-char)

To remove a widget: ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS:#forward-char})

blueray453 commented 3 years ago

Thank you very much.