Comment activer l'historique local sur ZSH par défaut

Avec zsh, en particulier avec oh-my-zsh, l’historique par défaut est global, c’est-à-dire partagé par tous les shells. Cela peut souvent être déroutant si vous travaillez avec plusieurs sessions de terminal et vous attendez à ce que chaque session ait son propre historique.

Pour corriger cela, ajoutez ce qui suit à votre fichier ~/.zshrc :

enable_local_history_zsh.sh
# Historique local - 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] + Curseur haut
bindkey "^[[1;5B" down-line-or-history  # [CTRL] + Curseur bas

Consultez les articles similaires par catégorie : Linux