aboutsummaryrefslogtreecommitdiffstats
path: root/bash/snip/setup
blob: 7f379194caea2e3759b58b0a970b38ea40c89c6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/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)'"