Skip to main content

A library for shortening Windows environment variables and paths

Project description

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

  1. 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
  2. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathshortener-0.1.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pathshortener-0.1.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file pathshortener-0.1.1.tar.gz.

File metadata

  • Download URL: pathshortener-0.1.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.7

File hashes

Hashes for pathshortener-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8482c8d54f01cd2d51a6e3f82553d0f090dfb46fb4423b4538859395bfc12706
MD5 eddbf7bc20d49bb654a81964999bf23f
BLAKE2b-256 69063b9ff2843ac40ce6db3d68d5d2a10030de61833b6b76a8b30be7bc7cf5f8

See more details on using hashes here.

File details

Details for the file pathshortener-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pathshortener-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f09d77b634ffc6637fcdce014e29bb1c88a5fc638d1ee4b378b380eb051a2729
MD5 a962e89683ed3187f9722638ec9e2ded
BLAKE2b-256 81e7b175eb209df865740e944d9b8c16870365ef2ca68a643c38f280d7fb4a1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page