blowviate

← back to all entries

tuesday, december 2, 2025

Today's Daily Double is... a snippet!

(this is pulled from a larger document outlining the Raycast scripts I have set up. I set these up as Raycast Utilities snippets but you can do whatever you want with it, that is not my job)

👶 Git pull children 👶

(you provide parent directory name, then raycast pulls main for every child directory that is a Git repository and runs pnpm install )

( basically it saves a couple of steps when you have to get all of the up-to-date things for a number of repos and you co-locate those repos in one parent directory )

  • more detail
    • Raycast command (~/raycast-scripts/git- pull-children.sh) takes one required text input: a directory name or path.
    • It resolves the path (supports absolute, ~/, or names like ex. multiplatto under your home), verifies the folder exists, then finds every immediate child directory that has a .git folder.
    • For each repo it fetches origin/main, hard-resets local changes, ensures the local main branch exists (creating it from origin/main if needed), pulls origin/main (--ff-only), and runs pnpm install when package.json is present and pnpm is on PATH.
    • Output is shown inline in Raycast (schemaVersion 1, fullOutput mode) so teammates see the per‑repo progress / warnings at a glance.
    • To use: open Raycast (⌥ + Space) → “Git Pull Children” → type the parent directory (e.g., tellytelly/multiplatto) → press Enter; share the script by telling others to drop it into their Raycast Scripts folder and import it via Raycast’s Extensions → Scripts
#!/bin/bash

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Git Pull Children
# @raycast.mode fullOutput
# @raycast.packageName Repo Tools
# @raycast.description Pull main for each child git repo and run pnpm install
# @raycast.author Callum
# @raycast.icon 🪄
# @raycast.argument1 { "type": "text", "placeholder": "Directory name or path", "optional": false }

set -uo pipefail
export PATH="/opt/homebrew/bin:/usr/local/bin:$HOME/.local/bin:$PATH"

input_dir="${1:-}"

if [[ -z "$input_dir" ]]; then
  echo "❌ Please provide a directory name or path."
  exit 1
fi

case "$input_dir" in
  ~*)
    target_dir="${input_dir/#\~/$HOME}"
    ;;
  /*)
    target_dir="$input_dir"
    ;;
  *)
    if [[ -d "$PWD/$input_dir" ]]; then
      target_dir="$PWD/$input_dir"
    else
      target_dir="$HOME/$input_dir"
    fi
    ;;
esac

if [[ -n "$input_dir" && ! -d "$target_dir" ]]; then
  search_name="$(basename "$input_dir")"
  candidate=$(find "$HOME" -maxdepth 4 -type d -name "$search_name" 2>/dev/null | head -n 1)
  if [[ -n "$candidate" ]]; then
    target_dir="$candidate"
  fi
fi

if [[ ! -d "$target_dir" ]]; then
  echo "❌ Directory not found: $target_dir"
  exit 1
fi

echo "🔍 Searching for git repositories under: $target_dir"
echo ""

shopt -s nullglob
found_any=false

for repo_dir in "$target_dir"/*/; do
  if [[ ! -d "${repo_dir}/.git" ]]; then
    continue
  fi

  found_any=true
  repo_name=$(basename "$repo_dir")
  echo "=== 📁 $repo_name ==="

  (
    set -e
    cd "$repo_dir"

    if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
      echo "  ⚠️ Not a valid git repo, skipping"
      exit 0
    fi

    echo "  📡 Fetching origin/main"
    if ! git fetch origin main >/dev/null 2>&1; then
      echo "  ⚠️ Failed to fetch origin/main, skipping"
      exit 0
    fi

    echo "  🧹 Resetting local changes"
    git reset --hard HEAD >/dev/null

    if git show-ref --verify --quiet refs/heads/main; then
      git checkout main >/dev/null 2>&1 || true
    elif git show-ref --verify --quiet refs/remotes/origin/main; then
      git checkout -b main origin/main >/dev/null 2>&1
    else
      echo "  ⚠️ No main branch found locally or remotely, skipping"
      exit 0
    fi

    echo "  ⬇️ Pulling origin/main"
    if ! git pull origin main --ff-only; then
      echo "  ⚠️ git pull failed"
      exit 0
    fi

    if command -v pnpm >/dev/null 2>&1 && [[ -f package.json ]]; then
      echo "  📦 pnpm install"
      if ! pnpm install >/dev/null; then
        echo "  ⚠️ pnpm install failed"
      fi
    else
      echo "  📦 pnpm install skipped (pnpm missing or no package.json)"
    fi
  )

  echo ""
done

if [[ "$found_any" == false ]]; then
  echo "ℹ️ No child git repositories found."
fi

echo "✅ Completed."

demooooo

script.gitPullChildren.mov

https://drive.google.com/file/d/1ou4NU3YkVBz5CVmT0x4DZa_cxoQRVeSj/view?usp=sharing

comments

loading comments...