-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_shell.sh
More file actions
executable file
·86 lines (74 loc) · 3.12 KB
/
Copy pathsetup_shell.sh
File metadata and controls
executable file
·86 lines (74 loc) · 3.12 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
# setup_shell.sh — Install opencoded shell functions for zsh or bash
set -euo pipefail
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
RED='\033[0;31m'
NC='\033[0m'
FUNCTIONS_FILE="$HOME/.local/bin/opencoded-functions.sh"
SOURCE_LINE="source \"\$HOME/.local/bin/opencoded-functions.sh\""
echo -e "${BLUE}OpenCode shell setup${NC}"
echo ""
# ── Detect shell ────────────────────────────────────────────────────────────
if command -v zsh &>/dev/null; then
RC_FILE="$HOME/.zshrc"
SHELL_NAME="zsh"
else
RC_FILE="$HOME/.bashrc"
SHELL_NAME="bash"
fi
echo -e "${GREEN}Detected shell:${NC} ${SHELL_NAME} → will configure ${CYAN}${RC_FILE}${NC}"
echo ""
# ── Create functions file ────────────────────────────────────────────────────
mkdir -p "$HOME/.local/bin"
cat >"$FUNCTIONS_FILE" <<'EOF'
# opencoded shell functions — generated by setup_shell.sh
# Run `~/opencoded/setup_shell.sh` again to update.
opencoded() {
docker run -d \
--name opencoded \
--rm \
--user "$(id -u):$(id -g)" \
-p "${OPENCODE_PORT:-4096}:4096" \
-v "${OPENCODE_PATH:-$(pwd)}:/workspace" \
-v "$HOME/.ssh/id_ed25519:/home/opencoded/.ssh/id_ed25519:ro" \
-v "$HOME/.config/opencode:/home/opencoded/.config/opencode" \
-v "$HOME/.local/share/opencode/auth.json:/home/opencoded/.local/share/opencode/auth.json" \
-e "GH_TOKEN=${GH_TOKEN:-}" \
-e "OPENCODE_SERVER_USERNAME=${OPENCODE_SERVER_USERNAME:-opencode}" \
-e "OPENCODE_SERVER_PASSWORD=${OPENCODE_SERVER_PASSWORD:-}" \
ghcr.io/brockar/opencoded:latest web --hostname 0.0.0.0 --port 4096
}
opencodedt() {
docker run -it \
--rm \
--name opencoded-tui \
--user "$(id -u):$(id -g)" \
-v "${OPENCODE_PATH:-$(pwd)}:/workspace" \
-v "$HOME/.ssh/id_ed25519:/home/opencoded/.ssh/id_ed25519:ro" \
-v "$HOME/.config/opencode:/home/opencoded/.config/opencode" \
-v "$HOME/.local/share/opencode/auth.json:/home/opencoded/.local/share/opencode/auth.json" \
-e "GH_TOKEN=${GH_TOKEN:-}" \
ghcr.io/brockar/opencoded:latest
}
EOF
chmod +x "$FUNCTIONS_FILE"
echo -e "${GREEN}Functions written to:${NC} ${CYAN}${FUNCTIONS_FILE}${NC}"
# ── Add source line to rc file (idempotent) ─────────────────────────────────
if grep -qF "opencoded-functions.sh" "$RC_FILE" 2>/dev/null; then
echo -e "${YELLOW}Source line already present in ${RC_FILE} — skipping.${NC}"
else
echo "" >>"$RC_FILE"
echo "# opencoded" >>"$RC_FILE"
echo "$SOURCE_LINE" >>"$RC_FILE"
echo -e "${GREEN}Source line added to:${NC} ${CYAN}${RC_FILE}${NC}"
fi
echo ""
echo -e "${GREEN}Done!${NC} Reload your shell with:"
echo -e " ${CYAN}source ${RC_FILE}${NC}"
echo ""
echo -e "${BLUE}Available commands after reload:${NC}"
echo -e " ${CYAN}opencoded${NC} — start web mode (detached)"
echo -e " ${CYAN}opencodedt${NC} — start TUI mode (interactive)"