powershell-shell-detection
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.
What this skill does
# PowerShell Shell Detection & Cross-Shell Compatibility
Critical guidance for distinguishing between PowerShell and Git Bash/MSYS2 shells on Windows, with shell-specific path handling and compatibility notes.
## Shell Detection Priority (Windows)
When working on Windows, correctly identifying the shell environment is crucial for proper path handling and command execution.
### Detection Order (Most Reliable First)
1. **process.env.PSModulePath** (PowerShell specific)
2. **process.env.MSYSTEM** (Git Bash/MinGW specific)
3. **process.env.WSL_DISTRO_NAME** (WSL specific)
4. **uname -s output** (Cross-shell, requires execution)
## PowerShell Detection
### Primary Indicators
**PSModulePath (Most Reliable):**
```powershell
# 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:**
```powershell
# 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+)
```
### Shell Type Detection in Scripts
```powershell
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
```
## Git Bash / MSYS2 Detection
### Primary Indicators
**MSYSTEM Environment Variable (Most Reliable):**
```bash
# 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:**
```bash
# 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
```
## Cross-Shell Compatibility on Windows
### Critical Differences
| 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 |
### Path Handling: PowerShell vs Git Bash
**PowerShell Path Handling:**
```powershell
# 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:**
```bash
# 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)
```
## Automatic Path Conversion in Git Bash (CRITICAL)
Git Bash/MSYS2 automatically converts paths in certain scenarios, which can cause issues:
### What Triggers Conversion
```bash
# 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
```
### What's Exempt from Conversion
```bash
# 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
```
### Disabling Path Conversion
```bash
# 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
```
## When to Use PowerShell vs Git Bash on Windows
### Use PowerShell When:
- ✅ **Windows-specific tasks** - Registry, WMI, Windows services
- ✅ **Azure/Microsoft 365 automation** - Az, Microsoft.Graph modules
- ✅ **Module ecosystem** - Leverage PSGallery modules
- ✅ **Object-oriented pipelines** - Rich object manipulation
- ✅ **Native Windows integration** - Built into Windows
- ✅ **CI/CD with pwsh** - GitHub Actions, Azure DevOps
- ✅ **Cross-platform scripting** - PowerShell 7 works on Linux/macOS
**Example PowerShell Scenario:**
```powershell
# Azure VM management with Az module
Connect-AzAccount
Get-AzVM -ResourceGroupName "Production" |
Where-Object {$_.PowerState -eq "VM running"} |
Stop-AzVM -Force
```
### Use Git Bash When:
- ✅ **Unix tool compatibility** - sed, awk, grep, find
- ✅ **Git operations** - Native Git command-line experience
- ✅ **POSIX script execution** - Running Linux shell scripts
- ✅ **Cross-platform shell scripts** - Bash scripts from Linux/macOS
- ✅ **Text processing** - Unix text utilities (sed, awk, cut)
- ✅ **Development workflows** - Node.js, Python, Ruby with Unix tools
**Example Git Bash Scenario:**
```bash
# Git workflow with Unix tools
git log --oneline | grep -i "feature" | awk '{print $1}' |
xargs git show --stat
```
## Shell-Aware Script Design
### Detect and Adapt (PowerShell)
```powershell
# 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 and Adapt (Bash)
```bash
# 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"
```
## Environment VariRelated in Ads & Marketing
ads
IncludedMulti-platform paid advertising audit and optimization skill. Analyzes Google, Meta, YouTube, LinkedIn, TikTok, Microsoft, and Apple Ads. 250+ checks with scoring, parallel agents, industry templates, and AI creative generation.
banana
IncludedAI image generation Creative Director powered by Google Gemini Nano Banana models. Use this skill for ANY request involving image creation, editing, visual asset production, or creative direction. Triggers on: generate an image, create a photo, edit this picture, design a logo, make a banner, visual for my anything, and all /banana commands. Handles text-to-image, image editing, multi-turn creative sessions, batch workflows, and brand presets.
rpg-migration-analyzer
IncludedAnalyzes legacy RPG (Report Program Generator) programs from AS/400 and IBM i systems for migration to modern Java applications. Extracts business logic from RPG III/IV/ILE source code, identifies data structures (D-specs), file operations (F-specs), program dependencies (CALLB/CALLP), and converts RPG constructs to Java equivalents. Generates migration reports, complexity estimates, and Java implementation strategies with POJO classes, JPA entities, and service methods. Use when modernizing AS/400 or IBM i legacy systems, analyzing RPG source files (.rpg, .rpgle, .RPGLE), converting RPG to Java, mapping data specifications to Java classes, planning legacy system migration, or when user mentions RPG analysis, Report Program Generator, RPG III/IV/ILE, AS/400 modernization, IBM i migration, packed decimal conversion, or mainframe application rewrite.
brand-library-architect
IncludedBuild a complete brand library for a product — visual asset render pipeline, brand documentation set (BRAND, COPY, MANIFESTO, BIOS, FAQ, GLOSSARY, TONE, PRICING), open-source convention files (README, CONTRIBUTING, SECURITY, CODE_OF_CONDUCT), and a self-contained press kit. This skill should be used when the user asks to "build a brand library / brand kit / press kit / brand assets" for a product, "set up a brand library workflow," "create a positioning manifesto plus visual identity," or any combination of brand documentation + visual asset pipeline. Apply phase-by-phase or run end-to-end. Templates are product-agnostic and use {{TOKEN}} placeholders the skill prompts the user to fill.
writing-tech-post
IncludedAuthors engineering blog posts end-to-end: launch deep-dives, incident postmortems, architecture migrations, performance case studies, tutorials, AI/agent system writeups, security disclosures, and research-to-product translations. Picks the correct archetype, plans the abstraction ladder, enforces an evidence cadence (diagrams, benchmarks, profiles, traces, code, ablations), tunes voice against publisher house styles (Datadog, Vercel, GitHub, AWS, Meta, Cloudflare, Jane Street), and runs a pre-publish gate for narrative momentum and disclosure ethics. Use when drafting a new engineering post, restructuring a draft that feels flat, deciding which evidence form belongs where, validating that depth and product context are balanced, or preparing a postmortem, migration, or performance narrative for external publication. Do not use for API reference documentation, README authoring, marketing copy, release notes, generic SEO content, ghost-written executive thought leadership, or non-engineering long-form essays.
blog-google
IncludedGoogle API integration for blog performance: PageSpeed Insights, CrUX Core Web Vitals with 25-week history, Search Console performance, URL Inspection, Indexing API, GA4 organic traffic, NLP entity analysis for E-E-A-T, YouTube video search for embedding, and Google Ads Keyword Planner. Progressive feature availability based on credential tier (API key, OAuth/service account, GA4, Ads). Shares config with claude-seo at ~/.config/claude-seo/google-api.json. Use when user says "google data", "page speed", "core web vitals", "search console", "indexation", "GA4", "keyword research", "nlp entities", "blog performance", "youtube search", "google api setup".