# Add auto-completion and a stored history file of commands for the Python repl.  Requires Python 2.0+ readline.  Autocomplete is bound to the Esc key by default.

# This file should be linked to ~/.pystartup, and set with an environment variable to point to it.

# fish "set -gx PYTHONSTARTUP ~/.pystartup"
# bash "export PYTHONSTARTUP=~/.pystartup"

import atexit
import os
import readline
import rlcompleter

historyPath = os.path.expanduser("~/.py_repl_history")

# Tab completion
# readline.parse_and_bind('tab: complete')

def save_history(historyPath=historyPath):
    import readline
    readline.write_history_file(historyPath)

if os.path.exists(historyPath):
    readline.read_history_file(historyPath)

atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
# {% endhight %}
