Skip to content

Instantly share code, notes, and snippets.

@cfstras
Last active July 3, 2019 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfstras/8824f4337c6f7d79dbb3fa3708645b0d to your computer and use it in GitHub Desktop.
Save cfstras/8824f4337c6f7d79dbb3fa3708645b0d to your computer and use it in GitHub Desktop.
Bash configuration for better history archive
# first, install fzf
# https://github.com/junegunn/fzf
# Windows:
# choco install fzf
# Arch:
# sudo pacman -S fzf
# Mac:
# brew install fzf
# $(brew --prefix)/opt/fzf/install
# use this block with fzf
HISTCONTROL="ignoredups"
unset HISTFILESIZE
PROMPT_COMMAND='history -a'
#####################
# use this block to create one history file per shell (harder to search, but better archival) -- doesn't work with fzf
HOSTNAME="$(hostname)"
HOSTNAME_SHORT="${HOSTNAME%%.*}"
HISTCONTROL="ignoredups"
unset HISTFILESIZE
HISTFILE="${HOME}/.history/$(date -u +%Y/%m/%d.%H.%M.%S)_${HOSTNAME_SHORT}_$$"
PROMPT_COMMAND='mkdir -p $(dirname "${HISTFILE}")&&history -a'
#FZF_CTRL_R_OPTS=
hag ()
{
find ~/.history/ -type f | sort | xargs -d "\n" ag "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment