From cf89251fbe22d219d16882cabf2d68c97181c537 Mon Sep 17 00:00:00 2001 From: Zane McCaig Date: Sat, 27 May 2023 18:17:26 -0700 Subject: [PATCH] Add a doc describing how to add custom suggestion strategies. This was very hard to figure out without guidance. --- How-to-Add-Custom-Suggestion-Strategy.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 How-to-Add-Custom-Suggestion-Strategy.md diff --git a/How-to-Add-Custom-Suggestion-Strategy.md b/How-to-Add-Custom-Suggestion-Strategy.md new file mode 100644 index 0000000..36a49ab --- /dev/null +++ b/How-to-Add-Custom-Suggestion-Strategy.md @@ -0,0 +1,16 @@ +## Adding a Custom Suggestion Strategy + +1. Add a `_zsh_autosuggest_strategy_` function to your `.zshrc`. It must set the global variable `suggestion` +2. Export the `ZSH_AUTOSUGGEST_STRATEGY` + +#### Example +This example applies the history strategy first and if it fails to find a match then it applies the custom strategy + +``` +_zsh_autosuggest_strategy_custom() { + typeset -g suggestion + suggestion=`./my-custom-suggestion-script.sh "$1"` +} + +export ZSH_AUTOSUGGEST_STRATEGY=(history custom) +``` \ No newline at end of file