PathShortener
A Python library for shortening Windows environment variables and paths by finding and replacing repeated patterns with environment variable references.
DISCLAIMER
This is a work in progress and should not be used in production. Be very careful with this tool. Use dry run mode to see what it will do. Be sure to back up your environment variables before running this tool.
Features
- Shorten environment variables by replacing repeated substrings with references
- Compress environment variables by finding common patterns
- Automatically split long environment variables into chunks
- Handle Windows registry operations for environment variables
- Support for both temporary and permanent environment variable changes
- Command-line interface for quick access to functionality
Installation
pip install pathshortener
Usage
As a Library
from pathshortener import shorten_string, compress_single_variable, compress_all_variables
# Shorten a single string
shortened_string, env_map = shorten_string(
input_string="C:\\Program Files\\Common Files\\System\\Some\\Long\\Path",
max_vars=10,
min_length=5,
dry_run=True
)
# Compress a single environment variable
old_len, new_len, env_map, final_val = compress_single_variable(
env_var_name="PATH",
dry_run=True,
max_vars=10,
min_length=5,
permanent=False,
max_length=2048 # Values exceeding this will be split into chunks
)
# Compress all environment variables
old_total, new_total, env_map, var_to_newval = compress_all_variables(
dry_run=True,
max_vars=10,
min_length=5,
permanent=False
)
Command Line Interface
# Shorten a string
pathshortener --string "C:\\Program Files\\Common Files\\System\\Some\\Long\\Path" --dry-run
# Compress a single environment variable
pathshortener --env-var PATH --dry-run --max-length 2048
# Compress all environment variables
pathshortener --env-var ALL --dry-run
# Make permanent changes (writes to Windows registry)
pathshortener --env-var PATH --permanent
Options
--dry-run: Show what would happen without making changes--max-vars: Maximum number of new environment variables to create (default: 10)--min-length: Minimum length of substrings to consider for substitution (default: 5)--max-length: Maximum length for environment variable values (default: 2048). Values exceeding this will be split into chunks.--env-var: Environment variable to process (default: PATH), or 'ALL' for global synergy--string: An arbitrary string to shorten--permanent: Write changes to Windows registry (HKEY_CURRENT_USER\Environment)
How It Works
-
First, the tool tries to shorten environment variables by:
- Finding and replacing repeated substrings with environment variable references
- Using existing environment variables where possible
- Creating new environment variables for common patterns
-
If the resulting value exceeds the maximum length (default: 2048 characters):
- The value is split into chunks at path separators
- Each chunk is stored in a new environment variable
- The original variable is updated to reference these chunks
This two-step process ensures that environment variables are both shortened and kept within Windows' length limits.
Requirements
- Windows operating system
- Python 3.6 or higher
License
MIT License
Metadata
Release files for pathshortener 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pathshortener-0.1.1.tar.gz | 10.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pathshortener-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / pathshortener-0.1.1.tar.gz
| Download URL | pathshortener-0.1.1.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8482c8d54f01cd2d51a6e3f82553d0f090dfb46fb4423b4538859395bfc12706
|
|
BLAKE2b-256 checksum How to use checksums |
69063b9ff2843ac40ce6db3d68d5d2a10030de61833b6b76a8b30be7bc7cf5f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.7
|
Release files / pathshortener-0.1.1-py3-none-any.whl
| Download URL | pathshortener-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f09d77b634ffc6637fcdce014e29bb1c88a5fc638d1ee4b378b380eb051a2729
|
|
BLAKE2b-256 checksum How to use checksums |
81e7b175eb209df865740e944d9b8c16870365ef2ca68a643c38f280d7fb4a1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.7
|