Como ativar histórico local no ZSH por padrão

Com zsh, particularmente com oh-my-zsh, o histórico padrão é global, ou seja, compartilhado por todos os shells. Isso pode muitas vezes ser estranho se você está trabalhando com múltiplas sessões de terminal e espera que cada sessão tenha seu próprio histórico.

Para corrigir isso, adicione o seguinte ao seu arquivo ~/.zshrc:

enable_local_history_zsh.sh
# Local history - https://superuser.com/a/691603/285486

bindkey "${key[Up]}" up-line-or-local-history
bindkey "${key[Down]}" down-line-or-local-history

up-line-or-local-history() {
    zle set-local-history 1
    zle up-line-or-history
    zle set-local-history 0
}
zle -N up-line-or-local-history
down-line-or-local-history() {
    zle set-local-history 1
    zle down-line-or-history
    zle set-local-history 0
}
zle -N down-line-or-local-history

bindkey "^[[1;5A" up-line-or-history    # [CTRL] + Cursor up
bindkey "^[[1;5B" down-line-or-history  # [CTRL] + Cursor down

Check out similar posts by category: Linux