# Why not use $XDG\_CONFIG\_HOME/pdb/.pdbrc?

**URL:** <https://discuss.python.org/t/why-not-use-xdg-config-home-pdb-pdbrc/91411>\
**Category:** Ideas\
**Created:** [May 9, 2025, 7:25pm UTC](https://discuss.python.org/t/why-not-use-xdg-config-home-pdb-pdbrc/91411 "2025-05-09T19:25:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![makukha](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/makukha/32/21764_2.png) [@makukha](https://discuss.python.org/u/makukha)\
**Post date:** [May 9, 2025, 7:25pm UTC](https://discuss.python.org/t/why-not-use-xdg-config-home-pdb-pdbrc/91411/1 "2025-05-09T19:25:31Z")

</div>

This question may come to mind when fine-tuning `pdb`.

For example, setting up `.pdb_history`. The widespread approach is to put instructions to `.pdbrc` that will load some code from, say, `pdbrc.py`. Storing both in $HOME? Too much clutter. Moving `pdbrc.py` to `~/.config/pdb/` sounds better, but why not move both?

The problem is that `pdb` supports only `./.pdbrc` and `~/.pdbrc` locations at the moment. Yes, adding support for new `.pdbrc` location will cost some lines of code [python/cpython#133733](https://github.com/python/cpython/pull/133733/files), but user’s $HOME will be more organized.

> **Example ~/.pdbrc (:sad:) and ~/.config/pdb/pdbrc.py**
>
> ```plaintext
> # ~/.pdbrc
> import os as _os
> with open(_os.path.expanduser('~/.config/pdb/pdbrc.py')) as _f: _f = _f.read()
> exec(_f)
> del _f, _os
> 
> ```
> 
> ```python
> # ~/.config/pdb/pdbrc.py
> def _pdbrc_init():
> """
> Save history across sessions.
> """
> import atexit
> import os
> import readline
> 
> HISTFILE = '~/.pdb_history'
> HISTFSIZE = 1000
> 
> readline.parse_and_bind('tab: complete')
> try:
> readline.read_init_file()
> except OSError:
> pass
> 
> history = os.path.expanduser(os.getenv('PDB_HISTFILE', HISTFILE))
> if readline.get_current_history_length() == 0:
> if os.path.exists(history):
> readline.read_history_file(history)
> 
> try:
> size = int(os.getenv('PDB_HISTSIZE', ''))
> except ValueError:
> size = HISTFSIZE
> readline.set_history_length(size)
> 
> def save_history(path):
> try:
> readline.write_history_file(path)
> except (FileNotFoundError, PermissionError):
> from warnings import warn
> warn(f'Unable to write Pdb history file {path}')
> 
> atexit.register(save_history, history)
> 
> _pdbrc_init()
> del _pdbrc_init
> 
> ```

What do you think?

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [May 9, 2025, 7:43pm UTC](https://discuss.python.org/t/why-not-use-xdg-config-home-pdb-pdbrc/91411/2 "2025-05-09T19:43:47Z")

</div>

I wish all the .rc was in .config as well.

For backwards compatibility if .config/pdb/pdbrc.py is missing then fallback to the current ~/.pdbrc?

---

<div class="post-metadata">

**Author:** ![makukha](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/makukha/32/21764_2.png) [@makukha](https://discuss.python.org/u/makukha)\
**Post date:** [May 9, 2025, 7:47pm UTC](https://discuss.python.org/t/why-not-use-xdg-config-home-pdb-pdbrc/91411/3 "2025-05-09T19:47:20Z")

</div>

@barry-scott yep, this is how it could look like: [https://cpython-previews–133733.org.readthedocs.build/en/133733/library/pdb.html#debugger-commands](https://cpython-previews--133733.org.readthedocs.build/en/133733/library/pdb.html#debugger-commands) (need to scroll down a little bit)
