Skip to main content

A lightweight tool that sanitizes AI-written shell commands into Windows compatible ones

Project description

win-cmd-fixer

License: MIT Python Version npm version

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 Filesdir "C:\Program Files")
  • Auto-add /d flag for cross-drive cd
  • Translate Unix command names to their Windows equivalents (cpcopy, lsdir, 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

MIT

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

win_cmd_fixer-0.2.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

win_cmd_fixer-0.2.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file win_cmd_fixer-0.2.1.tar.gz.

File metadata

  • Download URL: win_cmd_fixer-0.2.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for win_cmd_fixer-0.2.1.tar.gz
Algorithm Hash digest
SHA256 826abb698a24ba813e2ab41bba89ad4d1e9b8c6da525913b07f4f938e6710a5e
MD5 d48d911b3d625aed07f2f1f776e2f2ba
BLAKE2b-256 14c448225e6f64e82369ef412a4efd5e2c8a13e90fa98e649da305bcb38fd85c

See more details on using hashes here.

File details

Details for the file win_cmd_fixer-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: win_cmd_fixer-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for win_cmd_fixer-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5900a367c904d5122d63af5cd53f54e5befd82b85d744793ffb27fb9d561c6dd
MD5 e56f7bb844eb7ab2afdf8d0072f13a8a
BLAKE2b-256 83a8d9a293a726e37a91752d71c3f377f3d261964504ac2294d8611b6e6ada4d

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