Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env zsh
- set -euo pipefail
- ### ===== SETTINGS =====
- IDLE_MAX_SECS=300
- REPO_DIR="$HOME/path/to/your/repo" # or ~ if using ~/.claude/commands
- ### ===== ARGUMENTS =====
- if (( $# < 1 )); then
- echo "Usage: $0 <slash_command> [command_args...]" >&2
- exit 2
- fi
- SLASH_CMD="$1"
- shift
- SLASH_ARGS="${*:-}"
- ### ===== FUNCTIONS =====
- is_user_active() {
- local idle
- idle="$(ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}')"
- [[ -n "$idle" && "$idle" -lt "$IDLE_MAX_SECS" ]]
- }
- is_vpn_connected() {
- # ping github.paypal.com once, 2-second timeout, discard output
- ping -c 1 -W 2000 github.paypal.com >/dev/null 2>&1
- }
- ### ===== GATES =====
- is_user_active || exit 0
- is_vpn_connected || exit 0
- ### ===== RUN via Terminal so Touch ID can appear =====
- export REPO_DIR SLASH_CMD SLASH_ARGS
- osascript <<'APPLESCRIPT'
- on run
- set repoDir to system attribute "REPO_DIR"
- set slashCmd to system attribute "SLASH_CMD"
- set slashArgs to system attribute "SLASH_ARGS"
- tell application "Terminal"
- activate
- do script "exec /bin/zsh -l -c 'set -euo pipefail; cd " & repoDir & ";
- sudo -v; # Touch ID prompt (pam_tid) will appear here
- /usr/local/bin/claude-slash " & slashCmd & " " & quoted form of slashArgs & ";
- echo; echo \"[✔] Job finished. You can close this window.\"'"
- end tell
- end run
- APPLESCRIPT
Advertisement
Add Comment
Please, Sign In to add comment