Skip to content

Instantly share code, notes, and snippets.

@arowser
Created July 9, 2013 02:36
Show Gist options
  • Save arowser/5954256 to your computer and use it in GitHub Desktop.
Save arowser/5954256 to your computer and use it in GitHub Desktop.
Add History and Tab Completion to the Default Python Shell
# ~/.bashrc
export PYTHONSTARTUP=$HOME/.pythonstartup.py
# ~/.pythonstartup.py
try:
import readline
import rlcompleter
import atexit
import os
except ImportError:
print "Python shell enhancement modules not available."
else:
histfile = os.path.join(os.environ["HOME"], ".pythonhistory")
import rlcompleter
readline.parse_and_bind("tab: complete")
if os.path.isfile(histfile):
readline.read_history_file(histfile)
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter, atexit
print "Python shell history and tab completion are enabled."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment