Last active
June 28, 2024 06:16
-
-
Save potoo0/156c3e83575ba63d661cb80949e8f811 to your computer and use it in GitHub Desktop.
simple tmux conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################# tmux config ############################# | |
# : << EOF do not edit! 含义: 将 E-O-F 之间的重定向到 `:`, 也就是丢弃 | |
# `tmux -V` > tmux3.2a+ | |
# tmux 3.4 以上支持 run-shell 增加可选项 -c 来指定工作目录(issue 3661), eg: -c '#{pane_current_path}' | |
# config path: /etc/tmux.conf, ~/.config/tmux/tmux.conf, ~/.tmux.conf | |
# set(set-option): 如果选项不是用户选项,则 -w 或 -s 可省略,tmux 会根据设置名称自动推断. | |
# setw: set -w 的简写 | |
# bind(bind-key): 默认绑定到 prefix 表格中(相当于指定参数 -Tprefix), -N 用来写备注 | |
# 命令语法: https://man7.org/linux/man-pages/man1/tmux.1.html#PARSING_SYNTAX | |
# --------------------------- general --------------------------- | |
set -g default-terminal "screen-256color" # 也会作为环境变量 TERM 的默认值 | |
if 'infocmp -x tmux-256color > /dev/null 2>&1' 'set -g default-terminal "tmux-256color"' | |
set -g history-limit 100000 # default is 2000 | |
set -g automatic-rename off # 禁止 window auto-rename(打开会在每次执行命令后尝试重命名) | |
set -g allow-rename off # 禁止 pane 的程序修改 window 的名称 | |
set -g renumber-windows on # window 销毁后对 window 重新编号 | |
set -g base-index 1 # window 编号起始为 1, default is 0 | |
set -g pane-base-index 1 # pane 编号起始为 1 | |
set -g focus-events on # 传递 focus 事件给 tmux 内运行的程序 | |
# activity 与 bell(https://github.com/tmux/tmux/wiki/Advanced-Use#alerts-and-monitoring): | |
# activity: 有输出(stdout/stderr), 比如 tail -f ... | |
# bell : 发送了 ASCII BEL, 比如 bash/zsh: echo -e '\a' | |
set -g monitor-activity on # 监视 activity | |
set -g visual-activity off # 有活动时只 bell, 而不要状态栏显示 message | |
# set ctrl-a as secondary prefix key | |
set -g prefix2 C-a | |
bind -N 'secondary prefix key' C-a send-prefix -2 | |
# --------------------------- key table=root --------------------------- | |
bind -n -N 'clear screen and history' C-l send-keys C-l \; run 'sleep 0.1' \; clear-history | |
# bind ctrl+tab for next-window. | |
# mintty 需要关闭 *Switch window* | |
# windows terminal 需要增加 actions: { "command": {"action": "sendInput", "input": "\u001b[27;5;9~"}, "keys": "ctrl+tab" } | |
%if #{MSYSTEM} | |
set -s user-keys[0] "\e[1;5I" | |
bind -nr -N 'switch to next window' User0 next-window | |
%else | |
bind -nr -N 'switch to next window' C-Tab next-window | |
%endif | |
# --------------------------- key table=prefix --------------------------- | |
bind -N 'clear screen and history' C-l send-keys C-l \; run 'sleep 0.1' \; clear-history | |
bind -N 'switch to last window' Tab last-window | |
bind -N 'create session' C-c new-session | |
bind -N 'split-window horizontally' - split-window -v | |
bind -N 'split-window vertically' _ split-window -h | |
bind -N 'toggle zoom' + resize-pane -Z | |
bind -N 'toggle mouse mode' m { | |
set -g mouse #{?mouse,off,on} | |
display ">>>mouse: #{?mouse,on,off}" | |
} | |
bind -N 'cap pane history to file' C-p { | |
command-prompt -I '-#{history_limit},~/tmux-cap-#{session_name}-#{window_index}-#{pane_index}-%Y%m%d%H%M%S.log' -p 'start-line relative to visible pane:,save to:' { | |
run "tmux capture-pane -pS %1 > %2 \\; display 'saved pane history(start-line=%1) to file %2'" | |
} | |
} | |
bind -N 'reload config' r { | |
source-file -q /etc/tmux.conf ~/.config/tmux/tmux.conf ~/.tmux.conf | |
display 'config reloaded' | |
} | |
# --------------------------- status bar --------------------------- | |
set -g display-time 2000 # 状态栏消息显示时间 | |
# prefix 按下以及鼠标模式 右下角提示, 以及修改时间格式为 15:16 23/02/24 | |
# 原配置: `tmux display -p '#{status-right}'` | |
set -g status-right '#{?mouse,↖ | ,}#{?client_prefix,#[reverse]<C>#[noreverse] | ,}#{?window_bigger,[#{window_offset_x}#,#{window_offset_y}] | ,}"#{=21:pane_title}" | %H:%M %d/%m/%y' | |
# 以下配色方案取自 gpakosz/.tmux | |
set -g status-style 'fg=#8a8a8a,bg=#080808' # 状态栏样式 | |
set -g message-style 'fg=#ffff00,bg=#080808' # 状态栏消息样式 | |
set -g message-command-style 'fg=#ffff00,bg=#080808' # 状态栏消息样式 | |
set -g mode-style 'fg=#080808,bg=#00afff' # c-w(choose-tree) 的样式 | |
# 状态栏窗口样式. 注意: activity/bell 会被(来源不明?)修改为 reverse(fg与bg交换), | |
# 如果打开了 monitor-activity 则可能会导致通过脚本创建的初始窗口触发 activity 进而交换了 fg/bg, 所以此处修改它们 | |
set -g window-status-activity-style 'fg=default,bg=default,underscore' | |
set -g window-status-bell-style 'fg=#ffff00,bg=default,blink,bold' | |
set -g window-status-current-style 'fg=#080808,bg=#00afff,bold' # 当前激活 window 样式 | |
set -g window-status-last-style 'fg=#00afff,bg=#303030,none' # 上次激活 window 样式 | |
set -g window-status-style 'fg=#8a8a8a,bg=#080808,none' # window 默认样式 | |
# do not edit! | |
# EOF | |
############################### shell script ############################### | |
# set -e | |
# _uptime() { | |
# } | |
# # do not edit!, 用来 `sh -s` 执行指定函数 | |
# "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment