plugins/powershell-master/skills/powershell-shell-detection/SKILL.md
PowerShell vs Git Bash/MSYS2 shell detection and cross-shell compatibility on Windows. PROACTIVELY activate for: (1) detecting whether script runs under PowerShell, pwsh, Git Bash, or cmd, (2) shell-specific path handling, (3) MSYS_NO_PATHCONV when calling Windows binaries from Git Bash, (4) PowerShell from Git Bash and vice versa, (5) line-ending differences (CRLF vs LF), (6) environment variable differences (env: VAR vs VAR vs percent VAR percent), (7) calling PowerShell scripts (.ps1) from bash and bash scripts from PowerShell, (8) profile loading differences. Provides: shell-detection one-liners, path-conversion helpers, env-var portability patterns, and cross-shell invocation recipes.
npx skillsauth add JosiahSiegel/claude-plugin-marketplace powershell-shell-detectionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Critical guidance for distinguishing between PowerShell and Git Bash/MSYS2 shells on Windows, with shell-specific path handling and compatibility notes.
When working on Windows, correctly identifying the shell environment is crucial for proper path handling and command execution.
PSModulePath (Most Reliable):
# PowerShell detection
if ($env:PSModulePath) {
Write-Host "Running in PowerShell"
# PSModulePath contains 3+ paths separated by semicolons
$env:PSModulePath -split ';'
}
# Check PowerShell version
$PSVersionTable.PSVersion
# Output: 7.5.4 (PowerShell 7) or 5.1.x (Windows PowerShell)
PowerShell-Specific Variables:
# These only exist in PowerShell
$PSVersionTable # Version info
$PSScriptRoot # Script directory
$PSCommandPath # Script full path
$IsWindows # Platform detection (PS 7+)
$IsLinux # Platform detection (PS 7+)
$IsMacOS # Platform detection (PS 7+)
function Get-ShellType {
if ($PSVersionTable) {
return "PowerShell $($PSVersionTable.PSVersion)"
}
elseif ($env:PSModulePath -and ($env:PSModulePath -split ';').Count -ge 3) {
return "PowerShell (detected via PSModulePath)"
}
else {
return "Not PowerShell"
}
}
Get-ShellType
MSYSTEM Environment Variable (Most Reliable):
# Bash detection in Git Bash/MSYS2
if [ -n "$MSYSTEM" ]; then
echo "Running in Git Bash/MSYS2: $MSYSTEM"
fi
# MSYSTEM values:
# MINGW64 - Native Windows 64-bit environment
# MINGW32 - Native Windows 32-bit environment
# MSYS - POSIX-compliant build environment
Secondary Detection Methods:
# Using OSTYPE (Bash-specific)
case "$OSTYPE" in
msys*) echo "MSYS/Git Bash" ;;
cygwin*) echo "Cygwin" ;;
linux*) echo "Linux" ;;
darwin*) echo "macOS" ;;
esac
# Using uname (Most portable)
case "$(uname -s)" in
MINGW64*) echo "Git Bash 64-bit" ;;
MINGW32*) echo "Git Bash 32-bit" ;;
MSYS*) echo "MSYS" ;;
CYGWIN*) echo "Cygwin" ;;
Linux*) echo "Linux" ;;
Darwin*) echo "macOS" ;;
esac
| Aspect | PowerShell | Git Bash/MSYS2 |
|--------|-----------|----------------|
| Environment Variable | $env:VARIABLE | $VARIABLE |
| Path Separator | ; (semicolon) | : (colon) |
| Path Style | C:\Windows\System32 | /c/Windows/System32 |
| Home Directory | $env:USERPROFILE | $HOME |
| Temp Directory | $env:TEMP | /tmp |
| Command Format | Get-ChildItem | ls (native command) |
| Aliases | PowerShell cmdlet aliases | Unix command aliases |
PowerShell Path Handling:
# Native Windows paths work directly
$path = "C:\Users\John\Documents"
Test-Path $path # True
# Forward slashes also work in PowerShell 7+
$path = "C:/Users/John/Documents"
Test-Path $path # True
# Use Join-Path for cross-platform compatibility
$configPath = Join-Path -Path $PSScriptRoot -ChildPath "config.json"
# Use [System.IO.Path] for advanced scenarios
$fullPath = [System.IO.Path]::Combine($home, "documents", "file.txt")
Git Bash Path Handling:
# Git Bash uses Unix-style paths
path="/c/Users/John/Documents"
test -d "$path" && echo "Directory exists"
# Automatic path conversion (CAUTION)
# Git Bash converts Unix-style paths to Windows-style
# /c/Users → C:\Users (automatic)
# Arguments starting with / may be converted unexpectedly
# Use cygpath for manual conversion
cygpath -u "C:\path" # → /c/path (Unix format)
cygpath -w "/c/path" # → C:\path (Windows format)
cygpath -m "/c/path" # → C:/path (Mixed format)
Git Bash/MSYS2 automatically converts paths in certain scenarios, which can cause issues:
# Leading forward slash triggers conversion
command /foo # Converts to C:\msys64\foo
# Path lists with colons
export PATH=/foo:/bar # Converts to C:\msys64\foo;C:\msys64\bar
# Arguments after dashes
command --path=/foo # Converts to --path=C:\msys64\foo
# Arguments with equals sign (variable assignments)
VAR=/foo command # NOT converted
# Drive specifiers
command C:/path # NOT converted
# Arguments with semicolons (already Windows format)
command "C:\foo;D:\bar" # NOT converted
# Double slashes (Windows switches)
command //e //s # NOT converted
# Disable ALL conversion (Git Bash)
export MSYS_NO_PATHCONV=1
command /foo # Stays as /foo
# Exclude specific patterns (MSYS2)
export MSYS2_ARG_CONV_EXCL="*" # Exclude everything
export MSYS2_ARG_CONV_EXCL="--dir=;/test" # Specific prefixes
Example PowerShell Scenario:
# Azure VM management with Az module
Connect-AzAccount
Get-AzVM -ResourceGroupName "Production" |
Where-Object {$_.PowerState -eq "VM running"} |
Stop-AzVM -Force
Example Git Bash Scenario:
# Git workflow with Unix tools
git log --oneline | grep -i "feature" | awk '{print $1}' |
xargs git show --stat
# Detect if running in PowerShell or Git Bash context
function Test-PowerShellContext {
return ($null -ne $PSVersionTable)
}
# Adapt path handling based on context
function Get-CrossPlatformPath {
param([string]$Path)
if (Test-PowerShellContext) {
# PowerShell: Use Join-Path
return (Resolve-Path $Path -ErrorAction SilentlyContinue).Path
}
else {
# Non-PowerShell context
Write-Warning "Not running in PowerShell. Path operations may differ."
return $Path
}
}
# Detect shell environment
detect_shell() {
if [ -n "$MSYSTEM" ]; then
echo "git-bash"
elif [ -n "$PSModulePath" ]; then
echo "powershell"
elif [ -n "$WSL_DISTRO_NAME" ]; then
echo "wsl"
else
echo "unix"
fi
}
# Adapt path handling
convert_path() {
local path="$1"
local shell_type=$(detect_shell)
case "$shell_type" in
git-bash)
# Convert Windows path to Unix style
echo "$path" | sed 's|\\|/|g' | sed 's|^\([A-Z]\):|/\L\1|'
;;
*)
echo "$path"
;;
esac
}
# Usage
shell_type=$(detect_shell)
echo "Running in: $shell_type"
| Variable | PowerShell | Git Bash | Purpose |
|----------|-----------|----------|---------|
| Username | $env:USERNAME | $USER | Current user |
| Home Directory | $env:USERPROFILE | $HOME | User home |
| Temp Directory | $env:TEMP | /tmp | Temporary files |
| Path List | $env:Path (; sep) | $PATH (: sep) | Executable paths |
| Shell Detection | $env:PSModulePath | $MSYSTEM | Shell identifier |
PowerShell accessing environment variables:
$env:PATH # Current PATH
$env:PSModulePath # PowerShell module paths
$env:MSYSTEM # Would be empty in PowerShell
[Environment]::GetEnvironmentVariable("PATH", "Machine") # System PATH
Git Bash accessing environment variables:
echo $PATH # Current PATH
echo $MSYSTEM # Git Bash: MINGW64, MINGW32, or MSYS
echo $PSModulePath # Would be empty in pure Bash
PowerShell:
# Find files modified in last 7 days
Get-ChildItem -Path "C:\Projects" -Recurse -File |
Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) } |
Select-Object FullName, LastWriteTime
Git Bash:
# Same operation in Git Bash
find /c/Projects -type f -mtime -7 -exec ls -lh {} \;
PowerShell:
# Stop all Chrome processes
Get-Process chrome -ErrorAction SilentlyContinue | Stop-Process -Force
Git Bash:
# Same operation in Git Bash
ps aux | grep chrome | awk '{print $2}' | xargs kill -9 2>/dev/null
PowerShell:
# Extract unique email addresses from logs
Get-Content "logs.txt" |
Select-String -Pattern '\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b' |
ForEach-Object { $_.Matches.Value } |
Sort-Object -Unique
Git Bash:
# Same operation in Git Bash
grep -oE '\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b' logs.txt |
sort -u
Problem: Command works in one shell but not another
# PowerShell
Get-Process # Works
# Git Bash
Get-Process # Command not found
Solution: Understand that PowerShell cmdlets don't exist in Bash. Use native commands or install PowerShell Core (pwsh) in Git Bash:
# Run PowerShell from Git Bash
pwsh -Command "Get-Process"
Problem: Paths don't work across shells
# Git Bash path
/c/Users/John/file.txt # Works in Bash
# PowerShell
Test-Path "/c/Users/John/file.txt" # May fail
Solution: Use cygpath for conversion or normalize paths:
# Convert to Windows format for PowerShell
win_path=$(cygpath -w "/c/Users/John/file.txt")
pwsh -Command "Test-Path '$win_path'"
Problem: ls, cd, cat behave differently
# PowerShell
ls # Actually runs Get-ChildItem
# Git Bash
ls # Runs native Unix ls command
Solution: Use full cmdlet names in PowerShell scripts:
# Instead of: ls
Get-ChildItem # Explicit cmdlet name
$PSScriptRoot for script-relative pathsJoin-Path or [IO.Path]::Combine() for paths$IsWindows, $IsLinux, $IsMacOS for platform detection$MSYSTEM for Git Bash detectioncygpath for path conversion when neededMSYS_NO_PATHCONV=1 to disable auto-conversion if needed/c/...) within BashLast Updated: October 2025
development
This skill should be used when the user asks to train, debug, scale, or improve ML models. PROACTIVELY activate for: (1) PyTorch, TensorFlow/Keras, JAX, Flax, Hugging Face Trainer/Accelerate training loops, (2) distributed training, DDP/FSDP/DeepSpeed, TPU/GPU setup, (3) mixed precision AMP/bf16, gradient accumulation, checkpointing, seeding, (4) overfitting, imbalance, loss functions, regularization, LR schedules, warmup, (5) memory optimization, gradient checkpointing, offloading, quantization-aware training. Provides: reproducible training best practices across deep learning and classical ML.
development
This skill should be used when the user asks to productionize, track, version, govern, monitor, or automate ML systems. PROACTIVELY activate for: (1) MLflow, Weights & Biases, Neptune, Comet, ClearML experiment tracking, (2) model registry, model versioning, artifact lineage, reproducibility, (3) Kubeflow, SageMaker Pipelines, Vertex AI Pipelines, Azure ML pipelines, Databricks workflows, (4) CI/CD, continuous training/evaluation, A/B tests, canary/shadow deployments, (5) drift detection, model monitoring, data validation, responsible AI governance. Provides: end-to-end MLOps architecture and operational safeguards.
development
This skill should be used when the user asks to optimize, export, serve, compress, or accelerate ML inference. PROACTIVELY activate for: (1) latency, throughput, p95/p99, batching, concurrency, KV cache, memory, or cost issues, (2) quantization INT8/INT4, GPTQ, AWQ, bitsandbytes, pruning, sparsity, distillation, (3) ONNX export, ONNX Runtime, TensorRT, TorchScript, torch.compile, XLA, OpenVINO, Core ML, TFLite, (4) Triton, TorchServe, TF Serving, BentoML, Seldon, KServe configuration, (5) edge deployment, CPU/GPU/TPU/Inferentia serving. Provides: hardware-aware inference optimization and safe benchmarking.
testing
This skill should be used when the user asks to tune hyperparameters, run sweeps, optimize search spaces, or use AutoML. PROACTIVELY activate for: (1) Optuna, Ray Tune, FLAML, AutoGluon, Hyperopt, Nevergrad, KerasTuner, W&B sweeps, (2) grid search, random search, Bayesian optimization, TPE, Gaussian processes, evolutionary search, (3) ASHA, Hyperband, successive halving, multi-fidelity optimization, population-based training, (4) learning-rate finder, batch-size search, early stopping, pruning, (5) reproducible sweep design and experiment analysis. Provides: budget-aware hyperparameter search strategy.