Suggestions for cd generally suggest the most recent (or frequent?) cd ... command, which is often not valid in the current working directory. I think (but I'm not sure) that the Fish suggestions for cd are location-aware, which is handy.

ZSH_AUTOSUGGEST_STRATEGY gives more relevant cd suggestions in most cases.I think it's unlikely that this will be fixed for the history suggestion strategy, as it simply looks through your shell history for any entries that match the prefix. Zsh has no option to natively store the current working directory for each history entry, and I don't want to get this plugin into the business of trying to parse which words in history entries refer to directories/files and ensuring that those directories/files exist before offering the entry as a suggestion.
That being said, I have had pretty decent success using zsh-histdb to store current working directory alongside history entries and writing a custom suggestion strategy to suggest commands executed in the current directory before commands executed in other directories.
My .zshrc has this config:
ZSH_AUTOSUGGEST_USE_ASYNC=true
ZSH_AUTOSUGGEST_STRATEGY=(histdb history completion)
_zsh_autosuggest_strategy_histdb() {
typeset -g suggestion
suggestion=$(_histdb_query "
SELECT commands.argv
FROM history
LEFT JOIN commands ON history.command_id = commands.rowid
LEFT JOIN places ON history.place_id = places.rowid
WHERE
commands.argv LIKE '$(sql_escape $1)%' AND
places.dir = '$(sql_escape $PWD)'
GROUP BY commands.argv
ORDER BY history.start_time desc
LIMIT 1
")
}
The SQL query can be tweaked to get different behavior. There are more examples of SQL statements for suggestion strategies in that project's readme: https://github.com/larkery/zsh-histdb#integration-with-zsh-autosuggestions
There are currently some issues related to LIKE not being case-sensitive in SQLite, but it looks like I may be able to fix it with PRAGMA case_sensitive_like=ON;, though I haven't gotten the chance to look into it yet.
You may also be interested in https://github.com/ericfreese/zsh-prioritize-cwd-history and https://github.com/ericfreese/zsh-cwd-history, two plugins I wrote a while ago related to this issue. Though, I haven't maintained those in some time.
Most helpful comment
I think it's unlikely that this will be fixed for the
historysuggestion strategy, as it simply looks through your shell history for any entries that match the prefix. Zsh has no option to natively store the current working directory for each history entry, and I don't want to get this plugin into the business of trying to parse which words in history entries refer to directories/files and ensuring that those directories/files exist before offering the entry as a suggestion.That being said, I have had pretty decent success using zsh-histdb to store current working directory alongside history entries and writing a custom suggestion strategy to suggest commands executed in the current directory before commands executed in other directories.
My
.zshrchas this config:The SQL query can be tweaked to get different behavior. There are more examples of SQL statements for suggestion strategies in that project's readme: https://github.com/larkery/zsh-histdb#integration-with-zsh-autosuggestions
There are currently some issues related to
LIKEnot being case-sensitive in SQLite, but it looks like I may be able to fix it withPRAGMA case_sensitive_like=ON;, though I haven't gotten the chance to look into it yet.You may also be interested in https://github.com/ericfreese/zsh-prioritize-cwd-history and https://github.com/ericfreese/zsh-cwd-history, two plugins I wrote a while ago related to this issue. Though, I haven't maintained those in some time.