From f53a28e1fd29ed5d5b7887d58117ef137360d76b Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 22 Apr 2019 22:35:14 +0300 Subject: [PATCH] init.py: Read and save history from/to the current virtualenv Commented out for now. --- lib/python/init.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/python/init.py b/lib/python/init.py index 71526b9..1a91f04 100644 --- a/lib/python/init.py +++ b/lib/python/init.py @@ -36,16 +36,22 @@ def init(): or os.path.expanduser('~/.inputrc') readline.read_init_file(initfile) - histfile = os.path.expanduser('~/.python_history') - try: - readline.read_history_file(histfile) - except IOError: - pass # No such file # 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: @@ -55,6 +61,9 @@ def init(): pass else: readline.set_history_length(histsize) + histfile = histfiles[-1] + histfile = os.path.expandvars(histfile) + histfile = os.path.expanduser(histfile) readline.write_history_file(histfile) import atexit -- 2.39.2