A fast CLI tool for converting variable names between naming conventions.
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.
- 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
| Style | Example | Description |
|---|---|---|
camel |
myVariableName |
Lowercase first word, capitalize rest |
pascal |
MyVariableName |
Capitalize all words |
snake |
my_variable_name |
Lowercase with underscores |
kebab |
my-variable-name |
Lowercase with hyphens |
screaming |
MY_VARIABLE_NAME |
Uppercase with underscores |
dot |
my.variable.name |
Lowercase with dots |
title |
My_Variable_Name |
Capitalize with underscores |
train |
My-Variable-Name |
Capitalize with hyphens |
upper-kebab |
MY-VARIABLE-NAME |
Uppercase with hyphens |
# 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]"pip install git+https://github.com/onamfc/caseshift.git# 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 .Basic conversion:
caseshift myVariable --to snake
# Output: myVariable -> my_variableInteractive mode:
caseshift --interactive
# Launches interactive prompts for easy conversionDetect case style:
caseshift HTTPSConnection --to snake --detect
# Output: Detected: pascal
# HTTPSConnection -> https_connectionBatch processing:
cat variables.txt | caseshift --to kebab --batch
# Converts multiple variables from stdinQuiet mode (for scripting):
echo "myVariable" | caseshift --to snake --quiet
# Output: my_variable (no colors or arrows)from caseshift import convert_case, detect_case, to_snake_case
# Direct conversion
result = convert_case("myVariable", "snake")
print(result) # my_variable
# Detect case style
case_style = detect_case("HTTPSConnection")
print(case_style) # pascal
# Use specific converter
snake = to_snake_case("myVariable")
print(snake) # my_variable# 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# Process multiple variables
cat << EOF | caseshift --to snake --batch
myFirstVariable
mySecondVariable
myThirdVariable
EOF
# Output:
# myFirstVariable -> my_first_variable
# mySecondVariable -> my_second_variable
# myThirdVariable -> my_third_variable# 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 file
echo "myVariable" | caseshift --to snake --quiet > output.txtcaseshift --interactiveThis launches an interactive session where you can:
- Enter variable names
- See auto-detected case style
- Choose target case from a menu
- See colorized conversion results
from caseshift import (
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 converters
print(to_snake_case("myVariable")) # my_variable
print(to_camel_case("my_variable")) # myVariable
print(to_pascal_case("my-variable")) # MyVariable
print(to_kebab_case("MyVariable")) # my-variable
print(to_screaming_snake_case("myVar")) # MY_VAR
print(to_dot_case("myVariable")) # my.variable
print(to_title_case("myVariable")) # My_Variable
print(to_train_case("myVariable")) # My-Variable
print(to_upper_kebab_case("myVariable")) # MY-VARIABLE
# Generic converter with detection
text = "HTTPSConnection"
detected = detect_case(text)
print(f"Detected: {detected}") # pascal
converted = convert_case(text, "snake")
print(converted) # https_connectionUsage: 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
# 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 Python variables to JavaScript style
grep -oP '(?<=self\.)[a-z_]+' python_class.py | \
caseshift --to camel --batch --quiet# 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 --detectRun 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.pygit clone https://github.com/onamfc/caseshift.git
cd caseshift
pip install -r requirements-dev.txt
pip install -e .# Format code
black src/ tests/
# Type checking
mypy src/
# Linting
flake8 src/ tests/Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Make sure your Python scripts directory is in your PATH:
# Add to ~/.bashrc or ~/.zshrc
export PATH="$HOME/.local/bin:$PATH"Ensure the package is installed:
pip install -e .Install dev dependencies:
pip install -r requirements-dev.txtThis project is licensed under the MIT License - see the LICENSE file for details.
See CHANGELOG.md for version history and release notes.
- 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