Skip to content

Instantly share code, notes, and snippets.

@grahama1970
Created March 4, 2025 19:59
Show Gist options
  • Save grahama1970/2ece1e1de40101d439bcc29daa61ba51 to your computer and use it in GitHub Desktop.
Save grahama1970/2ece1e1de40101d439bcc29daa61ba51 to your computer and use it in GitHub Desktop.
Raycast script for repomix
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Repomix Copy
# @raycast.mode compact
# @raycast.packageName Repomix Tools
# @raycast.icon clipboard
# @raycast.description Pack a GitHub repository into clipboard using Repomix
# @raycast.author Graham Anderson
# @raycast.authorURL https://github.com/grahama1970
# @raycast.argument1 { "type": "text", "placeholder": "username/repo or full GitHub URL", "required": true }
# @raycast.argument2 { "type": "text", "placeholder": "paths to include (e.g. src/core,docs/api)", "required": false }
# @raycast.argument4 { "type": "text", "placeholder": "branch/commit (e.g. main)", "required": false }
# Debug log function
debug_log() {
echo "$(date): $1" >> /tmp/repomix_debug.log
}
# Log all arguments for debugging
debug_log "All arguments: $*"
# Set default values, but only if arguments are not provided at all
if [ "$#" -lt 2 ]; then ARG_INCLUDE="src/core"; else ARG_INCLUDE="$2"; fi
# if [ "$#" -lt 3 ]; then ARG_EXCLUDE="src/tests,src/__tests__"; else ARG_EXCLUDE="$3"; fi
if [ "$#" -lt 4 ]; then ARG_BRANCH="main"; else ARG_BRANCH="$4"; fi
# Log the interpreted values
debug_log "REPO: $1"
debug_log "ARG_INCLUDE: $ARG_INCLUDE"
# debug_log "ARG_EXCLUDE: $ARG_EXCLUDE"
debug_log "ARG_BRANCH: $ARG_BRANCH"
# Main logic
if [ -z "$1" ]; then
echo "Error: Repository argument is required"
exit 1
fi
REPO="$1"
# Ensure repomix is in PATH
export PATH="$PATH:$HOME/.npm-global/bin:/usr/local/bin:/opt/homebrew/bin"
# Check for repomix and install if not found
if ! command -v repomix &> /dev/null; then
npm install -g repomix
fi
# Build and execute command
CMD=(repomix --remote "$REPO" --remote-branch "$ARG_BRANCH" --compress)
[ -n "$ARG_INCLUDE" ] && CMD+=(--include "$ARG_INCLUDE")
# [ -n "$ARG_EXCLUDE" ] && CMD+=(--ignore "$ARG_EXCLUDE")
CMD+=(--style "markdown" --copy)
debug_log "Executing command: ${CMD[*]}"
if "${CMD[@]}"; then
echo "Repository content copied to clipboard!"
else
echo "Failed to process repository"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment