|
| 1 | +# PSCommandHelper |
| 2 | + |
| 3 | +> Learn PowerShell by doing. When you type a bash command that doesn't exist in PowerShell, PSCommandHelper suggests the PowerShell equivalent — with an explanation. |
| 4 | +
|
| 5 | +## What it does |
| 6 | + |
| 7 | +When you type a bash/Linux command in PowerShell 7 that doesn't resolve (like `rm -rf`, `grep`, `curl`, etc.), PSCommandHelper intercepts the error and shows you: |
| 8 | + |
| 9 | +``` |
| 10 | +──────────────────────────────────────────────────────────── |
| 11 | + 💡 PSCommandHelper |
| 12 | +
|
| 13 | + You typed: rm -rf |
| 14 | + Try this: Remove-Item -Recurse -Force |
| 15 | +
|
| 16 | + Remove-Item deletes files/folders. -Recurse handles subdirectories, -Force skips confirmation. |
| 17 | +
|
| 18 | + Example: |
| 19 | + > Remove-Item ./build -Recurse -Force |
| 20 | +──────────────────────────────────────────────────────────── |
| 21 | +``` |
| 22 | + |
| 23 | +It **does not** run the command for you — the goal is to help you learn, not to auto-correct. |
| 24 | + |
| 25 | +## Installation |
| 26 | + |
| 27 | +### Quick install |
| 28 | + |
| 29 | +```powershell |
| 30 | +git clone <repo-url> powershell-helper |
| 31 | +cd powershell-helper |
| 32 | +.\install.ps1 |
| 33 | +``` |
| 34 | + |
| 35 | +This copies the module to your `Documents\PowerShell\Modules` folder and adds it to your `$PROFILE`. |
| 36 | + |
| 37 | +### Manual install |
| 38 | + |
| 39 | +1. Copy the `PSCommandHelper` folder to a directory in your `$env:PSModulePath` |
| 40 | +2. Add these lines to your `$PROFILE`: |
| 41 | + |
| 42 | +```powershell |
| 43 | +Import-Module PSCommandHelper |
| 44 | +Enable-PSCommandHelper |
| 45 | +``` |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +Once installed, just use PowerShell normally. When you type a bash command that isn't recognized, you'll see a helpful suggestion. |
| 50 | + |
| 51 | +### Browse all mappings |
| 52 | + |
| 53 | +```powershell |
| 54 | +Get-CommandMapping |
| 55 | +``` |
| 56 | + |
| 57 | +### Search for a specific command |
| 58 | + |
| 59 | +```powershell |
| 60 | +Get-CommandMapping -Search "grep" |
| 61 | +Get-CommandMapping -Search "file" |
| 62 | +``` |
| 63 | + |
| 64 | +### Temporarily disable |
| 65 | + |
| 66 | +```powershell |
| 67 | +Disable-PSCommandHelper |
| 68 | +``` |
| 69 | + |
| 70 | +### Re-enable |
| 71 | + |
| 72 | +```powershell |
| 73 | +Enable-PSCommandHelper |
| 74 | +``` |
| 75 | + |
| 76 | +## Covered commands |
| 77 | + |
| 78 | +The built-in mapping table covers **75+ bash commands** across these categories: |
| 79 | + |
| 80 | +| Category | Examples | |
| 81 | +|----------|----------| |
| 82 | +| **File operations** | `rm`, `cp`, `mv`, `mkdir`, `touch`, `cat`, `ls`, `find`, `chmod`, `ln -s` | |
| 83 | +| **Text processing** | `grep`, `sed`, `awk`, `head`, `tail`, `wc`, `sort`, `uniq`, `cut`, `tr`, `diff` | |
| 84 | +| **System/process** | `ps`, `kill`, `top`, `df`, `du`, `env`, `export`, `which`, `whoami` | |
| 85 | +| **Networking** | `curl`, `wget`, `ping`, `ifconfig`, `netstat`, `ssh`, `scp`, `nslookup` | |
| 86 | +| **Shell/misc** | `echo`, `clear`, `history`, `alias`, `man`, `sudo`, `source`, `tar`, `zip` | |
| 87 | +| **Piping/redirection** | `> file`, `>> file`, `2>&1`, `/dev/null` | |
| 88 | + |
| 89 | +## Requirements |
| 90 | + |
| 91 | +- **PowerShell 7.0+** (uses `CommandNotFoundAction` which is not available in Windows PowerShell 5.1) |
| 92 | + |
| 93 | +## Running tests |
| 94 | + |
| 95 | +```powershell |
| 96 | +Invoke-Pester ./tests/PSCommandHelper.Tests.ps1 |
| 97 | +``` |
| 98 | + |
| 99 | +## How it works |
| 100 | + |
| 101 | +PowerShell 7 exposes the `$ExecutionContext.InvokeCommand.CommandNotFoundAction` event. When the shell can't find a command by name, this event fires **before** the error is shown. PSCommandHelper registers a handler that: |
| 102 | + |
| 103 | +1. Receives the unrecognized command name |
| 104 | +2. Looks it up in a hashtable of bash → PowerShell mappings |
| 105 | +3. Displays a colorful, educational suggestion |
| 106 | +4. Lets the original error propagate (so you know the command didn't run) |
| 107 | + |
| 108 | +## License |
| 109 | + |
| 110 | +MIT |
0 commit comments