1
0
mirror of https://github.com/frebib/dotfiles.git synced 2024-06-14 12:57:23 +00:00

python: move .python_history to $XDG_CACHE_DIR/python

Courtesy of 89fd8cc648

Signed-off-by: Joe Groocock <me@frebib.net>
This commit is contained in:
2020-08-23 11:17:01 +01:00
parent f16cd95a0f
commit be88417d59
2 changed files with 25 additions and 1 deletions

24
python/startup Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python
import atexit
import os
import readline
xdg_cache_home = os.environ['XDG_CACHE_HOME']
if xdg_cache_home is None or xdg_cache_home == "":
xdg_cache_home = os.path.join(os.path.expanduser("~"), ".cache")
python_cache_dir = os.path.join(xdg_cache_home, "python")
if not os.path.isdir(python_cache_dir):
os.mkdir(python_cache_dir)
histfile = os.path.join(python_cache_dir, "history")
try:
readline.read_history_file(histfile)
readline.set_history_length(10000)
except FileNotFoundError:
pass
atexit.register(readline.write_history_file, histfile)