Skip to content

Instantly share code, notes, and snippets.

@avicoder
Forked from matterche/.pystartup
Created September 20, 2017 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avicoder/13c90827934b5207b173eb8d55da013a to your computer and use it in GitHub Desktop.
Save avicoder/13c90827934b5207b173eb8d55da013a to your computer and use it in GitHub Desktop.
Enable Python REPL command history and tab completion
# Store this file in ~/.pystartup,
# set "export PYTHONSTARTUP=/home/user/.pystartup"
#
# Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
# full path to your home directory.
import atexit
import os
import readline
import rlcompleter
readline.parse_and_bind('tab: complete')
historyPath = os.path.expanduser("~/.pyhistory")
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment