새롭게 서버 세팅할 때 까먹지 않기 위해..
0. Zsh 및 플러그인들 설치하기
Zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
conda-zsh-completion
git clone https://github.com/esc/conda-zsh-completion ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/conda-zsh-completion
1. 기본 쉘 설정
VS Code 터미널을 열 때 bash 대신 zsh가 바로 뜨도록 설정한다.
-
Cmd+,(설정) 입력 -
terminal.integrated.defaultProfile.linux검색 -
값을 zsh 로 바꾸기
.zshrc 파일 열어서 아래 내용 붙여넣기. 당연하게도 더 좋게 가능
# [1] Oh My Zsh 및 경로 설정
export ZSH="$HOME/.oh-my-zsh"
# [2] 테마 설정
ZSH_THEME="agnoster"
# [3] 플러그인 설정
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
conda-zsh-completion
)
# [4] Oh My Zsh 실행
source $ZSH/oh-my-zsh.sh
# [5] 사용자 정의 함수 및 alias
# Tmux 자동 접속 (ta)
function ta() {
local sn="${1:-dev}"
if tmux has-session -t "$sn" 2>/dev/null; then
echo "Attaching to session: $sn"
tmux attach-session -t "$sn"
else
echo "Creating new session: $sn"
tmux new-session -s "$sn"
fi
}
# 슬랙 알림 함수
function alert() {
# 복사한 Webhook URL을 아래 따옴표 안에 넣기
local url="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
local status=$? # 이전 명령어의 성공(0) 또는 실패(비영) 상태 저장
local message
if [ $status -eq 0 ]; then
message="✅ *실험 종료 (Success)*\n>"
else
message="❌ *실험 종료 (Failed)*\n> 에러 발생 (Exit Code: $status)"
fi
# 슬랙에 JSON 데이터 전송
curl -s -X POST -H 'Content-type: application/json' \
--data "{'text': '$message'}" $url > /dev/null
}
# [6] Agnoster 테마 커스텀 (라벨 설정)
export CONDA_CHANGEPS1=false
# 1. 가상환경 라벨 (배경: 파스텔 분홍 217, 글자: 흰색 15)
prompt_virtualenv() {
if [[ -n $CONDA_DEFAULT_ENV ]]; then
prompt_segment 217 15 "$CONDA_DEFAULT_ENV"
fi
}
# 2. 사용자 정보 라벨 (비활성화 - 프롬프트를 깔끔하게 유지)
prompt_context() {}
# 3. 현재 디렉토리 라벨 (배경: 다크 그레이 237, 글자: 흰색 15)
prompt_dir() {
prompt_segment 237 15 '%~'
}
# 4. 프롬프트 마침 (새 줄에서 청록색 화살표 시작)
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
print -n "%{%k%}"
fi
print -n "%{%f%}"
CURRENT_BG=''
print -P "\n%B%F{45} ➜ %f%b"
}
source /opt/anaconda3/bin/activate
2. tmux 세팅하기
home directory에 .tmux.conf 파일을 만들고, 아래 내용 복사 붙여넣기
# Ctrl+S 를 prefix 키로 설정
unbind C-b
set -g prefix C-s
bind C-s send-prefix
# [화면 분할] 직관적으로 | - 이용
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# 마우스 설정
set -g mouse on
# Tmux의 기본 쉘을 zsh로 설정 (설정 파일을 읽어오기 위함)
set-option -g default-shell /bin/zsh
# 1. 256비트 색상 지원
set -g default-terminal "screen-256color"
set -as terminal-features ",xterm-256color:RGB"
# 2. 하단바 기본 색
set -g status-style bg=colour237,fg=white
# 3. 왼쪽: 세션 정보 (zsh의 가상환경 라벨인 분홍색 217 사용)
set -g status-left-length 30
set -g status-left "#[bg=colour217,fg=colour15,bold] ❐ #S #[bg=colour237,fg=colour217]"
set -g status-right-length 150
set -g status-right "#[fg=colour211]#[bg=colour211,fg=colour15] CPU: #{cpu_percentage} #[fg=colour108]#[bg=colour108,fg=colour15] 🐍 #(echo $CONDA_DEFAULT_ENV) #[fg=colour67]#[bg=colour67,fg=colour15] %H:%M #[fg=colour237,fg=colour15] #[bg=colour15,fg=colour0] #h "
# 현재 활성화된 창 (zsh의 디렉토리 라벨처럼 민트색 108 배경에 검정 글자)
set-window-option -g window-status-current-format "#[fg=colour237,bg=colour108]#[fg=colour0,bold] #I:#W #[fg=colour108,bg=colour237]"
# 비활성 창 (배경과 동화되도록 다크 그레이 237에 회색 글자)
set-window-option -g window-status-format "#[fg=colour237,bg=colour240]#[fg=colour250] #I:#W #[fg=colour240,bg=colour237]"
# 창 리스트 사이의 공백 제거
set-window-option -g window-status-separator ""
########################################
# 4. 플러그인 설정 (TPM)
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-cpu'
set -g @plugin 'tmux-plugins/tmux-net-speed'
# --- 플러그인 세부 설정 ---
set -g @continuum-restore 'on' # Tmux 실행 시 마지막 세션 자동 복구
run '~/.tmux/plugins/tpm/tpm'