1
0
mirror of https://github.com/frebib/dotfiles.git synced 2024-06-14 12:57:23 +00:00
dotfiles/python/startup
Joe Groocock be88417d59
python: move .python_history to $XDG_CACHE_DIR/python
Courtesy of 89fd8cc648

Signed-off-by: Joe Groocock <me@frebib.net>
2020-08-23 11:18:22 +01:00

25 lines
592 B
Python

#!/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)