|
| 1 | +* `sh` has terrible history mgmt, just dont even try. |
| 2 | +* `fish` is aiight but needs some love |
| 3 | +* `bash` is better with a lot of config (like the below) -- Even then it still isn't good enough: |
| 4 | + - up-arrow through history goes through all sessions, and not just the current one. |
| 5 | + |
| 6 | +```sh |
| 7 | +# Enable history expansion with space |
| 8 | +# E.g. typing !!<space> will replace the !! with your last command |
| 9 | +bind Space:magic-space |
| 10 | + |
| 11 | +# Use standard ISO 8601 timestamp |
| 12 | +# %F equivalent to %Y-%m-%d |
| 13 | +# %T equivalent to %H:%M:%S (24-hours format) |
| 14 | +export HISTTIMEFORMAT='%F %T ' |
| 15 | + |
| 16 | +# keep history up to date, across sessions, in realtime |
| 17 | +# http://unix.stackexchange.com/a/48113 |
| 18 | +export HISTCONTROL="ignoredups" # no duplicate entries, but keep space-prefixed commands. (bash-sensible uses "erasedups:ignoreboth" but i think i validated this already?) |
| 19 | +# here's the popularity amonngst other-peoples-dotfiles... (cmd: ag --nogroup --noheading --nofilename --hidden -o "HISTCONTROL.*" | grep -E -o "(ignore|erase)[a-z:]*" | sort | uniq -c | sort -r) |
| 20 | +# 5 ignoreboth |
| 21 | +# 4 ignoredups |
| 22 | +# 2 erasedups:ignoreboth |
| 23 | +# 1 ignorespace:erasedups |
| 24 | +# 1 ignoredups:erasedups |
| 25 | +# 1 erasedups |
| 26 | + |
| 27 | +export HISTSIZE=100000 # big big history (default is 500) |
| 28 | +export HISTFILESIZE=$HISTSIZE # big big history |
| 29 | +shopt -s histappend # append to history, don't overwrite it |
| 30 | +shopt -s cmdhist # Save multi-line commands as one command |
| 31 | + |
| 32 | + |
| 33 | +# Enable incremental history search with up/down arrows (also Readline goodness) |
| 34 | +# Learn more about this here: http://codeinthehole.com/writing/the-most-important-command-line-tip-incremental-history-searching-with-inputrc/ |
| 35 | +bind '"\e[A": history-search-backward' |
| 36 | +bind '"\e[B": history-search-forward' |
| 37 | + |
| 38 | +# Don't record some commands |
| 39 | +export HISTIGNORE="&:[ ]*:exit:ls:bg:fg:history:clear" |
| 40 | + |
| 41 | +# Save and reload the history after each command finishes. Also look for any conflicting prompt_command definitions!! |
| 42 | +export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" |
| 43 | + |
| 44 | +# ^ the only downside with this is [up] on the readline will go over all history not just this bash session. |
| 45 | +``` |
0 commit comments