Move .python_history to a new location

Signed-off-by: Severin Kaderli <severin.kaderli@gmail.com>
This commit is contained in:
Severin Kaderli 2019-02-13 22:19:58 +01:00
parent 62b2829be4
commit 55306bd850
Signed by: severinkaderli
GPG key ID: F419F8835B72F0C4
4 changed files with 27 additions and 2 deletions

View file

@ -0,0 +1,20 @@
import atexit
import os
import readline
XDG_DATA_HOME = os.environ["XDG_DATA_HOME"]
if not XDG_DATA_HOME:
histfile = os.path.join(os.path.expanduser(
"~"), ".local", "share", "python", "history")
else:
histfile = os.path.join(XDG_DATA_HOME, "python", "history")
try:
readline.set_auto_history(False)
readline.read_history_file(histfile)
readline.set_history_length(1000)
except FileNotFoundError:
pass
atexit.register(readline.write_history_file, histfile)