From 2a82c983c997dc322d704adeb4c20a8dd28fa346 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 30 May 2019 14:31:34 -0500 Subject: [PATCH] Improve bash history handling https://sanctum.geek.nz/arabesque/better-bash-history/ --- shell/bash/bashrc | 17 +++++++++++++++-- shell/bash/prompt | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/shell/bash/bashrc b/shell/bash/bashrc index 398432f..5eb989b 100644 --- a/shell/bash/bashrc +++ b/shell/bash/bashrc @@ -58,6 +58,9 @@ source "$DOTFILES_PATH/shell/bash/prompt" # instead places them in the readline for editing shopt -s histverify +# always _append_ to bash history +shopt -s histappend + # prevents some Java GUI apps from not working or rendering properly due to # using wacky window managers export _JAVA_AWT_WM_NONREPARENTING=1 @@ -81,8 +84,18 @@ export TERMINAL="urxvtc" export BROWSER="firefox-developer-edition" -# unlimited history -export HISTSIZE="" +# "unlimited" history +export HISTFILESIZE="10000000" +export HISTSIZE="10000000" + +# ignore duplicates and commands starting with space (" ") +export HISTCONTROL=ignoreboth + +# ignore certain commands +HISTIGNORE='ls:ll:la' + +# ensure command history is comprised of single lines +shopt -s cmdhist # load a per-device config last so anything can be overridden if [ -a "$HOME/.env_bashrc" ]; then diff --git a/shell/bash/prompt b/shell/bash/prompt index af44860..6123afe 100644 --- a/shell/bash/prompt +++ b/shell/bash/prompt @@ -27,6 +27,8 @@ export -f "preprocess_pwd" prompt_command_func() { + # commit history to prevent data loss from edge cases + history -a RET=$? # set the color of the user and host based on the result of the previous # command