10000 bpo-38791: Add readline history environment variable by jonathan-conder · Pull Request #17149 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-38791: Add readline history environment variable #17149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bpo-38791: Add readline history environment variable
  • Loading branch information
jonathan-conder committed Nov 14, 2019
commit 536ae80434daba2a9a294e7b82b7aadf9a9038f3
8 changes: 4 additions & 4 deletions Doc/library/site.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ On systems that support :mod:`readline`, this module will also import and
configure the :mod:`rlcompleter` module, if Python is started in
:ref:`interactive mode <tut-interactive>` and without the :option:`-S` option.
The default behavior is enable tab-completion and to use
:file:`~/.python_history` as the history save file. To disable it, delete (or
override) the :data:`sys.__interactivehook__` attribute in your
:mod:`sitecustomize` or :mod:`usercustomize` module or your
:envvar:`PYTHONSTARTUP` file.
:envvar:`PYTHONHISTFILE` (or :file:`~/.python_history`, if the former does not
exist) as the history save file. To disable it, delete (or override) the
:data:`sys.__interactivehook__` attribute in your :mod:`sitecustomize` or
:mod:`usercustomize` module or your :envvar:`PYTHONSTARTUP` file.

.. versionchanged:: 3.4
Activation of rlcompleter and history was made automatic.
Expand Down
6 changes: 6 additions & 0 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@ before the command-line switches other than -E or -I. It is customary that
command-line switches override environmental variables where there is a
conflict.

.. envvar:: PYTHONHISTFILE

If this is the name of a file, and :mod:`readline` is enabled, it will be
used as the history save file. The default is :file:`~/.python_history`.


.. envvar:: PYTHONHOME

Change the location of the standard Python libraries. By default, the
Expand Down
7 changes: 5 additions & 2 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,11 @@ def register_readline():
# each interpreter exit when readline was already configured
# through a PYTHONSTARTUP hook, see:
# http://bugs.python.org/issue5845#msg198636
history = os.path.join(os.path.expanduser('~'),
'.python_history')
history = os.environ.get('PYTHONHISTFILE')
if not history or not os.path.isfile(history):
history = os.path.join(os.path.expanduser('~'),
'.python_history')

try:
readline.read_history_file(history)
except OSError:
Expand Down
0