27 lines
609 B
Python
27 lines
609 B
Python
#!/usr/bin/env python3
|
|
# Interactive Python REPL startup. Wired via $PYTHONSTARTUP (see home.nix).
|
|
# Persists REPL history to $PYTHON_HISTFILE (XDG cache), creating the dir.
|
|
|
|
from pathlib import Path
|
|
import os
|
|
import atexit
|
|
import readline
|
|
|
|
|
|
history = os.getenv('PYTHON_HISTFILE')
|
|
|
|
if history:
|
|
try:
|
|
Path(history).parent.mkdir(parents=True, exist_ok=True)
|
|
readline.read_history_file(history)
|
|
except OSError:
|
|
pass
|
|
|
|
def write_history():
|
|
try:
|
|
readline.write_history_file(history)
|
|
except OSError:
|
|
pass
|
|
|
|
atexit.register(write_history)
|