Move everything possible into XDG directories
With the help of xdg-ninja (https://github.com/b3nj5m1n/xdg-ninja) we move all kinds of config/cache files into the XDG directories
This commit is contained in:
parent
7ceed45a28
commit
13b8724696
27 changed files with 131 additions and 42 deletions
33
.config/python/pythonrc
Normal file
33
.config/python/pythonrc
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# This file moves Python's history file to $XDG_STATE_HOME/python/history
|
||||
# Adapted from: https://unix.stackexchange.com/questions/630642/change-location-of-python-history
|
||||
|
||||
import os
|
||||
import atexit
|
||||
import readline
|
||||
from pathlib import Path
|
||||
|
||||
if readline.get_current_history_length() == 0:
|
||||
state_home = os.environ.get("XDG_STATE_HOME")
|
||||
if state_home is None:
|
||||
state_home = Path.home() / ".local" / "state"
|
||||
else:
|
||||
state_home = Path(state_home)
|
||||
|
||||
history_path = state_home / "python" / "history"
|
||||
if history_path.is_dir():
|
||||
raise OSError(f"'{history_path}' cannot be a directory")
|
||||
|
||||
history = str(history_path)
|
||||
|
||||
try:
|
||||
readline.read_history_file(history)
|
||||
except OSError: # Non existent
|
||||
pass
|
||||
|
||||
def write_history():
|
||||
try:
|
||||
readline.write_history_file(history)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
atexit.register(write_history)
|
||||
Loading…
Add table
Add a link
Reference in a new issue