Skip to content

Repository files navigation

CaseShift

License: MITPython 3.8+

A fast CLI tool for converting variable names between naming conventions.

Description

caseshift converts variable names between multiple naming conventions with intelligent detection and colorized output. Perfect for refactoring code, working across languages, or standardizing naming conventions in your projects.

Features

  • Convert between 9 popular naming conventions
  • Auto-detect source case style
  • Batch processing for multiple variables
  • Pipeline-friendly stdin/stdout interface
  • Intelligent acronym handling (HTTPSConnection → https_connection)
  • Colorized output for better readability
  • Interactive mode with user-friendly prompts
  • Zero configuration required
  • Programmatic API for Python projects

Supported Case Styles

StyleExampleDescription
camelmyVariableNameLowercase first word, capitalize rest
pascalMyVariableNameCapitalize all words
snakemy_variable_nameLowercase with underscores
kebabmy-variable-nameLowercase with hyphens
screamingMY_VARIABLE_NAMEUppercase with underscores
dotmy.variable.nameLowercase with dots
titleMy_Variable_NameCapitalize with underscores
trainMy-Variable-NameCapitalize with hyphens
upper-kebabMY-VARIABLE-NAMEUppercase with hyphens

Installation

From GitHub (Recommended)

# Clone the repository
git clone https://github.com/onamfc/caseshift.git
cd caseshift
# Install in development mode
pip install -e .# Or install with development dependencies
pip install -e ".[dev]"

Direct Installation

pip install git+https://github.com/onamfc/caseshift.git

For Development

# Clone and set up development environment
git clone https://github.com/onamfc/caseshift.git
cd caseshift
pip install -r requirements-dev.txt
pip install -e .

Quick Start

Command Line Usage

Basic conversion:

caseshift myVariable --to snake
# Output: myVariable -> my_variable

Interactive mode:

caseshift --interactive
# Launches interactive prompts for easy conversion

Detect case style:

caseshift HTTPSConnection --to snake --detect
# Output: Detected: pascal# HTTPSConnection -> https_connection

Batch processing:

cat variables.txt | caseshift --to kebab --batch
# Converts multiple variables from stdin

Quiet mode (for scripting):

echo"myVariable"| caseshift --to snake --quiet
# Output: my_variable (no colors or arrows)

Python API Usage

fromcaseshiftimportconvert_case, detect_case, to_snake_case# Direct conversionresult=convert_case("myVariable", "snake")
print(result) # my_variable# Detect case stylecase_style=detect_case("HTTPSConnection")
print(case_style) # pascal# Use specific convertersnake=to_snake_case("myVariable")
print(snake) # my_variable

Usage Examples

Single Variable Conversion

# Convert to different styles
caseshift myVariable --to snake # my_variable
caseshift my_variable --to camel # myVariable
caseshift my-variable --to pascal # MyVariable
caseshift MyVariable --to kebab # my-variable
caseshift http_request --to screaming # HTTP_REQUEST

Batch Processing

# Process multiple variables
cat <<EOF | caseshift --to snake --batchmyFirstVariablemySecondVariablemyThirdVariableEOF# Output:# myFirstVariable -> my_first_variable# mySecondVariable -> my_second_variable# myThirdVariable -> my_third_variable

Pipeline Usage

# Extract and convert variable names
grep -oP '\b[a-z][a-zA-Z0-9]*\b' file.js | caseshift --to snake --batch --quiet
# Convert clipboard content (macOS)
pbpaste | caseshift --to kebab
# Convert and save to fileecho"myVariable"| caseshift --to snake --quiet > output.txt

Interactive Mode

caseshift --interactive

This launches an interactive session where you can:

  1. Enter variable names
  2. See auto-detected case style
  3. Choose target case from a menu
  4. See colorized conversion results

Programmatic Usage

fromcaseshiftimport (
to_camel_case,
to_pascal_case,
to_snake_case,
to_kebab_case,
to_screaming_snake_case,
to_dot_case,
to_title_case,
to_train_case,
to_upper_kebab_case,
convert_case,
detect_case,
)
# Use specific convertersprint(to_snake_case("myVariable")) # my_variableprint(to_camel_case("my_variable")) # myVariableprint(to_pascal_case("my-variable")) # MyVariableprint(to_kebab_case("MyVariable")) # my-variableprint(to_screaming_snake_case("myVar")) # MY_VARprint(to_dot_case("myVariable")) # my.variableprint(to_title_case("myVariable")) # My_Variableprint(to_train_case("myVariable")) # My-Variableprint(to_upper_kebab_case("myVariable")) # MY-VARIABLE# Generic converter with detectiontext="HTTPSConnection"detected=detect_case(text)
print(f"Detected: {detected}") # pascalconverted=convert_case(text, "snake")
print(converted) # https_connection

Command Line Options

Usage: caseshift [OPTIONS] [TEXT]
Convert variable names between naming conventions.
Options:
-t, --to [camel|pascal|snake|kebab|screaming|dot|title|train|upper-kebab]
Target case style
-b, --batch Process multiple lines from stdin
-q, --quiet Output only converted text
-d, --detect Show detected case style
-i, --interactive Interactive mode with prompts
--version Show the version and exit
--help Show this message and exit

Advanced Examples

Refactoring Code Variables

# Extract all camelCase variables and convert to snake_case
grep -oP '\b[a-z][a-zA-Z0-9]*\b' src/app.js | \
sort -u | \
caseshift --to snake --batch

Convert Between Languages

# Convert Python variables to JavaScript style
grep -oP '(?<=self\.)[a-z_]+' python_class.py | \
caseshift --to camel --batch --quiet

Integration with Git Hooks

# In a pre-commit hook, check for consistent naming
git diff --cached --name-only | \
xargs grep -h "const\s\+\K[a-zA-Z_][a-zA-Z0-9_]*"| \
caseshift --to camel --detect

Testing

Run the test suite:

# Install dev dependencies first
pip install -r requirements-dev.txt
# Run all tests
pytest
# Run with coverage
pytest --cov=var_case --cov-report=html
# Run specific test file
pytest tests/test_converter.py

Development

Setup Development Environment

git clone https://github.com/onamfc/caseshift.git
cd caseshift
pip install -r requirements-dev.txt
pip install -e .

Code Quality

# Format code
black src/ tests/
# Type checking
mypy src/
# Linting
flake8 src/ tests/

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Troubleshooting

Command not found after installation

Make sure your Python scripts directory is in your PATH:

# Add to ~/.bashrc or ~/.zshrcexport PATH="$HOME/.local/bin:$PATH"

Import errors when using as library

Ensure the package is installed:

pip install -e .

Tests failing

Install dev dependencies:

pip install -r requirements-dev.txt

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

See CHANGELOG.md for version history and release notes.

Acknowledgments

  • Built with Click for the CLI interface
  • Inspired by the need for consistent naming across different programming languages

Made for developers who value clean, consistent code

About

A fast CLI tool for converting variable names between naming conventions.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages