MCP HubMCP Hub
스킬 목록으로 돌아가기

cross-platform-compat

vamseeachanta
업데이트됨 Today
16 조회
3
2
3
GitHub에서 보기
기타bashcross-platformwindowsgit-bashportablebcpython3nproc

정보

이 스킬은 Windows Git Bash, Linux, macOS에서 이식 가능한 스크립트 작성을 위한 표준 bash 패턴과 명령어 대체 방법을 제공합니다. OS 감지 기능과 `bc`, `python3`, `nproc`, `sed -i` 등 주요 호환성 문제 명령어에 대한 수정 사항을 포함합니다. 다양한 개발 환경에서 안정적으로 실행되어야 하는 스크립트를 작성하거나 검토할 때 활용하세요.

빠른 설치

Claude Code

추천
기본
npx skills add vamseeachanta/workspace-hub
플러그인 명령대체
/plugin add https://github.com/vamseeachanta/workspace-hub
Git 클론대체
git clone https://github.com/vamseeachanta/workspace-hub.git ~/.claude/skills/cross-platform-compat

Claude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요

문서

Cross-Platform Bash Compatibility

Canonical replacement patterns for shell constructs that break on Windows Git Bash, macOS, or both. Always use these patterns in workspace-hub scripts.

Quick Reference — Replacement Table

Broken PatternBreaks OnPortable Replacement
echo "$a < $b" | bc -lGit Bash (no bc)awk "BEGIN {print ($a < $b) ? 1 : 0}"
echo "scale=2; $a / $b" | bcGit Bashawk "BEGIN {printf \"%.2f\", $a / $b}"
python3 script.pyWindows$PYTHON script.py (use resolver below)
nprocGit Bashnproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1
sed -i "s/..."macOSsed -i.bak "s/..." && rm file.bak
git add missing/dir/all (set -e)Guard with [[ -d path ]] && git add path
date -v-1d +%Y%m%dLinux/Git Bashdate -d "yesterday" +%Y%m%d 2>/dev/null || date -v-1d +%Y%m%d

Patterns in Detail

Float Comparison Without bc

# bc not available on Git Bash Windows
# BAD:  if (( $(echo "$score < 0.6" | bc -l) )); then
# GOOD: awk-based (works everywhere)
float_lt() {
    awk "BEGIN {exit !($1 < $2)}"
}
if float_lt "$score" "0.6"; then echo "below threshold"; fi

# Or integer-multiply trick (score 0.0-1.0 → multiply by 10):
score_int=$(awk "BEGIN {print int($score * 10)}")
if (( score_int < 6 )); then echo "below threshold"; fi

Division / Percentages Without bc

# BAD:  pct=$(echo "scale=1; $done * 100 / $total" | bc)
# GOOD:
pct=$(awk "BEGIN {printf \"%.1f\", $done * 100 / $total}")

Platform-Aware Python Resolver

# Add once at top of script; use $PYTHON everywhere else
resolve_python() {
    if command -v python3 &>/dev/null; then
        echo "python3"
    elif command -v python &>/dev/null && python -c "import sys; assert sys.version_info >= (3,8)" 2>/dev/null; then
        echo "python"
    else
        echo "uv run --no-project python"
    fi
}
PYTHON=$(resolve_python)
# Usage: $PYTHON script.py  OR  $PYTHON -c "..."

CPU Count Without nproc

cpu_count() {
    nproc 2>/dev/null \
        || getconf _NPROCESSORS_ONLN 2>/dev/null \
        || sysctl -n hw.ncpu 2>/dev/null \
        || echo "1"
}
MAX_PARALLEL=$(cpu_count)

Safe git add (Skip Missing Paths)

