#!/bin/bash # push: push all git repos in ~/dev that have your own remotes # usage: push -- direct push of committed changes # push --smart -- use claude to commit+push intelligently LOGFILE="$HOME/.local/share/dev-push.log" DEVDIR="$HOME/dev" smart=0 [ "$1" = "--smart" ] && smart=1 if [ "$smart" -eq 1 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') — push --smart: attempting claude" >> "$LOGFILE" timeout 120 claude --dangerously-skip-permissions -p \ "Run push for me. For each git repo in ~/dev that is owned by krisyotam on GitHub, check if there are unpushed commits or uncommitted changes. If there are uncommitted changes, create a sensible commit and push. If already up to date, skip it. Be efficient — only report repos where you took action." \ --allowedTools "Bash(command:*)" \ 2>> "$LOGFILE" if [ $? -eq 0 ]; then exit 0 fi echo "$(date '+%Y-%m-%d %H:%M:%S') — claude unavailable, falling back to direct push" >> "$LOGFILE" fi echo "$(date '+%Y-%m-%d %H:%M:%S') — push starting" >> "$LOGFILE" for d in "$DEVDIR"/*/; do [ -d "$d/.git" ] || continue name="$(basename "$d")" remote_url="$(git -C "$d" remote get-url origin 2>/dev/null)" [ -z "$remote_url" ] && continue echo "$remote_url" | grep -qiE 'krisyotam|krisportfolio' || continue local_ref="$(git -C "$d" rev-parse HEAD 2>/dev/null)" tracking="$(git -C "$d" rev-parse '@{u}' 2>/dev/null)" [ "$local_ref" = "$tracking" ] 2>/dev/null && continue echo "$(date '+%Y-%m-%d %H:%M:%S') — pushing $name" >> "$LOGFILE" git -C "$d" push 2>> "$LOGFILE" && \ echo "$(date '+%Y-%m-%d %H:%M:%S') — $name pushed OK" >> "$LOGFILE" || \ echo "$(date '+%Y-%m-%d %H:%M:%S') — $name FAILED" >> "$LOGFILE" done echo "$(date '+%Y-%m-%d %H:%M:%S') — push complete" >> "$LOGFILE"