#!/usr/bin/env bash set -euo pipefail # GitHub Claude Code Discovery # Searches GitHub for skills, agents, and slash commands based on usage patterns # Parse arguments SEARCH_TYPE="${1:-all}" # all, agents, skills, commands QUERY="${2:-}" # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' RED='\033[0;31m' NC='\033[0m' # Check if gh CLI is installed HAS_GH=false if command -v gh &>/dev/null; then HAS_GH=true fi echo -e "${BLUE}GitHub Claude Code Discovery${NC}" >&2 echo -e "${BLUE}============================${NC}\n" >&2 # Function to search GitHub using gh CLI search_with_gh() { local path="$1" local query="$2" local limit="${3:-10}" if [ -z "$query" ]; then gh search code "path:$path" --limit "$limit" --json path,repository,url 2>/dev/null else gh search code "$query path:$path" --limit "$limit" --json path,repository,url 2>/dev/null fi } # Function to search GitHub using web URLs (fallback) get_search_url() { local path="$1" local query="$2" if [ -z "$query" ]; then echo "https://github.com/search?type=code&q=path:${path}" else # URL encode the query query_encoded=$(echo "$query" | sed 's/ /+/g') echo "https://github.com/search?type=code&q=${query_encoded}+path:${path}" fi } # Output JSON structure cat <&2 cat <&2 cat <&2 cat <&2 cat <&2 if [ "$HAS_GH" = false ]; then echo -e "${YELLOW}Note: Install 'gh' CLI for direct search results${NC}" >&2 echo -e "Install: ${BLUE}brew install gh${NC} (macOS) or see https://cli.github.com" >&2 fi