# BAD:  git add .claude/state/candidates/ .claude/state/corrections/
#       ^ fatal error + silent skip when dirs don't exist
# GOOD:
git_add_if_exists() {
    local staged=0
    for path in "$@"; do
        if [[ -e "$path" ]]; then
            git add "$path" && staged=1
        fi
    done
    return $(( staged == 0 ? 1 : 0 ))
}
if git_add_if_exists \
    .claude/state/candidates/ \
    .claude/state/corrections/ \
    .claude/state/patterns/; then
    git commit -m "chore: session learnings from $(hostname)"
fi

Portable sed -i (Linux + macOS)

# BAD:  sed -i "s/old/new/" file      # macOS: requires backup extension
# GOOD:
portable_sed_i() {
    local expr="$1" file="$2"
    if sed --version 2>/dev/null | grep -q GNU; then
        sed -i "$expr" "$file"          # GNU sed (Linux, Git Bash)
    else
        sed -i '' "$expr" "$file"       # BSD sed (macOS)
    fi
}

OS Detection

# From bash-script-framework utils.sh — canonical pattern:
get_os() {
    case "$(uname -s)" in
        Linux*)              echo "linux" ;;
        Darwin*)             echo "macos" ;;
        CYGWIN*|MINGW*|MSYS*) echo "windows" ;;
        *)                   echo "unknown" ;;
    esac
}

IS_WINDOWS=false
[[ "$(get_os)" == "windows" ]] && IS_WINDOWS=true

Startup Compatibility Check

Add to scripts that must run cross-platform:

check_deps() {
    local missing=()
    # jq is required for JSON parsing
    command -v jq &>/dev/null || missing+=("jq (install: https://jqlang.github.io/jq/)")
    # Report clearly — never silently degrade
    if [[ ${#missing[@]} -gt 0 ]]; then
        echo "ERROR: missing required tools:" >&2
        printf '  - %s\n' "${missing[@]}" >&2
        exit 1
    fi
}
check_deps

Anti-Patterns (Never Use in Cross-Platform Scripts)

# NEVER: bc for arithmetic           → use awk
# NEVER: python3 hardcoded           → use $PYTHON resolver
# NEVER: nproc without fallback      → use cpu_count()
# NEVER: git add path/ without guard → use git_add_if_exists()
# NEVER: 2>/dev/null || echo "1"     → hides errors, returns wrong fallback
#         ^-- this is the "silent failure" anti-pattern

WRK Reference

  • WRK-1117: Fixed comprehensive-learning.sh Windows push + bc in guard.sh
  • WRK-1118: Systematic sweep of all bc/python3/nproc across 150+ script lines

GitHub 저장소

vamseeachanta/workspace-hub
경로: .claude/skills/_core/bash/cross-platform-compat

연관 스킬

moai-domain-mobile-app

테스팅

This Claude Skill provides enterprise mobile development expertise for React Native 0.76+, Flutter 3.24+, and Capacitor 6.x cross-platform frameworks. It focuses on implementing robust patterns, comprehensive testing, and CI/CD automation for production-ready mobile applications. Use this skill for guidance on mobile architecture, performance optimization, and deployment strategies.

스킬 보기

rust-desktop-applications

개발

This skill helps developers build cross-platform desktop applications using Rust, primarily through the Tauri framework or native GUI alternatives. It's ideal for creating performant apps requiring system integration, small bundle sizes, and high performance. The guidance covers project setup, IPC, state management, and cross-platform testing and deployment.

스킬 보기

moai-domain-mobile-app

테스팅

This Claude Skill provides enterprise mobile development expertise for React Native 0.76+, Flutter 3.24+, and Capacitor 6.x frameworks. It focuses on cross-platform patterns, testing strategies, and CI/CD automation for production-ready applications. Use this skill for guidance on modern mobile development workflows and deployment best practices.

스킬 보기

moai-lang-flutter

기타

This Claude Skill specializes in Flutter 3.24+ and Dart 3.5+ development, focusing on modern state management with Riverpod and declarative navigation using go_router. It is designed for building cross-platform mobile, desktop, and web applications. Use this skill for guidance on adaptive layouts, Dart's latest language features, and integrating platform-specific functionality.

스킬 보기