Claude Code 네이티브 statusLine 방식의 4줄 상태바 스크립트와 어느 머신에서든 한 줄로 설치·업데이트할 수 있는 스크립트 추가. 크로스플랫폼(Linux/macOS) stat 호환 처리 포함. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
152 lines
4.3 KiB
Bash
Executable File
152 lines
4.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ccstatusline-config installer
|
|
# 어느 머신에서든 한 줄로 설치:
|
|
# git clone https://git.scrutineer.co.kr/zaksal58/ccstatusline-config.git && cd ccstatusline-config && ./install.sh
|
|
#
|
|
# 또는 원격 설치:
|
|
# curl -sSL https://git.scrutineer.co.kr/zaksal58/ccstatusline-config/raw/branch/main/install.sh | bash
|
|
|
|
set -euo pipefail
|
|
|
|
REPO_URL="https://git.scrutineer.co.kr/zaksal58/ccstatusline-config.git"
|
|
CLAUDE_DIR="${HOME}/.claude"
|
|
STATUSLINE_SCRIPT="${CLAUDE_DIR}/statusline.sh"
|
|
SETTINGS_FILE="${CLAUDE_DIR}/settings.json"
|
|
|
|
# --- Colors ---
|
|
RED=$'\033[91m'
|
|
GREEN=$'\033[92m'
|
|
YELLOW=$'\033[93m'
|
|
CYAN=$'\033[96m'
|
|
BOLD=$'\033[1m'
|
|
RESET=$'\033[0m'
|
|
|
|
info() { echo "${CYAN}[INFO]${RESET} $*"; }
|
|
ok() { echo "${GREEN}[OK]${RESET} $*"; }
|
|
warn() { echo "${YELLOW}[WARN]${RESET} $*"; }
|
|
err() { echo "${RED}[ERROR]${RESET} $*" >&2; }
|
|
|
|
# --- Dependency check ---
|
|
check_deps() {
|
|
local missing=()
|
|
for cmd in jq git; do
|
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
missing+=("$cmd")
|
|
fi
|
|
done
|
|
if [ ${#missing[@]} -gt 0 ]; then
|
|
err "필수 의존성이 없습니다: ${missing[*]}"
|
|
err "설치 후 다시 실행해주세요."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# --- Determine script source directory ---
|
|
get_script_dir() {
|
|
# If run from a cloned repo, use local files
|
|
local dir
|
|
dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
if [ -f "${dir}/statusline.sh" ]; then
|
|
echo "$dir"
|
|
return
|
|
fi
|
|
# If run via curl pipe, clone to temp dir
|
|
local tmpdir
|
|
tmpdir=$(mktemp -d)
|
|
info "저장소 클론 중..."
|
|
git clone --depth 1 "$REPO_URL" "$tmpdir" >/dev/null 2>&1
|
|
echo "$tmpdir"
|
|
}
|
|
|
|
# --- Install statusline script ---
|
|
install_statusline() {
|
|
local src_dir="$1"
|
|
|
|
mkdir -p "$CLAUDE_DIR"
|
|
|
|
# Backup existing statusline if different
|
|
if [ -f "$STATUSLINE_SCRIPT" ]; then
|
|
if ! diff -q "${src_dir}/statusline.sh" "$STATUSLINE_SCRIPT" >/dev/null 2>&1; then
|
|
local backup="${STATUSLINE_SCRIPT}.bak.$(date +%Y%m%d%H%M%S)"
|
|
cp "$STATUSLINE_SCRIPT" "$backup"
|
|
warn "기존 statusline.sh 백업: ${backup}"
|
|
fi
|
|
fi
|
|
|
|
cp "${src_dir}/statusline.sh" "$STATUSLINE_SCRIPT"
|
|
chmod +x "$STATUSLINE_SCRIPT"
|
|
ok "statusline.sh 설치 완료: ${STATUSLINE_SCRIPT}"
|
|
}
|
|
|
|
# --- Update settings.json ---
|
|
update_settings() {
|
|
local statusline_entry
|
|
statusline_entry=$(cat <<JSONEOF
|
|
{
|
|
"type": "command",
|
|
"command": "${STATUSLINE_SCRIPT}",
|
|
"padding": 0
|
|
}
|
|
JSONEOF
|
|
)
|
|
|
|
if [ ! -f "$SETTINGS_FILE" ]; then
|
|
# Create new settings.json with statusLine
|
|
cat > "$SETTINGS_FILE" <<JSONEOF
|
|
{
|
|
"statusLine": {
|
|
"type": "command",
|
|
"command": "${STATUSLINE_SCRIPT}",
|
|
"padding": 0
|
|
}
|
|
}
|
|
JSONEOF
|
|
ok "settings.json 생성 완료 (statusLine 설정 포함)"
|
|
return
|
|
fi
|
|
|
|
# Check if statusLine is already configured
|
|
local existing
|
|
existing=$(jq -r '.statusLine.command // ""' "$SETTINGS_FILE" 2>/dev/null || echo "")
|
|
|
|
if [ "$existing" = "$STATUSLINE_SCRIPT" ]; then
|
|
ok "settings.json에 statusLine이 이미 올바르게 설정되어 있습니다."
|
|
return
|
|
fi
|
|
|
|
# Update or add statusLine entry
|
|
local tmpfile
|
|
tmpfile=$(mktemp)
|
|
jq --arg cmd "$STATUSLINE_SCRIPT" '.statusLine = {"type": "command", "command": $cmd, "padding": 0}' "$SETTINGS_FILE" > "$tmpfile"
|
|
mv "$tmpfile" "$SETTINGS_FILE"
|
|
ok "settings.json 업데이트 완료 (statusLine 경로: ${STATUSLINE_SCRIPT})"
|
|
}
|
|
|
|
# --- Main ---
|
|
main() {
|
|
echo ""
|
|
echo "${BOLD}${CYAN}╔══════════════════════════════════════╗${RESET}"
|
|
echo "${BOLD}${CYAN}║ Claude Code Statusline Installer ║${RESET}"
|
|
echo "${BOLD}${CYAN}╚══════════════════════════════════════╝${RESET}"
|
|
echo ""
|
|
|
|
check_deps
|
|
|
|
local src_dir
|
|
src_dir=$(get_script_dir)
|
|
|
|
install_statusline "$src_dir"
|
|
update_settings
|
|
|
|
echo ""
|
|
echo "${GREEN}${BOLD}설치 완료!${RESET}"
|
|
echo ""
|
|
echo " Claude Code를 다시 시작하면 새 statusline이 적용됩니다."
|
|
echo ""
|
|
echo " 업데이트하려면:"
|
|
echo " ${CYAN}cd ${src_dir} && git pull && ./install.sh${RESET}"
|
|
echo ""
|
|
}
|
|
|
|
main "$@"
|