In yesterday’s post the
past repo was described.
The first step to getting that to work is to correctly configure
history files in the first place. Some are easy, but some are more
For zsh and MySQL it’s rather easy. Just put something
like this in your
setopt append_history hist_allow_clobber hist_ignore_dups
setopt hist_ignore_space hist_no_store hist_reduce_blanks
setopt hist_verify inc_append_history
if [[ ! -d ~/.history.d ]]; then
For [bash][bash] it’s similar:
shopt -s histappend
if [ ! -d "$HOME/.history.d" ]; then
In both bash and zsh I use a setting that prevents commands prefixed with
a space from being saved to history. I do this when I run a command with
a password on them. MySQL also blocks some statements
from being stored.
Lastly is Python which proved more difficult due to differences
between python on Linux and on OS X. I haven’t yet tested it with
python 3.x versions.
# Add auto-completion and a stored history file of commands to your Python
# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
# bound to the tab key - see the readline.parse_and_bind call.
# Store the file in ~/.pystartup, and set an environment variable to point
# to it: "export PYTHONSTARTUP=/home/user/.pystartup" in bash.
# Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
# full path to your home directory.
# Based off the 2.4 python docs, changed by email@example.com
# Set readline interactive options.
if 'libedit' in readline.__doc__:
# Fucking Apple.
readline.parse_and_bind("bind ^I rl_complete")
# Set history path (shard by version), saving and recall.
historyPath = os.path.expanduser("~/.history.d/%s.python%s.%s.interactive"
% (os.uname().split('.'), sys.version_info, sys.version_info))
print('TODO: Define some funcs to import history from other versions.')
del os, sys, atexit, readline, rlcompleter, save_history, historyPath