docker-claude/launch.sh

63 lines
2.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# launch.sh — Pick a project folder and start Claude Code
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ─── First-time setup ─────────────────────────────────────────────────────────
if [[ ! -f "$SCRIPT_DIR/.env" ]]; then
echo "Looks like this is your first time. Running setup..."
echo ""
"$SCRIPT_DIR/setup.sh" || exit 1
echo ""
fi
# ─── Folder picker ────────────────────────────────────────────────────────────
pick_folder() {
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS — native Finder dialog
osascript -e \
'tell application "Finder" to POSIX path of (choose folder with prompt "Select the project folder to work on:")' \
2>/dev/null | tr -d '\n'
elif command -v zenity &>/dev/null; then
# Linux — GNOME/GTK dialog
zenity --file-selection --directory \
--title="Select your project folder" 2>/dev/null
elif command -v kdialog &>/dev/null; then
# Linux — KDE dialog
kdialog --getexistingdirectory "$HOME" \
--title "Select your project folder" 2>/dev/null
else
echo ""
fi
}
folder=$(pick_folder || true)
# Fallback: text prompt (no GUI available, or user cancelled dialog)
if [[ -z "$folder" ]]; then
echo "Enter the path to your project folder"
echo "(Tip: you can drag the folder into this window, then press Enter)"
echo ""
read -rp "> " folder
# Clean up: strip surrounding quotes and trailing whitespace from drag-and-drop
folder="${folder%"${folder##*[![:space:]]}"}"
folder="${folder#\'}" ; folder="${folder%\'}"
folder="${folder#\"}" ; folder="${folder%\"}"
# Expand ~ to home directory
folder="${folder/#\~/$HOME}"
fi
if [[ -z "$folder" ]]; then
echo "No folder selected. Exiting."
exit 1
fi
if [[ ! -d "$folder" ]]; then
echo "Folder not found: $folder"
exit 1
fi
cd "$folder"
exec "$SCRIPT_DIR/claude.sh" start