2016-02-05 22:14:08 +00:00
|
|
|
|
2016-02-14 07:29:43 +00:00
|
|
|
#--------------------------------------------------------------------#
|
|
|
|
# Suggestion #
|
|
|
|
#--------------------------------------------------------------------#
|
2016-02-05 22:14:08 +00:00
|
|
|
|
|
|
|
# Get a suggestion from history that matches a given prefix
|
|
|
|
_zsh_autosuggest_suggestion() {
|
2016-02-25 01:35:17 +00:00
|
|
|
local prefix="$(_zsh_autosuggest_escape_command_prefix "$1")"
|
2016-02-05 22:14:08 +00:00
|
|
|
|
2016-02-16 17:30:34 +00:00
|
|
|
# Get all history items (reversed) that match pattern $prefix*
|
|
|
|
local history_matches
|
|
|
|
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
|
|
|
|
|
|
|
|
# Echo the first item that matches
|
2016-02-24 03:11:56 +00:00
|
|
|
echo -E "$history_matches[1]"
|
|
|
|
}
|
|
|
|
|
|
|
|
_zsh_autosuggest_escape_command_prefix() {
|
|
|
|
setopt localoptions EXTENDED_GLOB
|
|
|
|
|
|
|
|
# Escape special chars in the string (requires EXTENDED_GLOB)
|
|
|
|
echo -E "${1//(#m)[\\()\[\]|*?]/\\$MATCH}"
|
2016-02-05 22:14:08 +00:00
|
|
|
}
|