gseguin

claude-slash

Aug 13th, 2025 (edited)
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.86 KB | None | 0 0
  1. #!/usr/bin/env zsh
  2. set -euo pipefail
  3.  
  4. if (( $# < 1 )); then
  5.   print -u2 "usage: claude-slash <command> [args…]"
  6.   exit 2
  7. fi
  8.  
  9. CMD="$1"; shift || true
  10. ARGS="${*:-}"
  11.  
  12. # project first, then global
  13. if [[ -f ".claude/commands/${CMD}.md" ]]; then
  14.   FILE=".claude/commands/${CMD}.md"
  15. elif [[ -f "$HOME/.claude/commands/${CMD}.md" ]]; then
  16.   FILE="$HOME/.claude/commands/${CMD}.md"
  17. else
  18.   print -u2 "Command '${CMD}' not found in .claude/commands or ~/.claude/commands"
  19.   exit 1
  20. fi
  21.  
  22. # strip YAML frontmatter (--- … ---)
  23. CONTENT="$(awk 'BEGIN{p=1} /^---$/{c++} c==1{next} c>1{p=1} {if(p) print}' "$FILE")"
  24.  
  25. # inject $ARGUMENTS placeholder
  26. PROMPT="${CONTENT//\$ARGUMENTS/$ARGS}"
  27.  
  28. # run in print mode; allow Bash snippets if your command uses !`…`
  29. claude -p --output-format text \
  30.   --allowedTools "Bash(*:*)" \
  31.   --dangerously-skip-permissions \
  32.   "$PROMPT"
  33.  
Advertisement
Add Comment
Please, Sign In to add comment