A lightweight tool that sanitizes AI-written shell commands into Windows compatible ones
Project description
win-cmd-fixer
Convert problematic shell commands into Windows-compatible ones.
Have you ever used a deep-agent, or pasted an AI-generated command, then got errors like "cannot find the path" or "syntax is incorrect"?
That command made perfect sense — but Windows CMD just wouldn't cooperate.
Then this tool is for you.
Features
- Fix unquoted paths with spaces (e.g.
dir C:\Program Files→dir "C:\Program Files") - Auto-add
/dflag for cross-drivecd - Translate Unix command names to their Windows equivalents (
cp→copy,ls→dir, etc.) - Three output targets: Windows CMD, PowerShell 5.x, and Unix shell
- Handles chained commands with
&&,||,|,>,>>separators - Supports 20+ commands:
cd,dir,copy,move,del,type,mkdir,rmdir,rename,echo,find,findstr,cls,more,xcopy,pushd,popd,where, and their Unix aliases - Already-correct commands pass through unchanged
- Unknown commands are emitted verbatim (never crashes)
- Zero dependencies — both the Python and TypeScript packages are fully standalone
- Available in both Python and TypeScript
Installation
Python
pip install win-cmd-fixer
TypeScript / JavaScript
npm install win-cmd-fixer
Usage
Python
from win_cmd_fixer import fix_cmd, fix_powershell, fix_unix_shell
# Fix for Windows CMD
fix_cmd('cd D:\\Program Files\\project')
# => 'cd /d "D:\\Program Files\\project"'
fix_cmd('cp -r D:\\Program Files\\src C:\\Program Files\\dst')
# => 'robocopy /e "D:\\Program Files\\src" "C:\\Program Files\\dst"'
# Fix for PowerShell 5.x
fix_powershell('cd D:\\Program Files\\project')
# => 'Set-Location "D:\\Program Files\\project"'
fix_powershell('rm -rf D:\\Program Files\\old')
# => 'Remove-Item "D:\\Program Files\\old" -Recurse -Force'
# Fix for Unix shell (e.g. Git Bash, WSL)
fix_unix_shell('dir D:\\Program Files\\')
# => 'ls "/d/Program Files/"'
TypeScript / JavaScript
import {fixCmd, fixPowershell, fixUnixShell} from 'win-cmd-fixer';
// Fix for Windows CMD
fixCmd('cd D:\\Program Files\\project');
// => 'cd /d "D:\\Program Files\\project"'
fixCmd('cp -r D:\\Program Files\\src C:\\Program Files\\dst');
// => 'robocopy /e "D:\\Program Files\\src" "C:\\Program Files\\dst"'
// Fix for PowerShell 5.x
fixPowershell('cd D:\\Program Files\\project');
// => 'Set-Location "D:\\Program Files\\project"'
// Fix for Unix shell
fixUnixShell('dir D:\\Program Files\\');
// => 'ls "/d/Program Files/"'
What It Fixes
| Issue | Example | CMD | PowerShell | Unix |
|---|---|---|---|---|
| Paths with spaces | dir C:\Program Files |
dir "C:\Program Files" |
Get-ChildItem "C:\Program Files" |
ls "/c/Program Files" |
Cross-drive cd |
cd D:\folder |
cd /d "D:\folder" |
Set-Location "D:\folder" |
cd "/d/folder" |
| Unix command names | cp file.txt dest\ |
copy file.txt dest\ |
Copy-Item file.txt dest\ |
cp file.txt dest/ |
rm -rf |
rm -rf D:\old |
rmdir /s /q "D:\old" |
Remove-Item "D:\old" -Recurse -Force |
rm -rf "/d/old" |
cp -r |
cp -r src dst |
robocopy /e src dst |
Copy-Item src dst -Recurse |
cp -r src dst |
grep |
grep "pat" file |
findstr "pat" file |
Select-String "pat" file |
grep "pat" file |
clear |
clear |
cls |
Clear-Host |
clear |
which |
which python |
where python |
Get-Command python |
which python |
| Chained commands | echo hi && dir C:\P F |
echo hi && dir "C:\P F" |
Write-Output hi ; Get-ChildItem "C:\P F" |
echo hi && ls "/c/P F" |
API Reference
Python
| Function | Description |
|---|---|
fix_cmd(text: str) -> str |
Convert to valid Windows CMD syntax |
fix_powershell(text: str) -> str |
Convert to valid PowerShell 5.x syntax |
fix_unix_shell(text: str) -> str |
Convert to valid Unix shell syntax |
TypeScript
| Function | Description |
|---|---|
fixCmd(text: string): string |
Convert to valid Windows CMD syntax |
fixPowershell(text: string): string |
Convert to valid PowerShell 5.x syntax |
fixUnixShell(text: string): string |
Convert to valid Unix shell syntax |
Contributing
Contributions are welcome! Especially:
- New edge cases you've encountered
- Better heuristics for path detection
- Support for more commands or shell variations
Setup
git clone https://github.com/RockeyDon/win-cmd-fixer.git
cd win-cmd-fixer
Python
cd python
python -m venv .venv
.venv\Scripts\activate # Windows
pip install -e ".[dev]"
pytest tests/
TypeScript
cd typescript
npm install
npm test
Build & Publish
A single PowerShell script handles both packages:
# Build only (dry run)
.\publish.ps1
# Build and publish to PyPI + npm
.\publish.ps1 -Publish
# Publish Python to TestPyPI, npm dry-run
.\publish.ps1 -Publish -TestPyPI
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file win_cmd_fixer-0.2.0.tar.gz.
File metadata
- Download URL: win_cmd_fixer-0.2.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60eefccb56f294e4fa008d2e16c79fa21cb266006b6035a8eb2e8fdd19aa8a62
|
|
| MD5 |
6316e5c9c0c41626d106e48c5f688cc8
|
|
| BLAKE2b-256 |
b7525b7f0017d0ce4d5cd94bcc40ee36a60286c5f193427965b07beeb3551581
|
File details
Details for the file win_cmd_fixer-0.2.0-py3-none-any.whl.
File metadata
- Download URL: win_cmd_fixer-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc0fa903f56e69d094dac0c8d5aa917fa1f2d65507d8094e0fcafb9e51688871
|
|
| MD5 |
607141022b5ea5bb2fb9fb54eba0a52f
|
|
| BLAKE2b-256 |
0661512f3bc5d18eb0c45ba9322ece26ef609081fc90486f2b0cb910e5e650f0
|