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.

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.0.tar.gz (10.7 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.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pathshortener-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1bc52d88d4a73859b2970eb7882a43b2eb7b41c2ffc9966960a50b9d28e8f550
MD5 d16d3388e759526013cd4575eb745ba2
BLAKE2b-256 1ffe4f02fe03b84f0f4338cb46850315c311e880f91d580d83185bd81d964e0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pathshortener-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa5bf97b98fdeec909f542a7a17defef0ffd43cdb9c6d69b51ef19b5541cd19c
MD5 111de0e3736d9fd480d4be5c6c233299
BLAKE2b-256 31fbd14effd2e7c40ce30ef24f2822752c3e35749cadff369b877c49bde9f71f

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