rwx/sh/tmux.sh
2025-01-26 14:41:08 +01:00

264 lines
7.7 KiB
Bash

# ╭──────┬───────╮
# │ tmux │ setup │
# ╰──────┴───────╯
rwx_tmux_setup() {
local file
file="${HOME}/.tmux.conf"
rwx_file_write "${file}" "\
# ╭────────╮
# │ option │
# ╰────────╯
# empty name for windows
set-option -g automatic-rename-format '#{pane_current_command}'
set-option -g automatic-rename on
# first index number
set-option -g base-index 1
# display duration
set-option -g display-time 1536
# extend history limit
set-option -g history-limit 1048576
# style for messages
set-option -g message-style bg=red,fg=white
# activity monitoring
set-window-option -g monitor-activity on
# silence monitoring
set-window-option -g monitor-silence 0
# enable mouse actions
set-option -g mouse on
# prefix with ^B or F12
set-option -g prefix C-b
set-option -g prefix2 F12
# renumber windows after closing one
set-option -g renumber-windows on
# enable title
set-option -g set-titles on
# set title to working directory
set-option -g set-titles-string '\
#{session_name}\
- \
#{window_index}∕#{session_windows} #{window_name}\
- \
#{pane_index}∕#{window_panes} #{pane_current_command}\
'
# ╭────────┬──────╮
# │ option │ pane │
# ╰────────┴──────╯
# first index number
set-option -g pane-base-index 1
# ╭────────┬──────┬────────╮
# │ option │ pane │ border │
# ╰────────┴──────┴────────╯
# active style
set-option -g pane-active-border-style fg=green
# regular style
set-option -g pane-border-style fg=blue
# ╭────────┬────────╮
# │ option │ status │
# ╰────────┴────────╯
# status lines
set-option -g status 3
# background color
set-option -g status-bg '#0D0D0D'
# foreground color
set-option -g status-fg white
# line 1
set-option -g status-format[0] '\
#{W:\
#[bg=##202020] #[bg=##303030]\
#{?window_zoomed_flag,#[fg=magenta][, }\
#[fg=yellow]#{window_index}\
#{?window_zoomed_flag,#[fg=magenta]], }\
\
#{?window_active,#[fg=green],\
#{?window_activity_flag,#[fg=red],#[fg=blue]}}\
#{window_name}\
#[bg=##303030] #[bg=##202020] \
#[bg=default] \
}\
#[align=right]\
#[bg=##202020] #[bg=##303030] \
#[fg=yellow]%H:%M:%S\
#[bg=##303030] #[bg=##202020]\
#{?client_prefix,#[fg=green]p, }\
'
# line 2
set-option -g status-format[1] '\
#{S:\
#[bg=##202020] #[bg=##303030] \
#{?session_many_attached,#[fg=red],\
#{?session_attached,#[fg=magenta],#[fg=blue]}}\
#{session_name}\
#[bg=##303030] #[bg=##202020] \
#[bg=default] \
}\
#[fg=yellow]→ #[fg=green]#{session_name} \
#[align=right]\
#[bg=##202020] #[bg=##303030] \
#[fg=yellow]%Y-%m-%d\
#[bg=##303030] #[bg=##202020] \
'
# line 3
set-option -g status-format[2] '\
#[fg=cyan]#{pane_current_path}\
#[align=right]\
#[bg=##202020] #[bg=##303030] \
#[fg=yellow]#{host}\
#[bg=##303030] #[bg=##202020] \
'
# line 4
set-option -g status-format[3] '\
#{P:\
#[bg=##202020] #[bg=##303030] \
#[fg=yellow]#{pane_index}\
\
#{?pane_active,#[fg=green],#[fg=blue]}\
#{pane_current_command}\
#[bg=##303030] #[bg=##202020] \
#[bg=default] \
}\
#[align=right]\
#[bg=##202020] #[bg=##303030] \
#{?uid,#[fg=green],#[fg=red]}\
#{user}\
#[bg=##303030] #[bg=##202020] \
'
# line 5
set-option -g status-format[4] '\
#{P:\
#[bg=##202020] #[bg=##303030] \
#[fg=yellow]#{pane_index}\
\
#{?pane_active,#[fg=green],#[fg=blue]}\
#{pane_width}×#{pane_height}\
#[bg=##303030] #[bg=##202020] \
#[bg=default] \
}\
#[align=right]\
#[bg=##202020] #[bg=##303030] \
#[fg=green]#{window_width}×#{window_height}\
#[bg=##303030] #[bg=##202020] \
'
# refresh period
set-option -g status-interval 1
# bar location
set-option -g status-position bottom
# ╭─────╮
# │ key │
# ╰─────╯
# detach client
bind-key -n F6 detach-client
# new window
bind-key -n F2 new-window
# select pane
bind-key -n C-S-Down select-pane -D
bind-key -n C-S-Left select-pane -L
bind-key -n C-S-Right select-pane -R
bind-key -n C-S-Up select-pane -U
# status lines
bind-key -n C-F10 set-option -g status off
bind-key -n C-F1 set-option -g status on
bind-key -n C-F2 set-option -g status 2
bind-key -n C-F3 set-option -g status 3
bind-key -n C-F4 set-option -g status 4
bind-key -n C-F5 set-option -g status 5
# switch session
bind-key -n M-Down switch-client -n
bind-key -n M-Up switch-client -p
# switch window
bind-key -n M-Left previous-window
bind-key -n M-Right next-window
# ╭─────┬────────╮
# │ key │ prefix │
# ╰─────┴────────╯
# rename
bind-key C-s command-prompt { rename-session '%%' }
bind-key C-w command-prompt { rename-window '%%' }
# split window
bind-key h split-window -h
bind-key v split-window -v
# toggle mouse
bind-key t set-option -g mouse \\; display-message 'mouse = #{mouse}'
# reload configuration
bind-key r source-file ${file} \\; display-message 'source-file ${file}'
# swap window
bind-key M-Left swap-window -t -1
bind-key M-Right swap-window -t +1
# ╭─────────────╮
# │ default │
# ╭───────────┬─────────┼─────┬───────┤
# │ -n │ F12 │ -n │ C-b │
# ╭───────────────────┼───────────┼─────────┼─────┼───────┤
# │ command-prompt │ │ │ │ : │
# │ copy-mode │ │ │ │ PPage │
# │ detach-client │ │ │ │ d │
# │ new-session │ │ │ │ │
# │ new-window │ F2 │ │ │ c │
# │ next-window │ M-Right │ │ │ n │
# │ previous-window │ M-Left │ │ │ p │
# │ rename-session │ │ C-s │ │ │
# │ rename-window │ │ C-w │ │ │
# │ resize-pane -Z │ │ │ │ z │
# │ select-pane -D │ C-S-Down │ │ │ │
# │ select-pane -L │ C-S-Left │ │ │ │
# │ select-pane -R │ C-S-Right │ │ │ │
# │ select-pane -U │ C-S-Up │ │ │ │
# │ set -g mouse │ │ t │ │ │
# │ set -g status off │ C-F10 │ │ │ │
# │ set -g status on │ C-F1 │ │ │ │
# │ set -g status 2 │ C-F2 │ │ │ │
# │ set -g status 3 │ C-F3 │ │ │ │
# │ set -g status 4 │ C-F4 │ │ │ │
# │ set -g status 5 │ C-F5 │ │ │ │
# │ source-file │ │ r │ │ │
# │ split-window -h │ │ h │ │ % │
# │ split-window -v │ │ v │ │ \" │
# │ swap-window -t -1 │ │ M-Left │ │ │
# │ swap-window -t +1 │ │ M-Right │ │ │
# │ switch-client -n │ M-Down │ │ │ │
# │ switch-client -p │ M-Up │ │ │ │
# ╰───────────────────┴───────────┴─────────┴─────┴───────╯
"
}