Last active
April 17, 2026 15:22
-
-
Save styledev/10ef04dc4402a75f2ab4d9751e0a419f to your computer and use it in GitHub Desktop.
Universal Run Command for Zshrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Universal project run function | |
| # Checks for a Runfile first, then auto-detects by project type. | |
| # Save this file to ~/.zsh_functions and then add the following to the end of your ~/.zshrc file: | |
| # source ~/.zsh_functions | |
| run() { | |
| # 1. Explicit Runfile | |
| if [[ -f "Runfile" ]]; then | |
| echo "▶ Running via Runfile" | |
| local cmd | |
| cmd=$(cat Runfile) | |
| eval "$cmd" | |
| return | |
| fi | |
| # 2. run.sh / start.sh | |
| if [[ -x "run.sh" ]]; then | |
| echo "▶ Running ./run.sh" | |
| ./run.sh | |
| return | |
| fi | |
| if [[ -x "start.sh" ]]; then | |
| echo "▶ Running ./start.sh" | |
| ./start.sh | |
| return | |
| fi | |
| # 3. Makefile — prefer 'run' target, fall back to 'start' | |
| if [[ -f "Makefile" ]]; then | |
| if grep -qE '^run:' Makefile; then | |
| echo "▶ Running make run" | |
| make run | |
| return | |
| fi | |
| if grep -qE '^start:' Makefile; then | |
| echo "▶ Running make start" | |
| make start | |
| return | |
| fi | |
| fi | |
| # 4. package.json — detect yarn vs pnpm vs npm, prefer 'dev' script, fall back to 'start' | |
| if [[ -f "package.json" ]]; then | |
| local pkg_cmd="npm" | |
| [[ -f "yarn.lock" ]] && pkg_cmd="yarn" | |
| [[ -f "pnpm-lock.yaml" ]] && pkg_cmd="pnpm" | |
| if node -e "process.exit(require('./package.json').scripts?.dev ? 0 : 1)" 2>/dev/null; then | |
| echo "▶ Running $pkg_cmd run dev" | |
| $pkg_cmd run dev | |
| return | |
| fi | |
| if node -e "process.exit(require('./package.json').scripts?.start ? 0 : 1)" 2>/dev/null; then | |
| echo "▶ Running $pkg_cmd start" | |
| $pkg_cmd start | |
| return | |
| fi | |
| fi | |
| # Nothing found | |
| echo "✗ No run target found. Checked:" | |
| echo " Runfile · run.sh · start.sh · Makefile (run/start) · package.json via yarn/pnpm/npm (dev/start)" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment