Skip to content

Instantly share code, notes, and snippets.

@kevinma2010
Last active September 2, 2025 16:56
Show Gist options
  • Select an option

  • Save kevinma2010/fb82cb493c3db4ea39e2b536b9bf092e to your computer and use it in GitHub Desktop.

Select an option

Save kevinma2010/fb82cb493c3db4ea39e2b536b9bf092e to your computer and use it in GitHub Desktop.
一键启动工作空间( NeoVim, tmux, Claude Code, Codex)
#!/bin/bash
# 智能session命名:使用当前目录名或自定义名称
if [ -z "$1" ]; then
# 获取当前目录名,并清理特殊字符(空格、点号等)
SESSION_NAME=$(basename "$PWD" | tr '.' '-' | tr ' ' '-')
else
SESSION_NAME=$1
fi
# 检查session是否已存在
tmux has-session -t "$SESSION_NAME" 2>/dev/null
if [ $? != 0 ]; then
# 创建新session和窗格布局
tmux new-session -d -s "$SESSION_NAME" -c "$PWD"
tmux send-keys -t "$SESSION_NAME" 'nvim +"Neotree focus"' C-m
# 小延迟避免并发问题
sleep 0.3
# 创建右侧终端(30%宽度)
tmux split-window -h -p 30 -t "$SESSION_NAME" -c "$PWD"
# 在右侧窗格自动启动 Claude AI Assistant(先清屏)
tmux send-keys -t "$SESSION_NAME:0.1" 'clear; claude' C-m
# 小延迟避免并发问题
sleep 0.3
# 在右侧窗格再进行水平分割(上下各50%)
tmux split-window -v -p 50 -t "$SESSION_NAME:0.1" -c "$PWD"
# 在新的下方窗格启动 Codex(先清屏)
tmux send-keys -t "$SESSION_NAME:0.2" 'clear; codex' C-m
# 聚焦回左侧nvim
tmux select-pane -t "$SESSION_NAME:0.0"
echo "✨ Workspace '$SESSION_NAME' forged successfully!"
echo "🤖 AI Assistant (Claude and Codex) summoned in right pane!"
else
echo "🔄 Rejoining existing workspace '$SESSION_NAME'..."
fi
# 进入工作空间
tmux attach-session -t "$SESSION_NAME"
# 退出后自动清屏
clear
# --- General ---
set -g mouse on # 开启鼠标支持
set -g history-limit 10000 # 增加历史行数
# --- Keybindings ---
# 设置一个新的、更顺手的前缀键 Ctrl+a
# a is easier to reach than b
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# 使用 r 键重载配置文件,立即生效
bind r source-file ~/.tmux.conf \; display "Reloaded!"
# 使用 | 和 - 来分割窗口,更直观
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
# 使用 Vim 的方式在窗格间切换
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# --- UI ---
# 状态栏设置
set -g status-position bottom
set -g status-bg colour234 # 背景色
set -g status-fg colour137 # 前景色
set -g status-left "" # 左边不显示东西
set -g status-right "#[fg=colour233,bg=colour241,bold] %m/%d %H:%M:%S " # 右边显示时间
set -g status-right-length 50
set -g status-left-length 20
# 高亮当前窗口
set-window-option -g window-status-current-style fg=colour16,bg=colour255,bold
set-window-option -g window-status-current-format ' #I#[fg=colour249]:#[fg=colour255]#W#[fg=colour249]#F '
# 普通窗口
set-window-option -g window-status-style fg=colour138,bg=colour235,none
set-window-option -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F '
# --- Clipboard ---
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
# === 会话管理快捷键 ===
# Ctrl+a s - 默认的session列表
# Ctrl+a Q - 快速切换session(更常用)
bind Q choose-session
# === 退出和销毁快捷键 ===
# Ctrl+a X (大写X) 快速杀死当前session无需确认
bind X kill-session
# Ctrl+a K (大写K) 带确认的杀死session
bind K confirm-before -p "Kill session #S? (y/n)" "kill-session"
# Ctrl+a Ctrl+x 选择并销毁session
bind C-x choose-session "kill-session -t '%%'"
# Ctrl+a Ctrl+q 优雅退出(分离)
bind C-q detach-client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment