Private path - tmuxp._internal.private_path

Warning

Be careful with these! Internal APIs are not covered by version policies. They can break or be removed between minor versions!

If you need an internal API stabilized please file an issue.

Privacy-aware path utilities for hiding sensitive directory information.

This module provides utilities for masking user home directories in path output, useful for logging, debugging, and displaying paths without exposing PII.

class tmuxp._internal.private_path.PrivatePath

Bases: PosixPath

Path subclass that hides the user’s home directory in textual output.

The class behaves like pathlib.Path, but normalizes string and representation output to replace the current user’s home directory with ~. This is useful when logging or displaying paths that should not leak potentially sensitive information.

Examples

>>> from pathlib import Path
>>> home = Path.home()
>>> PrivatePath(home)
PrivatePath('~')
>>> PrivatePath(home / "projects" / "tmuxp")
PrivatePath('~/projects/tmuxp')
>>> str(PrivatePath("/tmp/example"))
'/tmp/example'
>>> f'config: {PrivatePath(home / ".tmuxp" / "config.yaml")}'
'config: ~/.tmuxp/config.yaml'
tmuxp._internal.private_path.collapse_home_in_string(text)
function[source]

Collapse home directory paths within a colon-separated string.

Useful for processing PATH-like environment variables that may contain multiple paths, some of which are under the user’s home directory.

Parameters:

text (str) – String potentially containing paths separated by colons (or semicolons on Windows)

Returns:

String with home directory paths collapsed to ~

Return type:

str

Examples

>>> import pathlib
>>> home = str(pathlib.Path.home())
>>> collapse_home_in_string(f"{home}/.local/bin:/usr/bin")
'~/.local/bin:/usr/bin'
>>> collapse_home_in_string("/usr/bin:/bin")
'/usr/bin:/bin'
>>> path_str = f"{home}/bin:{home}/.cargo/bin:/usr/bin"
>>> collapse_home_in_string(path_str)
'~/bin:~/.cargo/bin:/usr/bin'