2026-05-13 13:13:35 +09:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
|
|
|
|
|
|
# Installs tmux (terminal multiplexer) and deploys .tmux.conf.
|
|
|
|
|
# tmux: https://github.com/tmux/tmux
|
|
|
|
|
#
|
|
|
|
|
# Supported platforms:
|
|
|
|
|
# macOS : Intel (x86_64), Apple Silicon (arm64) — via Homebrew
|
|
|
|
|
# Linux : x86_64, aarch64 — via apt, yum, dnf, zypper, or pacman
|
|
|
|
|
#
|
|
|
|
|
# Prerequisites:
|
|
|
|
|
# - macOS: Homebrew (brew)
|
|
|
|
|
# - Linux: a supported package manager (apt, yum, dnf, zypper, or pacman)
|
|
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
# Constants
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
CONF_FILE="${HOME}/.tmux.conf"
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
# Utility functions (all stderr output)
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
info() { echo "[INFO] $*" >&2; }
|
|
|
|
|
warn() { echo "[WARN] $*" >&2; }
|
|
|
|
|
error() {
|
|
|
|
|
echo "[ERROR] $*" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
success() { echo "[OK] $*" >&2; }
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
# Detect OS
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
OS="$(uname -s)"
|
|
|
|
|
ARCH="$(uname -m)"
|
|
|
|
|
|
|
|
|
|
case "$OS" in
|
|
|
|
|
Darwin | Linux) ;;
|
|
|
|
|
*)
|
|
|
|
|
error "Unsupported OS: $OS. This script only supports macOS and Linux."
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2026-05-13 22:18:20 +09:00
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
# Ensure Homebrew is available on macOS
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
ensure_brew() {
|
|
|
|
|
if command -v brew &>/dev/null; then
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
info "Homebrew is not installed. Installing Homebrew..."
|
|
|
|
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
|
|
|
|
# Add brew to PATH for Apple Silicon
|
|
|
|
|
if [ -d /opt/homebrew/bin ]; then
|
|
|
|
|
export PATH="/opt/homebrew/bin:$PATH"
|
|
|
|
|
fi
|
|
|
|
|
if [ -d /usr/local/bin ]; then
|
|
|
|
|
export PATH="/usr/local/bin:$PATH"
|
|
|
|
|
fi
|
|
|
|
|
command -v brew &>/dev/null || error "Homebrew installation failed. Install it manually: https://brew.sh/"
|
|
|
|
|
success "Homebrew installed"
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-13 13:13:35 +09:00
|
|
|
info "Platform: $OS ($ARCH)"
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
# Step 1: Install tmux
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
info "Installing tmux..."
|
|
|
|
|
|
|
|
|
|
if command -v tmux &>/dev/null; then
|
|
|
|
|
CURRENT_VER="$(tmux -V 2>/dev/null || echo 'unknown')"
|
|
|
|
|
info "tmux is already installed ($CURRENT_VER). Skipping installation."
|
|
|
|
|
else
|
|
|
|
|
case "$OS" in
|
|
|
|
|
Darwin)
|
2026-05-13 22:18:20 +09:00
|
|
|
ensure_brew
|
|
|
|
|
brew install tmux
|
|
|
|
|
success "tmux installed via Homebrew"
|
2026-05-13 13:13:35 +09:00
|
|
|
;;
|
|
|
|
|
Linux)
|
|
|
|
|
if command -v apt-get &>/dev/null; then
|
|
|
|
|
sudo apt-get update -y
|
|
|
|
|
sudo apt-get install -y tmux
|
|
|
|
|
success "tmux installed via apt-get"
|
|
|
|
|
elif command -v dnf &>/dev/null; then
|
|
|
|
|
sudo dnf install -y tmux
|
|
|
|
|
success "tmux installed via dnf"
|
|
|
|
|
elif command -v yum &>/dev/null; then
|
|
|
|
|
sudo yum install -y tmux
|
|
|
|
|
success "tmux installed via yum"
|
|
|
|
|
elif command -v zypper &>/dev/null; then
|
|
|
|
|
sudo zypper -n install tmux
|
|
|
|
|
success "tmux installed via zypper"
|
|
|
|
|
elif command -v pacman &>/dev/null; then
|
|
|
|
|
sudo pacman -S --noconfirm tmux
|
|
|
|
|
success "tmux installed via pacman"
|
|
|
|
|
else
|
|
|
|
|
error "No supported package manager found (apt, dnf, yum, zypper, pacman). Install tmux manually."
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Verify tmux is available
|
|
|
|
|
if command -v tmux &>/dev/null; then
|
|
|
|
|
success "tmux is available: $(command -v tmux)"
|
|
|
|
|
else
|
|
|
|
|
warn "tmux was not found in PATH after installation. You may need to open a new terminal."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
# Step 2: Deploy .tmux.conf
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
if [ -f "$CONF_FILE" ]; then
|
|
|
|
|
warn "Existing .tmux.conf found at $CONF_FILE"
|
|
|
|
|
BACKUP="${CONF_FILE}.bak.$(date +%Y%m%d%H%M%S)"
|
|
|
|
|
cp "$CONF_FILE" "$BACKUP"
|
|
|
|
|
info "Backup saved to $BACKUP"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cat >"$CONF_FILE" <<'TMUXCONF'
|
|
|
|
|
# .tmux.conf 샘플
|
|
|
|
|
|
|
|
|
|
# Prefix key 변경 (기본은 Ctrl-b)
|
|
|
|
|
set -g prefix C-a
|
|
|
|
|
unbind C-b
|
|
|
|
|
bind C-a send-prefix
|
|
|
|
|
|
|
|
|
|
# 창 분할 단축키 변경
|
|
|
|
|
bind | split-window -h -c "#{pane_current_path}"
|
|
|
|
|
bind - split-window -v -c "#{pane_current_path}"
|
|
|
|
|
unbind '"'
|
|
|
|
|
unbind %
|
|
|
|
|
|
|
|
|
|
# 창 이동 단축키 (vim 스타일)
|
|
|
|
|
bind h select-pane -L
|
|
|
|
|
bind j select-pane -D
|
|
|
|
|
bind k select-pane -U
|
|
|
|
|
bind l select-pane -R
|
|
|
|
|
|
|
|
|
|
# 창 전환 단축키
|
|
|
|
|
bind -r C-h previous-window
|
|
|
|
|
bind -r C-l next-window
|
|
|
|
|
|
|
|
|
|
# 창 재정렬
|
|
|
|
|
bind Space next-layout
|
|
|
|
|
|
|
|
|
|
# 창 회전
|
|
|
|
|
bind o rotate-window
|
|
|
|
|
|
|
|
|
|
# 창 이름 변경
|
|
|
|
|
bind , command-prompt "rename-window %%"
|
|
|
|
|
|
|
|
|
|
# 창 닫기
|
|
|
|
|
bind & kill-window
|
|
|
|
|
|
|
|
|
|
# 세션 재시작
|
|
|
|
|
bind r source-file ~/.tmux.conf \; display "Reloaded!"
|
|
|
|
|
|
|
|
|
|
# 상태 표시줄 설정
|
|
|
|
|
set -g status-bg colour235
|
|
|
|
|
set -g status-fg colour136
|
|
|
|
|
set -g status-left-length 40
|
|
|
|
|
set -g status-right-length 40
|
|
|
|
|
set -g status-interval 5
|
|
|
|
|
set -g history-limit 10000
|
|
|
|
|
|
|
|
|
|
# 상태 표시줄 왼쪽 내용
|
|
|
|
|
set -g status-left '#[fg=green]#S #[fg=yellow]#H'
|
|
|
|
|
|
|
|
|
|
# 상태 표시줄 오른쪽 내용
|
|
|
|
|
set -g status-right '#[fg=cyan]%Y-%m-%d #[fg=green]%H:%M:%S'
|
|
|
|
|
|
|
|
|
|
# 활성 창 스타일
|
|
|
|
|
#set -g window-active-style 'fg=colour250,bg=colour232'
|
|
|
|
|
|
|
|
|
|
# 비활성 창 스타일
|
|
|
|
|
#set -g window-style 'fg=colour247,bg=colour236'
|
|
|
|
|
|
|
|
|
|
# 패널 테두리 색상
|
|
|
|
|
#set -g pane-border-fg colour238
|
|
|
|
|
#set -g pane-active-border-fg colour51
|
|
|
|
|
set-option -g pane-border-style 'fg=colour244'
|
|
|
|
|
set-option -g pane-active-border-style 'fg=colour77'
|
|
|
|
|
|
|
|
|
|
# 복사 모드에서 vi 키 바인딩 사용
|
|
|
|
|
setw -g mode-keys vi
|
|
|
|
|
|
|
|
|
|
# 마우스 지원 활성화
|
|
|
|
|
set -g mouse on
|
|
|
|
|
|
|
|
|
|
# 256색 지원
|
|
|
|
|
set -g default-terminal "screen-256color"
|
|
|
|
|
|
|
|
|
|
# for pi
|
|
|
|
|
set -g extended-keys on
|
|
|
|
|
set -g extended-keys-format csi-u
|
|
|
|
|
TMUXCONF
|
|
|
|
|
|
|
|
|
|
success ".tmux.conf deployed to $CONF_FILE"
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
# Step 3: Post-install notes
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
info ""
|
|
|
|
|
info "=================================================="
|
|
|
|
|
success "tmux installation complete!"
|
|
|
|
|
info "=================================================="
|
|
|
|
|
info ""
|
|
|
|
|
info "Getting started:"
|
|
|
|
|
info " tmux - Start a new session"
|
|
|
|
|
info " tmux new -s <name> - Start a named session"
|
|
|
|
|
info " tmux attach -t <name> - Attach to a session"
|
|
|
|
|
info " tmux ls - List sessions"
|
|
|
|
|
info ""
|
|
|
|
|
info "Key bindings (customized via .tmux.conf):"
|
|
|
|
|
info " Ctrl-a | - Split horizontally"
|
|
|
|
|
info " Ctrl-a - - Split vertically"
|
|
|
|
|
info " Ctrl-a h/j/k/l - Navigate panes (vim-style)"
|
|
|
|
|
info " Ctrl-a r - Reload .tmux.conf"
|
|
|
|
|
info ""
|
|
|
|
|
info "Config file: $CONF_FILE"
|