Skip to content

Commit 92559df

Browse files
committed
Consolidate setup scripts and remove emojis
Changes: - Create .claude/setup-common.sh with shared setup functions - Refactor SessionStart hook to use common setup functions - Remove all emojis from Claude Code scripts (activate.sh, SessionStart) - Update devcontainer to use shared setup functions - Update setup_host.sh to optionally use common pixi installation - Update documentation in README.md and .claude/README.md Benefits: - Reduced code duplication across setup scripts - Consistent setup behavior across different environments - Easier maintenance with centralized setup logic - Cleaner, more professional output without emojis
1 parent 94fab02 commit 92559df

File tree

7 files changed

+95
-39
lines changed

7 files changed

+95
-39
lines changed

.claude/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@
22

33
This directory contains configuration for using this project with Claude Code, particularly in the online environment.
44

5+
## Files
6+
7+
- `setup-common.sh` - Shared setup functions used by SessionStart, devcontainer, and other setup scripts
8+
- `activate.sh` - Manual activation script to add pixi to PATH
9+
- `hooks/SessionStart` - Automatic setup hook for Claude Code online sessions
10+
11+
## Setup Architecture
12+
13+
The setup is consolidated using shared functions in `setup-common.sh`:
14+
15+
- `install_pixi()` - Installs pixi package manager
16+
- `install_dependencies()` - Installs project dependencies via pixi
17+
- `setup_pre_commit()` - Configures pre-commit hooks
18+
- `setup_git_merge_driver()` - Sets up git merge driver for lockfiles
19+
- `setup_environment()` - Runs all setup steps
20+
521
## SessionStart Hook
622

7-
The `hooks/SessionStart` script automatically runs when a new Claude Code session begins. It:
23+
The `hooks/SessionStart` script automatically runs when a new Claude Code session begins. It sources `setup-common.sh` and executes the full environment setup:
824

925
1. **Installs pixi** (if not already installed) - The package and environment manager
1026
2. **Installs project dependencies** - All Python packages and tools defined in `pyproject.toml`

.claude/activate.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ export PATH="$HOME/.pixi/bin:$PATH"
77

88
# Optional: Activate pixi shell if available
99
if command -v pixi &> /dev/null; then
10-
echo "Pixi environment activated"
11-
echo "💡 Available commands:"
10+
echo "Pixi environment activated"
11+
echo "Available commands:"
1212
echo " pixi run test - Run tests"
1313
echo " pixi run lint - Run linters"
1414
echo " pixi run format - Format code"
1515
echo " pixi run ci - Run full CI"
1616
pixi task list --summary 2>/dev/null || true
1717
else
18-
echo "⚠️ Pixi not found. Please run .claude/hooks/SessionStart first."
18+
echo "Pixi not found. Please run .claude/hooks/SessionStart first."
1919
fi

.claude/hooks/SessionStart

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,23 @@
44

55
set -e
66

7-
echo "🚀 Setting up Python Template environment..."
7+
# Get the directory where this script is located
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
89

9-
# Check if pixi is installed
10-
if ! command -v pixi &> /dev/null; then
11-
echo "📦 Installing pixi..."
12-
curl -fsSL https://pixi.sh/install.sh | bash
10+
# Source common setup functions
11+
source "$SCRIPT_DIR/../setup-common.sh"
1312

14-
# Add pixi to PATH for current session
15-
export PATH="$HOME/.pixi/bin:$PATH"
13+
echo "Setting up Python Template environment..."
1614

17-
# Source bashrc to get pixi in PATH (if bashrc was updated)
18-
[ -f "$HOME/.bashrc" ] && source "$HOME/.bashrc"
15+
# Run the full environment setup
16+
setup_environment
1917

20-
echo "✅ Pixi installed successfully"
21-
else
22-
echo "✅ Pixi already installed"
23-
fi
24-
25-
# Ensure pixi is in PATH for this session
26-
export PATH="$HOME/.pixi/bin:$PATH"
27-
28-
# Install project dependencies
29-
echo "📦 Installing project dependencies..."
30-
pixi install
31-
32-
# Run pre-commit installation
33-
echo "🔧 Setting up pre-commit hooks..."
34-
pixi run pre-commit install || echo "⚠️ Pre-commit installation skipped (optional)"
35-
36-
# Set up git merge driver for lockfiles
37-
echo "🔧 Configuring git merge driver..."
38-
pixi run setup-git-merge-driver || true
39-
40-
echo "✅ Environment setup complete!"
18+
echo "Environment setup complete!"
4119
echo ""
4220
echo "Available pixi tasks:"
4321
pixi task list
4422
echo ""
45-
echo "💡 Common commands:"
23+
echo "Common commands:"
4624
echo " pixi run test - Run tests"
4725
echo " pixi run lint - Run linters"
4826
echo " pixi run format - Format code"

