From a4454c5d982dd4f76f0f0ab3fa27d9f98ba20c7d Mon Sep 17 00:00:00 2001 From: warlock <941510759> Date: Thu, 3 Jun 2021 16:51:50 +0800 Subject: [PATCH] tmux_config --- tmux_config/install_tmux.sh | 55 ++++++++ tmux_config/tmux.conf | 242 +++++++++++++++++++++++++++++++++++ tmux_config/tmux.remote.conf | 13 ++ 3 files changed, 310 insertions(+) create mode 100755 tmux_config/install_tmux.sh create mode 100644 tmux_config/tmux.conf create mode 100644 tmux_config/tmux.remote.conf diff --git a/tmux_config/install_tmux.sh b/tmux_config/install_tmux.sh new file mode 100755 index 0000000..ff223fd --- /dev/null +++ b/tmux_config/install_tmux.sh @@ -0,0 +1,55 @@ +#!/usr/bin/bash + +## +# tmux采用C/S模型构建,输入tmux命令就相当于开启了一个服务器,此时默认将新建一个会话,然后会话中默认新建一个窗口,窗口中默认新建一个面板。会话、窗口、面板之间的联系如下: +#一个tmux session(会话)可以包含多个window(窗口),窗口默认充满会话界面,因此这些窗口中可以运行相关性不大的任务。 +#一个window又可以包含多个pane(面板),窗口下的面板,都处于同一界面下,这些面板适合运行相关性高的任务,以便同时观察到它们的运行情况。 +# +# + +set -e +set -u +set -o pipefail + + +REDIR="$(cd "$(dirname "$0")";pwd -P)" +cd $REDIR + +check_installed(){ + type "$1" &>/dev/null +} + +if ! check_installed tmux;then + printf "WARNING:Command 'tmux' not found" + exit 1 +else + printf "yes,you success installed 'tmux'\n" +fi + +if [ ! -e "$HOME/.tmux/plugins/tpm" ]; then + printf "WARNING: Cannot found TPM (Tmux Plugin Manager) \ + at default location: \$HOME/.tmux/plugins/tpmi.\n" + git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm +fi + +if [ -e "$HOME/.tmux.conf" ]; then + printf "Found file '.tmux.conf' in your \$HOME directory. Will create a backup at $HOME/.tmux.conf.bak\n" +fi + +cp -vf "$HOME/.tmux.conf" "$HOME/.tmux.conf.bak" 2>/dev/null || true +cp -av ./* ~/.tmux/ +ln -sf -v ./tmux.conf ~/.tmux/tmux.conf + +# Install TPM plugins. +# TPM requires running tmux server, as soon as `tmux start-server` does not work +# create dump __noop session in detached mode, and kill it when plugins are installed +printf "Install TPM plugins\n" +tmux new -d -s __noop >/dev/null 2>&1 || true +tmux set-environment -g TMUX_PLUGIN_MANAGER_PATH "~/.tmux/plugins" +"$HOME"/.tmux/plugins/tpm/bin/install_plugins || true +tmux kill-session -t __noop >/dev/null 2>&1 || true + +printf "OK: Completed\n" + +## chang +sed -i "s/google/baidu/g" ~/.tmux/plugins/tmux-online-status/scripts/online_status_icon.sh diff --git a/tmux_config/tmux.conf b/tmux_config/tmux.conf new file mode 100644 index 0000000..b29c38d --- /dev/null +++ b/tmux_config/tmux.conf @@ -0,0 +1,242 @@ +# ===================== +# = my tmux srttings = +# ===================== +# http://man.openbsd.org/OpenBSD-current/man1/tmux.1 + + +set -g -q mouse on ## 鼠标 +set -g default-terminal "screen-256color" ## 设置颜色 256 +#set -s default-terminal 'tmux-256color' + +# === encoding === +# === 编码 === +#set -g utf8 on # 开启窗口的UTF-8支持 +#set -g status-utf8 on + +#set-window-option -g mode-mouse on # 窗口切换后让人可以用鼠标上下滑动显示历史输出 +set -g history-limit 500000 # boost history +set-option -g display-time 5000 # 提示信息的持续时间;设置足够的时间以避免看不清提示,单位为毫>秒 + + +# === bar windows === +# === 状态栏 === +#set -g status-position top +set -g renumber-windows on +set -g status-interval 1 #刷新 +setw -g monitor-activity on # 非当前窗口有内容更新时在状态栏通知 +set -g visual-activity on +set -s focus-events on +setw -g bell-action any +set -g set-clipboard on + +# 通知方式 +setw -g monitor-activity on +set -g visual-activity on + +set -g base-index 1 ## 从 1 开始编号,而不是从 0 开始 +setw -g pane-base-index 1 + +setw -g automatic-rename off +set -g renumber-windows off +set-option -g allow-rename off + + + +bind '"' splitw -v -c '#{pane_current_path}' # 垂直方向新增面板,默认进入当前目录 +bind % splitw -h -c '#{pane_current_path}' # 水平方向新增面板,默认进入当前目录 +bind C-c splitw -c '#{pane_current_path}' # 新增面板,默认进入当前目录 +bind c new-window -c "#{pane_current_path}" + + +set-hook -g after-new-window 'command-prompt -I "#{window_name}" "rename-window '%%'"' #立刻重命名 +# =================== +# === key === +# =================== + +set-window-option -g mode-keys vi # 复制模式中的默认键盘布局;可以设置为vi或emacs +set -g status-keys vi + +set-option -g prefix 'C- ' +set-option -g prefix2 'C-\' + + +bind -n M-Left select-pane -L #绑定Alt ← +bind -n M-Right select-pane -R #绑定Alt → +bind -n M-Up select-pane -U #绑定Alt ↑ +bind -n M-Down select-pane -D #绑定Alt ↓ + + + +# ================== +# == panl +# ================== + + +color_dark="$color_black" +color_light="$color_white" +color_orange="colour166" # 208, 166 +color_purple="colour134" # 135, 134 +color_green="colour076" # 070 +color_blue="colour39" +color_yellow="colour220" +color_red="colour160" +color_black="colour232" +color_white="white" # 015 + +color_dark="$color_black" +color_light="$color_white" +color_session_text="$color_blue" +color_status_text="colour245" +color_main="$color_orange" +color_secondary="$color_purple" +color_level_ok="$color_green" +color_level_warn="$color_yellow" +color_level_stress="$color_red" +color_window_off_indicator="colour088" +color_window_off_status_bg="colour238" +color_window_off_status_current_bg="colour254" + +set -g status on +set -g set-titles on +set -g set-titles-string "[#S] #I:#W" +set-option -g status-justify "left" # 窗口列表居中显示 centre + +# tmux-plugin-sysstat +set -g status-interval 1 + + +set-option -g status-bg $color_dark # 状态栏背景颜色 +set-option -g status-fg $color_light # 状态栏前景颜色 + +set -g window-status-separator "" +separator_powerline_left="" +separator_powerline_right="" + + +wg_session="#[fg=$color_session_text] #S #[default]" +#wg_is_zoomed="#[fg=$color_light,bg=$color_secondary]#{?window_zoomed_flag,⛶ ,}#[default]" ## ▣ +wg_is_zoomed="#{?window_zoomed_flag,🐸,}#[default]" ## +wg_is_keys_off="#[fg=$color_light,bg=$color_window_off_indicator]#([ $(tmux show-option -qv key-table) = 'off' ] && echo 'OFF')#[default]" +wg_date="#[fg=$color_secondary]%H:%M:%S#[default]" +wg_user_host="#[fg=$color_secondary]#(whoami)@#H" + +set-option -g status-left-length 60 # 状态栏左方的内容长度; +set-option -g status-right-length 100 # 状态栏右方的内容长度;建议把更多的空间留给状态栏左方(用于列出当前窗口) +#set-option -g status-left "[#{session_name}] #[default]" # 状态栏左方的内容 +set -g status-left "$wg_session" +set -g status-right "#{prefix_highlight}$wg_is_zoomed[#{sysstat_cpu} #{sysstat_mem} #{sysstat_loadavg}][$wg_user_host $wg_date]#{online_status}" +# 状态栏右方的内容;这里的设置将得到类似23:59的显示 + +#set -g status-right '#{prefix_highlight} [#($TMUX_PLUGIN_MANAGER_PATH/tmux-mem-cpu-load/tmux-mem-cpu-load -c -g 7 --interval 2)] [#H]' # 状态栏右方的内容;这里的设置将得到类似23:59的显示 + + +# # 分割窗口边界的颜色 +# set-option -g pane-active-border-fg '#55ff55' +# set-option -g pane-border-fg '#555555' +# 当前激活窗口在状态栏的展位格式 +setw -g window-status-current-style "fg=$color_light,bold,bg=$color_main" +setw -g window-status-current-format "#[fg=$color_dark,bg=$color_main]$separator_powerline_right#[default] #I:#W #[fg=$color_main,bg=$color_dark]$separator_powerline_right#[default]" +# 未激活每个窗口占位的格式 +setw -g window-status-format ' #I:#W' + +setw -g window-status-activity-style "fg=$color_main" +setw -g pane-active-border-style "fg=$color_main" + +#set -g @sysstat_mem_view_tmpl '#Used [fg=#{mem.color}]#{mem.used}#[default] out of #{mem.total}' +#set -g @sysstat_cpu_view_tmpl '#Used [fg=#{cpu.color}]#{cpu.used}#[default] out of #{cpu.total}' +#set -g @sysstat_cpu_view_tmpl '#{cpu.pused}' + +#--- +# 刷新 +bind-key r source-file ~/.tmux.conf \; display-message "tmux.conf reloaded" + + + + +#run-shell -b /home/h/SoftWare/tmux-onedark-theme/tmux-onedark-theme.tmux + + +# List of plugins +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-sensible' +set -g @plugin 'samoshkin/tmux-plugin-sysstat' +set -g @plugin 'thewtex/tmux-mem-cpu-load' +#set -g @plugin 'tmux-plugins/tmux-battery' +set -g @plugin 'tmux-plugins/tmux-online-status' +set -g @plugin 'tmux-plugins/tmux-prefix-highlight' + +##set -g @plugin 'odedlaz/tmux-onedark-theme' + +##set -g @plugin 'tmux-plugins/tmux-prefix-highlight' +set -g @prefix_highlight_show_copy_mode 'on' +set -g @prefix_highlight_show_sync_mode 'on' + +set -g @prefix_highlight_output_prefix '' +set -g @prefix_highlight_prefix_prompt '⌨ ' +set -g @prefix_highlight_output_suffix '' + +set -g @prefix_highlight_fg "$color_dark" +set -g @prefix_highlight_bg "$color_secondary" + + +##set -g @plugin 'tmux-plugins/tmux-online-status' +set -g @online_icon "#[fg=$color_level_ok]●#[default]" +set -g @offline_icon "#[fg=$color_level_stress]●#[default]" + + +# +set -g @sysstat_cpu_color_low "$color_level_ok" +set -g @sysstat_cpu_color_medium "$color_level_warn" +set -g @sysstat_cpu_color_stress "$color_level_stress" + +set -g @sysstat_mem_color_low "$color_level_ok" +set -g @sysstat_mem_color_medium "$color_level_warn" +set -g @sysstat_mem_color_stress "$color_level_stress" + +set -g @sysstat_swap_color_low "$color_level_ok" +set -g @sysstat_swap_color_medium "$color_level_warn" +set -g @sysstat_swap_color_stress "$color_level_stress" + +set -g @sysstat_mem_view_tmpl '🖸 :#[fg=#{mem.color}]#{mem.pused}#[default]' +set -g @sysstat_cpu_view_tmpl '🖵 :#[fg=#{cpu.color}]#{cpu.pused}#[default]' + +# Other examples: +# set -g @plugin 'github_username/plugin_name' +# set -g @plugin 'git@github.com:user/plugin' +# set -g @plugin 'git@bitbucket.com:user/plugin' + + +# ============================================== +# === Nesting local and remote sessions === +# ============================================== + + +if-shell 'test -n "$SSH_CLIENT"' \ + 'source-file ~/.tmux/tmux.remote.conf' + + +bind -T root F12 \ + set prefix None \;\ + set key-table off \;\ + set status-style "fg=$color_status_text,bg=$color_window_off_status_bg" \;\ + set window-status-current-format "#[fg=$color_window_off_status_bg,bg=$color_window_off_status_current_bg]$separator_powerline_right#[default] #I:#W# #[fg=$color_window_off_status_current_bg,bg=$color_window_off_status_bg]$separator_powerline_right#[default]" \;\ + set window-status-current-style "fg=$color_dark,bold,bg=$color_window_off_status_current_bg" \;\ + if -F '#{pane_in_mode}' 'send-keys -X cancel' \;\ + refresh-client -S \;\ + +bind -T off F12 \ + set -u prefix \;\ + set -u key-table \;\ + set -u status-style \;\ + set -u window-status-current-style \;\ + set -u window-status-current-format \;\ + refresh-client -S + + + + + +# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) +run '~/.tmux/plugins/tpm/tpm' + +##run-shell '~/.tmux/plugins/tmux-onedark-theme/tmux-onedark-theme.tmux' diff --git a/tmux_config/tmux.remote.conf b/tmux_config/tmux.remote.conf new file mode 100644 index 0000000..ce7dcab --- /dev/null +++ b/tmux_config/tmux.remote.conf @@ -0,0 +1,13 @@ +# show status bar at bottom for remote session, +# so it do not stack together with local session's one +set -g status-position top + +# Set port of SSH remote tunnel, where tmux will pipe buffers to transfer on local machine for copy +set -g @copy_backend_remote_tunnel_port 11988 + +# In remote mode we don't show "clock" and "battery status" widgets + +set -g status-left "$wg_session" +set -g status-right "#{prefix_highlight}$wg_is_keys_off$wg_is_zoomed[#{sysstat_cpu} #{sysstat_mem} #{sysstat_loadavg}]$wg_user_host#{online_status}" +setw -g window-status-current-style "fg=$color_light,bold,bg=$color_blue" +setw -g window-status-current-format "#[fg=$color_dark,bg=$color_blue]$separator_powerline_right #I:#W #[fg=$color_blue,bg=$color_dark]$separator_powerline_right#[default]"