From aa8a1c6d72f1c6ef1564d64fbd5101cefdbd8c21 Mon Sep 17 00:00:00 2001 From: Carl Kittelberger Date: Wed, 30 Sep 2020 10:20:20 +0200 Subject: [PATCH] Set defaults for preserving zsh history. --- home/dotfiles/zshrc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/home/dotfiles/zshrc b/home/dotfiles/zshrc index 3aea8c8..6a1c573 100644 --- a/home/dotfiles/zshrc +++ b/home/dotfiles/zshrc @@ -23,6 +23,8 @@ ZSH_GPG_PINENTRY_FIX=${ZSH_GPG_PINENTRY_FIX:-1} ZSH_LOGO_LS=${ZSH_LOGL_LS:-$(when_binary_available logo-ls)} ZSH_PIPX=${ZSH_PIPX:-$(when_binary_available pipx)} ZSH_POWERLINE="${ZSH_POWERLINE:-1}" +ZSH_PRESERVE_HISTORY="${ZSH_PRESERVE_HISTORY:-1}" +ZSH_PRESERVE_HISTORY_IMMEDIATELY="${ZSH_PRESERVE_HISTORY_IMMEDIATELY:-1}" ZSH_PRINT_REBOOT_REQUIRED=${ZSH_PRINT_REBOOT_REQUIRED:-0} # hacky, see below ZSH_SYNTAX_HIGHLIGHTING="${ZSH_SYNTAX_HIGHLIGHTING:-1}" ZSH_THEFUCK=${ZSH_THEFUCK:-1} @@ -267,6 +269,22 @@ if [ $ZSH_PRINT_REBOOT_REQUIRED -gt 0 ]; then fi section_end +# Preserving zsh history +section "preserve zsh history" +if [ $ZSH_PRESERVE_HISTORY -gt 0 ]; then + : "${HISTFILE:=${HOME}/.zsh_history}" + : "${HISTSIZE:=10000}" + : "${SAVEHIST:=1000}" + if [ $ZSH_PRESERVE_HISTORY_IMMEDIATELY -gt 0 ]; then + # import new commands from the history file and also append typed commands to the history file immediately + setopt SHARE_HISTORY + else + # the history entry is written out to the file after the command is finished, so that the time taken by the command is recorded correctly in the history file in EXTENDED_HISTORY format + setopt INC_APPEND_HISTORY_TIME + fi +fi +section_end + # print env section "Environment variables" log "$(export)"