Skip to content

Instantly share code, notes, and snippets.

@ckabalan
Last active February 20, 2024 23:17
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save ckabalan/7d374ceea8c2d9dd237d763d385cf2aa to your computer and use it in GitHub Desktop.
Save ckabalan/7d374ceea8c2d9dd237d763d385cf2aa to your computer and use it in GitHub Desktop.
The Best Bash History Settings Ever
# /etc/profile.d/best_bash_history.sh
# Save 5,000 lines of history in memory
HISTSIZE=10000
# Save 2,000,000 lines of history to disk (will have to grep ~/.bash_history for full listing)
HISTFILESIZE=2000000
# Append to history instead of overwrite
shopt -s histappend
# Ignore redundant or space commands
HISTCONTROL=ignoreboth
# Ignore more
HISTIGNORE='ls:ll:ls -alh:pwd:clear:history'
# Set time format
HISTTIMEFORMAT='%F %T '
# Multiple commands on one line show up as a single line
shopt -s cmdhist
# Append new history lines, clear the history list, re-read the history list, print prompt.
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
@CaseOf
Copy link

CaseOf commented Jul 20, 2023

It could be worth testing if it’s an interactive bash shell before loading vars in profile.d with something like:

# Not bash?
[ -n "${BASH_VERSION:-}" ] || return 0

# Not an interactive shell?
[[ $- == *i* ]] || return 0

@dovwatbnh
Copy link

@CaseOf Why's it important to check for interactive shell?

@dovwatbnh
Copy link

I see bind gives some errors if it's not interactive

@CaseOf
Copy link

CaseOf commented Feb 20, 2024

I dont remember exactly but I think I did get an issue while trying to run a script in cron or something like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment