#!/bin/sh # Setup script for snip snippet manager # This script initializes the ~/.snippets directory with proper git setup set -e SNIPPETS_DIR="${HOME}/.snippets" SCRIPT_DIR="$(dirname "$0")" echo "Setting up snip snippet manager..." # Create snippets directory mkdir -p "$SNIPPETS_DIR" # Copy .gitignore to snippets directory cp "$SCRIPT_DIR/.gitignore" "$SNIPPETS_DIR/.gitignore" # Initialize git repository cd "$SNIPPETS_DIR" if [ ! -d ".git" ]; then git init echo "Initialized git repository in $SNIPPETS_DIR" fi # Add .gitignore to git git add .gitignore git commit -m "Initial commit: Add .gitignore" || true # Create example snippets mkdir -p "$SNIPPETS_DIR/bash" mkdir -p "$SNIPPETS_DIR/git" # Add example bash snippet cat > "$SNIPPETS_DIR/bash/hello-world.txt" << 'EOF' #!/bin/bash echo "Hello, World!" EOF # Add example git snippet cat > "$SNIPPETS_DIR/git/commit-message.txt" << 'EOF' feat: add new feature - Detailed description of changes - List of specific changes made - Any breaking changes or considerations EOF # Add example snippets to git git add . git commit -m "Add example snippets" || true echo "Setup complete!" echo "Snippets directory: $SNIPPETS_DIR" echo "Example usage:" echo " $SCRIPT_DIR/snip list" echo " $SCRIPT_DIR/snip select" echo " $SCRIPT_DIR/snip add python 'fibonacci' 'def fib(n): return n if n <= 1 else fib(n-1) + fib(n-2)'"