-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup-aliases.sh
More file actions
executable file
·136 lines (117 loc) · 5.71 KB
/
setup-aliases.sh
File metadata and controls
executable file
·136 lines (117 loc) · 5.71 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# Setup cc/claude/ccraw aliases for claude with local system prompt support
#
# Idempotent: removes the entire managed block then re-writes it fresh.
# Safe to run on every container start via postStartCommand.
CLAUDE_DIR="${CLAUDE_CONFIG_DIR:?CLAUDE_CONFIG_DIR not set}"
echo "[setup-aliases] Configuring Claude aliases..."
# Resolve check-setup path once (used inside the block we write)
DEVCONTAINER_SCRIPTS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BLOCK_START='# === CodeForge Claude aliases START (managed by setup-aliases.sh — do not edit) ==='
BLOCK_END='# === CodeForge Claude aliases END ==='
for rc in ~/.bashrc ~/.zshrc; do
if [ -f "$rc" ]; then
# --- 1. Backup before modifying ---
cp "$rc" "${rc}.bak.$(date +%s)" 2>/dev/null || true
# Clean old backups (keep last 3)
ls -t "${rc}.bak."* 2>/dev/null | tail -n +4 | xargs rm -f 2>/dev/null || true
# --- 2. Remove existing managed block (if present) ---
sed -i '/# === CodeForge Claude aliases START/,/# === CodeForge Claude aliases END/d' "$rc"
# --- 3. Legacy cleanup (pre-marker formats only) ---
# These remove remnants from versions that predated the block-marker system.
# After step 2, anything matching these patterns is orphaned from old formats.
# Old function forms (pre-v1.10.0)
if grep -q "^cc()" "$rc" 2>/dev/null; then
sed -i '/^cc() {/,/^}/d' "$rc"
echo "[setup-aliases] Removed legacy cc() function from $(basename "$rc")"
fi
if grep -q "^_claude_with_config()" "$rc" 2>/dev/null; then
sed -i '/^_claude_with_config() {/,/^}/d' "$rc"
echo "[setup-aliases] Removed legacy _claude_with_config() function from $(basename "$rc")"
fi
if grep -q "^claude() { _claude_with_config" "$rc" 2>/dev/null; then
sed -i '/^claude() { _claude_with_config/d' "$rc"
echo "[setup-aliases] Removed legacy claude() function from $(basename "$rc")"
fi
if grep -q "alias specwright=" "$rc" 2>/dev/null; then
sed -i '/alias specwright=/d' "$rc"
echo "[setup-aliases] Removed legacy specwright alias from $(basename "$rc")"
fi
# Old alias/export form (v1.10.0 — no block markers)
sed -i '/# Claude Code environment and aliases/d' "$rc"
sed -i '/^export CLAUDE_CONFIG_DIR="/d' "$rc"
sed -i '/^export LANG=en_US\.UTF-8$/d' "$rc"
sed -i '/^export LC_ALL=en_US\.UTF-8$/d' "$rc"
# _CLAUDE_BIN if-block (4 patterns: if, elif, else, fi + assignments)
sed -i '/^if \[ -x "\$HOME\/\.local\/bin\/claude" \]/,/^fi$/d' "$rc"
sed -i '/^ _CLAUDE_BIN=/d' "$rc"
# Standalone aliases from old format
sed -i "/^alias cc='/d" "$rc"
sed -i "/^alias claude='/d" "$rc"
sed -i "/^alias ccraw='/d" "$rc"
sed -i "/^alias ccw='/d" "$rc"
sed -i '/^alias check-setup=/d' "$rc"
# cc-tools function from old format
if grep -q "^cc-tools()" "$rc" 2>/dev/null; then
sed -i '/^cc-tools() {/,/^}/d' "$rc"
fi
# --- 5. Write fresh managed block ---
cat >>"$rc" <<BLOCK_EOF
${BLOCK_START}
export CLAUDE_CONFIG_DIR="${CLAUDE_CONFIG_DIR}"
export GH_CONFIG_DIR="${GH_CONFIG_DIR:-/workspaces/.gh}"
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Terminal color defaults — Docker sets TERM=xterm (8 colors); upgrade to 256-color
if [ "\$TERM" = "xterm" ] || [ -z "\$TERM" ]; then
export TERM=xterm-256color
fi
export COLORTERM="\${COLORTERM:-truecolor}"
# Prefer native binary over npm-installed version
if [ -x "\$HOME/.local/bin/claude" ]; then
_CLAUDE_BIN="\$HOME/.local/bin/claude"
elif [ -x /usr/local/bin/claude ]; then
_CLAUDE_BIN=/usr/local/bin/claude
else
_CLAUDE_BIN=claude
fi
# ChromaTerm wrapper (if ct is installed, wrap claude through it)
if command -v ct >/dev/null 2>&1; then
_CLAUDE_WRAP="ct"
else
_CLAUDE_WRAP="command"
fi
alias cc='CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 "\$_CLAUDE_WRAP" "\$_CLAUDE_BIN" --system-prompt-file "\$CLAUDE_CONFIG_DIR/main-system-prompt.md" --permission-mode plan --allow-dangerously-skip-permissions'
alias claude='CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 "\$_CLAUDE_WRAP" "\$_CLAUDE_BIN" --system-prompt-file "\$CLAUDE_CONFIG_DIR/main-system-prompt.md" --permission-mode plan --allow-dangerously-skip-permissions'
alias ccraw='command "\$_CLAUDE_BIN"'
alias ccw='CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 "\$_CLAUDE_WRAP" "\$_CLAUDE_BIN" --system-prompt-file "\$CLAUDE_CONFIG_DIR/writing-system-prompt.md" --permission-mode plan --allow-dangerously-skip-permissions'
cc-tools() {
echo "CodeForge Available Tools"
echo "━━━━━━━━━━━━━━━━━━━━━━━━"
printf " %-20s %s\n" "COMMAND" "STATUS"
echo " ────────────────────────────────────"
for cmd in claude cc ccw ccraw ccusage ccburn claude-monitor \\
ccms ct cargo ruff biome dprint shfmt shellcheck hadolint \\
ast-grep tree-sitter pyright typescript-language-server \\
agent-browser gh docker git jq tmux bun go infocmp; do
if command -v "\$cmd" >/dev/null 2>&1; then
ver=\$("\$cmd" --version 2>/dev/null | head -1 || echo "installed")
printf " %-20s ✓ %s\n" "\$cmd" "\$ver"
else
printf " %-20s ✗ not found\n" "\$cmd"
fi
done
}
alias check-setup='bash ${DEVCONTAINER_SCRIPTS}/check-setup.sh'
${BLOCK_END}
BLOCK_EOF
echo "[setup-aliases] Added aliases to $(basename "$rc")"
fi
done
echo "[setup-aliases] Aliases configured:"
echo " cc -> claude with \$CLAUDE_CONFIG_DIR/main-system-prompt.md"
echo " claude -> claude with \$CLAUDE_CONFIG_DIR/main-system-prompt.md"
echo " ccraw -> vanilla claude without any config"
echo " ccw -> claude with \$CLAUDE_CONFIG_DIR/writing-system-prompt.md"
echo " cc-tools -> list all available CodeForge tools"
echo " check-setup -> verify CodeForge setup health"