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(*args: Any, **kwargs: Any)[source]¶
Bases:
PosixPathPath 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'
- classmethod _collapse_home(value)[source]¶
Collapse the user’s home directory to
~invalue.- Return type:
- Parameters:
value (str) – Path string to process
- Returns:
Path with home directory replaced by
~if applicable- Return type:
Examples
>>> import pathlib >>> home = str(pathlib.Path.home()) >>> PrivatePath._collapse_home(home) '~' >>> PrivatePath._collapse_home(home + "/projects") '~/projects' >>> PrivatePath._collapse_home("/tmp/test") '/tmp/test' >>> PrivatePath._collapse_home("~/already/collapsed") '~/already/collapsed'
- tmuxp._internal.private_path.collapse_home_in_string(text)[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.
- Return type:
- Parameters:
text (str) – String potentially containing paths separated by colons (or semicolons on Windows)
- Returns:
String with home directory paths collapsed to
~- Return type:
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'