atuinsh / atuin

✨ Magical shell history
https://atuin.sh
MIT License
19k stars 527 forks source link

zsh-autosuggestions integration doesn't use `workspaces` setting #1618

Open Nemo157 opened 5 months ago

Nemo157 commented 5 months ago

I just noticed the zsh-autosuggestions integration, and was wondering why I was still getting global suggestions rather than workspace ones despite setting workspaces = true. I think it would be good to pass --cwd . so that it acts more like interactive searching.

Nemo157 commented 5 months ago

Maybe with two strategies, one with --cwd ., and the other without, so it will fallback to using atuin's global search instead of then going to zsh's history.

DeveloperC286 commented 5 months ago

Maybe with two strategies, one with --cwd ., and the other without, so it will fallback to using atuin's global search instead of then going to zsh's history.

This is what I added to my rc

# https://github.com/atuinsh/atuin/blob/8372abb6132e18767e55f87152cc3ac45bd0205b/atuin/src/shell/atuin.zsh#L18
_zsh_autosuggest_strategy_atuin() {
    suggestion=$(atuin search --cmd-only --limit 1 --filter-mode directory --search-mode prefix -- "$1" || atuin search --cmd-only --limit 1 --search-mode prefix -- "$1")
}
Nemo157 commented 4 months ago

Ah yeah, I should post what I did, using multiple strategies for the two cases:

# Add --cwd flag to have auto-workspace-detection active
_zsh_autosuggest_strategy_atuin_auto() {
    suggestion=$(atuin search --cwd . --cmd-only --limit 1 --search-mode prefix -- "$1")
}

_zsh_autosuggest_strategy_atuin_global() {
    suggestion=$(atuin search --cmd-only --limit 1 --search-mode prefix -- "$1")
}

ZSH_AUTOSUGGEST_STRATEGY=(atuin_auto atuin_global)