diff --git a/home-manager/common.nix b/home-manager/common.nix index 306d4a8..56acf19 100644 --- a/home-manager/common.nix +++ b/home-manager/common.nix @@ -256,8 +256,7 @@ in "ghostty" = createDotLink "ghostty"; }; home.file = { - ".pdbrc" = { - source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/python/.pdbrc"; - }; + ".pdbrc" = { source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/python/.pdbrc";}; + ".pdb_startup.py" = { source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/python/.pdb_startup.py";}; }; } diff --git a/python/.pdb_startup.py b/python/.pdb_startup.py new file mode 100644 index 0000000..164e8ad --- /dev/null +++ b/python/.pdb_startup.py @@ -0,0 +1,17 @@ +import atexit +import os + +try: + import readline + historyPath = os.path.expanduser("~/.pdb_history") + readline.clear_history() + if os.path.exists(historyPath): + readline.read_history_file(historyPath) + + def save_history(historyPath=historyPath): + import readline + readline.write_history_file(historyPath) + + atexit.register(save_history) +except ImportError: + pass diff --git a/python/.pdbrc b/python/.pdbrc index 9779672..ea15ba9 100644 --- a/python/.pdbrc +++ b/python/.pdbrc @@ -1,18 +1 @@ -# ~/.pdbrc -import atexit -import os -import readline - -# Define where the pdb command history will be saved -historyPath = os.path.expanduser("~/.pdb_history") - -# Read existing history if it exists -if os.path.exists(historyPath): - readline.read_history_file(historyPath) - -# Register a hook to automatically save history when exiting pdb -def save_history(historyPath=historyPath): - import readline - readline.write_history_file(historyPath) - -atexit.register(save_history) +import importlib.util, os; spec = importlib.util.spec_from_file_location("pdb_startup", os.path.expanduser("~/.pdb_startup.py")); mod = importlib.util.module_from_spec(spec); spec.loader.exec_module(mod)