.claude/setup-common.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
# Common setup functions for pixi-based development environments
3+
# Can be sourced by various setup scripts (SessionStart, devcontainer, etc.)
4+
5+
# Install pixi if not already installed
6+
install_pixi() {
7+
if ! command -v pixi &> /dev/null; then
8+
echo "Installing pixi..."
9+
curl -fsSL https://pixi.sh/install.sh | bash
10+
11+
# Add pixi to PATH for current session
12+
export PATH="$HOME/.pixi/bin:$PATH"
13+
14+
# Source bashrc to get pixi in PATH (if bashrc was updated)
15+
[ -f "$HOME/.bashrc" ] && source "$HOME/.bashrc"
16+
17+
echo "Pixi installed successfully"
18+
else
19+
echo "Pixi already installed"
20+
fi
21+
22+
# Ensure pixi is in PATH for this session
23+
export PATH="$HOME/.pixi/bin:$PATH"
24+
}
25+
26+
# Install project dependencies using pixi
27+
install_dependencies() {
28+
echo "Installing project dependencies..."
29+
pixi install
30+
}
31+
32+
# Setup pre-commit hooks
33+
setup_pre_commit() {
34+
echo "Setting up pre-commit hooks..."
35+
pixi run pre-commit install || echo "Pre-commit installation skipped (optional)"
36+
}
37+
38+
# Setup git merge driver for lockfiles
39+
setup_git_merge_driver() {
40+
echo "Configuring git merge driver..."
41+
pixi run setup-git-merge-driver || true
42+
}
43+
44+
# Full environment setup
45+
setup_environment() {
46+
install_pixi
47+
install_dependencies
48+
setup_pre_commit
49+
setup_git_merge_driver
50+
}

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
"mounts": [
2828
"source=${localWorkspaceFolderBasename}-pixi,target=${containerWorkspaceFolder}/.pixi,type=volume"
2929
],
30-
"postCreateCommand": "sudo chown vscode .pixi && pixi install"
30+
"postCreateCommand": "sudo chown vscode .pixi && source .claude/setup-common.sh && install_dependencies && setup_pre_commit && setup_git_merge_driver"
3131
}

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ If you are using pixi, look at the available tasks in pyproject.toml If you are
3838

3939
# Claude Code Online Support
4040

41-
This template includes built-in support for [Claude Code](https://docs.claude.com/claude-code) online environment! The `.claude/hooks/SessionStart` script automatically:
41+
This template includes built-in support for [Claude Code](https://docs.claude.com/claude-code) online environment! The setup is consolidated using shared scripts:
4242

43+
- `.claude/setup-common.sh` - Shared setup functions used across different environments
44+
- `.claude/hooks/SessionStart` - Automatic setup hook for Claude Code online
45+
- `.claude/activate.sh` - Manual activation script
46+
47+
The SessionStart hook automatically:
4348
- Installs pixi package manager
4449
- Sets up all project dependencies
4550
- Configures pre-commit hooks

scripts/setup_host.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,15 @@ docker run hello-world
5151
echo "you may need to restart your machine"
5252

5353
#INSTALL PIXI
54-
curl -fsSL https://pixi.sh/install.sh | bash
55-
echo 'eval "$(pixi completion --shell bash)"' >> ~/.bashrc
54+
# Use common setup function if available, otherwise install directly
55+
if [ -f "$(dirname "$0")/../.claude/setup-common.sh" ]; then
56+
source "$(dirname "$0")/../.claude/setup-common.sh"
57+
install_pixi
58+
echo 'eval "$(pixi completion --shell bash)"' >> ~/.bashrc
59+
else
60+
curl -fsSL https://pixi.sh/install.sh | bash
61+
echo 'eval "$(pixi completion --shell bash)"' >> ~/.bashrc
62+
fi
5663

5764
#INSTALL UV
5865
curl -LsSf https://astral.sh/uv/install.sh | sh

0 commit comments

Comments
 (0)