annotate .zfun/zsh-autosuggestions/src/strategies/default.zsh @ 524:24f7a481d284

shell: cache openssl prefix from homebrew Turns out homebrew costs about 800ms to figure this out, experimentally. :(
author Augie Fackler <raf@durin42.com>
date Mon, 14 Nov 2022 10:40:29 -0500
parents e1ce8897030d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
1
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
2 #--------------------------------------------------------------------#
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
3 # History Suggestion Strategy #
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
4 #--------------------------------------------------------------------#
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
5 # Suggests the most recent history item that matches the given
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
6 # prefix.
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
7 #
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
8
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
9 _zsh_autosuggest_strategy_history() {
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
10 # Reset options to defaults and enable LOCAL_OPTIONS
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
11 emulate -L zsh
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 # Enable globbing flags so that we can use (#m)
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14 setopt EXTENDED_GLOB
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
15
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
16 # Escape backslashes and all of the glob operators so we can use
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
17 # this string as a pattern to search the $history associative array.
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
18 # - (#m) globbing flag enables setting references for match data
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
19 # TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
20 local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
21
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
22 # Get the history items that match
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
23 # - (r) subscript flag makes the pattern match on values
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
24 typeset -g suggestion="${history[(r)${prefix}*]}"
e1ce8897030d zsh: import df6f6f9ff41 of zsh-autosuggestions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
25 }