gseguin

run-claude-job.zsh

Aug 13th, 2025 (edited)
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.39 KB | None | 0 0
  1. #!/usr/bin/env zsh
  2. set -euo pipefail
  3.  
  4. ### ===== SETTINGS =====
  5. IDLE_MAX_SECS=300
  6. REPO_DIR="$HOME/path/to/your/repo"   # or ~ if using ~/.claude/commands
  7.  
  8. ### ===== ARGUMENTS =====
  9. if (( $# < 1 )); then
  10.   echo "Usage: $0 <slash_command> [command_args...]" >&2
  11.   exit 2
  12. fi
  13.  
  14. SLASH_CMD="$1"
  15. shift
  16. SLASH_ARGS="${*:-}"
  17.  
  18. ### ===== FUNCTIONS =====
  19. is_user_active() {
  20.   local idle
  21.   idle="$(ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}')"
  22.   [[ -n "$idle" && "$idle" -lt "$IDLE_MAX_SECS" ]]
  23. }
  24.  
  25. is_vpn_connected() {
  26.   # ping github.paypal.com once, 2-second timeout, discard output
  27.   ping -c 1 -W 2000 github.paypal.com >/dev/null 2>&1
  28. }
  29.  
  30. ### ===== GATES =====
  31. is_user_active || exit 0
  32. is_vpn_connected || exit 0
  33.  
  34. ### ===== RUN via Terminal so Touch ID can appear =====
  35. export REPO_DIR SLASH_CMD SLASH_ARGS
  36.  
  37. osascript <<'APPLESCRIPT'
  38. on run
  39.   set repoDir to system attribute "REPO_DIR"
  40.   set slashCmd to system attribute "SLASH_CMD"
  41.   set slashArgs to system attribute "SLASH_ARGS"
  42.  
  43.   tell application "Terminal"
  44.     activate
  45.     do script "exec /bin/zsh -l -c 'set -euo pipefail; cd " & repoDir & ";
  46.       sudo -v;  # Touch ID prompt (pam_tid) will appear here
  47.       /usr/local/bin/claude-slash " & slashCmd & " " & quoted form of slashArgs & ";
  48.       echo; echo \"[✔] Job finished. You can close this window.\"'"
  49.   end tell
  50. end run
  51. APPLESCRIPT
  52.  
Advertisement
Add Comment
Please, Sign In to add comment