3 ms·
- For your 1st issue, you can setup bash to append commands rather than overwrite them. Here the part of my .bashrc about history: # append rather than overw
by tupolef 3y ago
- For your 1st issue, you can setup bash to append commands rather than overwrite them. Here the part of my .bashrc about history:
# append rather than overwrite
shopt -s histappend
# attempts to save all lines of a multiple-line command in the same history entry
shopt -s cmdhist
# with cmdhist, saved with embedded newlines rather than semicolon separators
shopt -s lithist
HISTCONTROL=ignoreboth
HISTSIZE=10000
HISTFILESIZE=20000
HISTTIMEFORMAT="%y/%m/%d %T "
HISTIGNORE="history:ls:l:pwd:exit:"
if [[ ${BASH_VERSION:0:1} -gt 5 || ${BASH_VERSION:0:1} -ge 5 && ${BASH_VERSION:2:1} -ge 1 ]]; then
PROMPT_COMMAND=("history -a" "history -c" "history -r")
else
PROMPT_COMMAND="history -a; history -c; history -r"
fi
- And about the 2nd issue, you should use fzf or skim (probably faster) to replace the ctrl-r binding. fzf includes such a script that you just need to call from .bashrc.
# Enable key bindings for fzf
if command -v fzf 1> /dev/null && [[ -f "/usr/share/doc/fzf/examples/key-bindings.bash" ]]; then
source /usr/share/doc/fzf/examples/key-bindings.bash
fi
- sjagoe 3y agoI had been using the history append for years before finding atuin a couple years ago. I still occassionally lost history through some combination of events I was never able to understand. I've been using atuin happily for a few years now and it blows bash history out of the water.
- berkes 3y agoI had nearly the exact setup. But I never fully understood it. And despite tweaks, it kept loosing some history entries. Not a huge problem, until it was :) I have far more confidence in atuin handling race-conditions and upserts than in my bash-spagetti not doing that. Also, fzf, has a better append-history, but even there I managed to get it into some race-condition now and again. I presume it has to do with when the append happens: after the command ran and finished vs when I hit enter? Again, I don't know the details, and frankly, don't really want to know them either, if I can just lean on a tool by people who truly understand the problem.
- jcynix 3y ago>For your 1st issue, you can setup bash to append commands rather than overwrite them. Good, but even better (IMHO) is to write one history file for each terminal window, shell and level as in export HISTFILE=$HOME/.history/${TTY##*/}.$SHLVL And then I tell zsh to add timestamps setopt APPENDHISTORY # don't overwrite HISTFILE setopt EXTENDEDHISTORY # add timestamps to HISTFILE setopt HISTIGNORESPACE # aka setopt -g set HIST_FIND_NO_DUPS # don't show duplicates on ctrl-R Now I can grep my history and, based on other work notes I take, can even limit my search by date/time if needed.