Main.MinimalistStartupFile History
Hide minor edits - Show changes to output
Added lines 1-62:
(:source lang=python:)
""" minimalstartup.py
A minimalist python startup file that sets up tab completion and command history
Author: Asa Ben-Hur
It's very easy to add tab completion and command-line history to your
python shell, and make it behave a lot like your unix command line.
All you need is a pythonstartup file, which is a file that the
interpreter calls when it starts up. You need to tell your shell
where the file is located by setting the PYTHONSTARTUP environment
variable to the location of your python startup file. This is done
by adding the following lines to your .bashrc file, which is located
in your home directory:
PYTHONSTARTUP=/home/asa/python/minimalstartup.py
export PYTHONSTARTUP
Adjust the location according to where you want to put your
startup file, and change this if you use a different shell.
"""
# These modules are always nice to have in the namespace
import sys, os
sys.path.append(".")
# The place to store your command history between sessions
histfile=os.path.join(os.environ["HOME"], "python", ".python-history")
# Try to set up command history completion/saving/reloading
try:
import readline, atexit, rlcompleter
try :
readline.parse_and_bind('tab: complete')
except :
pass
try:
readline.read_history_file(histfile)
except IOError:
pass # It doesn't exist yet.
def savehist():
try:
#global histfile
readline.write_history_file(histfile)
except:
print 'Unable to save Python command history'
atexit.register(savehist)
del atexit
except ImportError:
print "problem setting up tab completion or command history"
##### Make reload work recursively #####
try:
import __builtin__, deep_reload
__builtin__.reload = deep_reload.reload
del __builtin__, deep_reload
except ImportError:
pass
(:sourceend:)
""" minimalstartup.py
A minimalist python startup file that sets up tab completion and command history
Author: Asa Ben-Hur
It's very easy to add tab completion and command-line history to your
python shell, and make it behave a lot like your unix command line.
All you need is a pythonstartup file, which is a file that the
interpreter calls when it starts up. You need to tell your shell
where the file is located by setting the PYTHONSTARTUP environment
variable to the location of your python startup file. This is done
by adding the following lines to your .bashrc file, which is located
in your home directory:
PYTHONSTARTUP=/home/asa/python/minimalstartup.py
export PYTHONSTARTUP
Adjust the location according to where you want to put your
startup file, and change this if you use a different shell.
"""
# These modules are always nice to have in the namespace
import sys, os
sys.path.append(".")
# The place to store your command history between sessions
histfile=os.path.join(os.environ["HOME"], "python", ".python-history")
# Try to set up command history completion/saving/reloading
try:
import readline, atexit, rlcompleter
try :
readline.parse_and_bind('tab: complete')
except :
pass
try:
readline.read_history_file(histfile)
except IOError:
pass # It doesn't exist yet.
def savehist():
try:
#global histfile
readline.write_history_file(histfile)
except:
print 'Unable to save Python command history'
atexit.register(savehist)
del atexit
except ImportError:
print "problem setting up tab completion or command history"
##### Make reload work recursively #####
try:
import __builtin__, deep_reload
__builtin__.reload = deep_reload.reload
del __builtin__, deep_reload
except ImportError:
pass
(:sourceend:)
