# readline/pyreadline
- pyreadlinew32_startup = os.path.join(
- sys.prefix, 'lib', 'site-packages',
- 'pyreadline', 'configuration', 'startup.py')
+ # From Bruce Edge:
+ # https://mail.python.org/pipermail/python-list/2001-March/062888.html
- if os.path.exists(pyreadlinew32_startup):
- execfile(pyreadlinew32_startup)
-
- else:
- # From Bruce Edge:
- # https://mail.python.org/pipermail/python-list/2001-March/062888.html
-
- try:
- import rlcompleter # noqa: need for completion
- import readline
- initfile = os.environ.get('INPUTRC') \
- or os.path.expanduser('~/.inputrc')
- readline.read_init_file(initfile)
-
- # if 'libedit' in readline.__doc__:
- # readline.parse_and_bind("bind ^I rl_complete")
- # else:
- # readline.parse_and_bind("tab: complete")
-
- histfiles = ['~/.python_history']
- # if 'VIRTUAL_ENV' in os.environ:
- # histfiles.append('$VIRTUAL_ENV/.python_history')
- for histfile in histfiles:
- try:
- histfile = os.path.expandvars(histfile)
- histfile = os.path.expanduser(histfile)
- readline.read_history_file(histfile)
- except IOError:
- pass # No such file
-
- def savehist():
- histsize = os.environ.get('HISTSIZE')
- if histsize:
- try:
- histsize = int(histsize)
- except ValueError:
- pass
- else:
- readline.set_history_length(histsize)
- histfile = histfiles[-1]
+ try:
+ import rlcompleter # noqa: need for completion
+ import readline
+ initfile = os.environ.get('INPUTRC') \
+ or os.path.expanduser('~/.inputrc')
+ readline.read_init_file(initfile)
+
+ # if 'libedit' in readline.__doc__:
+ # readline.parse_and_bind("bind ^I rl_complete")
+ # else:
+ # readline.parse_and_bind("tab: complete")
+
+ histfiles = ['~/.python_history']
+ # if 'VIRTUAL_ENV' in os.environ:
+ # histfiles.append('$VIRTUAL_ENV/.python_history')
+ for histfile in histfiles:
+ try:
histfile = os.path.expandvars(histfile)
histfile = os.path.expanduser(histfile)
+ readline.read_history_file(histfile)
+ except IOError:
+ pass # No such file
+
+ def savehist():
+ histsize = os.environ.get('HISTSIZE')
+ if histsize:
try:
- readline.write_history_file(histfile)
- except IOError:
+ histsize = int(histsize)
+ except ValueError:
pass
+ else:
+ readline.set_history_length(histsize)
+ histfile = histfiles[-1]
+ histfile = os.path.expandvars(histfile)
+ histfile = os.path.expanduser(histfile)
+ try:
+ readline.write_history_file(histfile)
+ except IOError:
+ pass
+
+ import atexit
+ atexit.register(savehist)
import atexit
- atexit.register(savehist)
- except (ImportError, AttributeError):
- # no readline or atexit, or readline doesn't have
- # {read,write}_history_file - ignore the error
- pass
+ except (ImportError, AttributeError):
+ # no readline or atexit, or readline doesn't have
+ # {read,write}_history_file - ignore the error
+ pass
# terminal