rwx/sh/tmux.sh

346 lines
9.2 KiB
Bash
Raw Normal View History

2025-06-28 04:36:16 +02:00
# ╭──────╮
# │ tmux │
# ╰──────╯
# ╭──────┬───────╮
# │ tmux │ setup │
# ╰──────┴───────╯
rwx_tmux_setup() {
2025-06-30 00:28:33 +02:00
local file script
file="${HOME}/.tmux.conf"
2025-06-30 00:28:33 +02:00
script="${HOME}/.tmux.sh"
rwx_file_write "${script}" "\
rwx_tmux_server() {
basename \"\${TMUX}\" |
cut \\
--delimiter \",\" \\
--fields \"1\"
}
2025-06-30 01:08:26 +02:00
rwx_tmux_servers() {
2025-06-30 02:10:17 +02:00
local active=\"\$(rwx_tmux_server)\"
local ifs=\"\${IFS}\"
local name path text
2025-06-30 02:20:11 +02:00
local paths=\"\$(lsof -U |
awk \"/^tmux:.*\\(LISTEN\\)\$/ {print \\\$9}\")\"
2025-06-30 02:10:17 +02:00
IFS=\"
\"
2025-06-30 02:20:11 +02:00
for path in \${paths}; do
2025-06-30 02:10:17 +02:00
name=\"\$(basename \"\${path}\")\"
2025-06-30 03:40:04 +02:00
text=\"\${text}\\
#[fg=default]\\
#[bg=default] \\
\"
2025-06-30 02:10:17 +02:00
if [ \"\${active}\" = \"\${name}\" ]; then
text=\"\${text}#[fg=green]\"
else
text=\"\${text}#[fg=yellow]\"
fi
text=\"\${text}\\
2025-06-30 03:40:04 +02:00
#[bg=##181818] \\
#[bg=##282828]\${name}\\
#[bg=##181818] \\
\"
2025-06-30 02:10:17 +02:00
done
IFS=\"\${ifs}\"
echo \"\${text}\"
2025-06-30 01:08:26 +02:00
}
2025-06-30 03:52:26 +02:00
rwx_tmux_uptime() {
local since=\"\$(uptime --since)\"
local date=\"\$(echo \"\${since}\" | awk '{print \$1}')\"
local time=\"\$(echo \"\${since}\" | awk '{print \$2}')\"
echo \"\\
#[fg=yellow]\\
#[bg=##181818] \\
#[bg=##282828]\${date}\\
#[bg=##181818] \\
#[fg=default]\\
#[bg=default] \\
#[fg=yellow]\\
#[bg=##181818] \\
#[bg=##282828]\${time}\\
#[bg=##181818] \\
\"
}
2025-06-30 00:28:33 +02:00
"
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 '\
2025-06-30 00:28:33 +02:00
#(sh -c \". ${script}; rwx_tmux_server\")\
2025-06-30 03:07:32 +02:00
\
#{session_name}\
2025-06-30 03:07:32 +02:00
\
2025-06-30 03:08:57 +02:00
#{window_name} (#{window_index}∕#{session_windows})\
2025-06-30 03:07:32 +02:00
\
2025-06-30 03:08:57 +02:00
#{pane_current_command} (#{pane_index}∕#{window_panes})\
'
# ╭────────┬──────╮
# │ 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
2025-06-29 10:19:01 +02:00
set-option -g status 2
# background color
2025-06-29 18:34:43 +02:00
set-option -g status-bg '#080808'
# foreground color
set-option -g status-fg white
# line 1
set-option -g status-format[0] '\
#{W:\
#{?window_active,#[fg=green],\
2025-06-29 10:28:14 +02:00
#{?window_activity_flag,#[fg=red],#[fg=yellow]}}\
2025-06-29 19:23:05 +02:00
#[bg=##181818]#{?window_zoomed_flag,#[fg=magenta][, }\
#[bg=##282828]#{window_name}\
#[bg=##181818]#{?window_zoomed_flag,#[fg=magenta]], }\
#[fg=default]\
2025-06-30 04:07:33 +02:00
#[bg=default] \
} \
#[align=right]\
2025-06-29 19:11:36 +02:00
#[fg=yellow]\
#[bg=##181818] \
#[bg=##282828]%H:%M:%S\
#[bg=##181818]#{?client_prefix,#[fg=green]p, }\
'
# line 2
set-option -g status-format[1] '\
#{S:\
2025-06-29 18:40:03 +02:00
#{?session_many_attached,#[fg=magenta],\
#{?session_attached,#[fg=red],#[fg=yellow]}}\
2025-06-29 18:34:43 +02:00
#[bg=##181818] \
2025-06-29 19:26:57 +02:00
#[bg=##282828]#{session_name}\
#[bg=##181818] \
#[fg=default]\
#[bg=default] \
}\
2025-06-29 22:48:06 +02:00
#[fg=white]→\
2025-06-29 19:28:44 +02:00
#[fg=default] \
2025-06-29 19:31:50 +02:00
#[fg=green]\
#[bg=##181818] \
#[bg=##282828]#{session_name}\
#[bg=##181818] \
2025-06-30 04:03:08 +02:00
#[fg=default]\
#[bg=default] \
#[align=right]\
2025-06-29 19:11:36 +02:00
#[fg=yellow]\
#[bg=##181818] \
#[bg=##282828]%Y-%m-%d\
2025-06-29 18:34:43 +02:00
#[bg=##181818] \
'
# line 3
set-option -g status-format[2] '\
2025-06-29 22:42:55 +02:00
#[fg=cyan]#{pane_current_path}\
2025-06-30 04:03:08 +02:00
#[fg=default]\
#[bg=default] \
2025-06-30 03:40:04 +02:00
#[align=right]\
#(sh -c \". ${script}; rwx_tmux_servers\")\
'
# line 4
set-option -g status-format[3] '\
#{P:\
2025-06-29 14:33:59 +02:00
#{?pane_active,#[fg=green],#[fg=yellow]}\
2025-06-29 20:14:40 +02:00
#[bg=##181818] \
#[bg=##282828]#{pane_current_command}\
2025-06-29 18:34:43 +02:00
#[bg=##181818] \
2025-06-29 20:21:22 +02:00
#[fg=default]\
2025-06-30 04:07:33 +02:00
#[bg=default] \
} \
#[align=right]\
2025-06-30 03:52:26 +02:00
#[bg=##282828]#(sh -c \". ${script}; rwx_tmux_uptime\")\
'
# line 5
set-option -g status-format[4] '\
#{P:\
2025-06-29 14:33:59 +02:00
#{?pane_active,#[fg=green],#[fg=yellow]}\
2025-06-29 20:14:40 +02:00
#[bg=##181818] \
#[bg=##282828]#{pane_width}×#{pane_height}\
2025-06-29 18:34:43 +02:00
#[bg=##181818] \
2025-06-29 20:21:22 +02:00
#[fg=default]\
#[bg=default] \
}\
2025-06-29 23:23:51 +02:00
#[fg=white]=\
2025-06-29 22:22:10 +02:00
#[fg=default] \
#[fg=green]\
#[bg=##181818] \
#[bg=##282828]#{window_width}×#{window_height}\
#[bg=##181818] \
2025-06-30 04:03:08 +02:00
#[fg=default]\
#[bg=default] \
#[align=right]\
2025-06-29 22:32:47 +02:00
#{?uid,#[fg=green],#[fg=red]}\
2025-06-29 20:10:26 +02:00
#[bg=##181818] \
2025-06-29 22:23:07 +02:00
#[bg=##282828]#{user}\
2025-06-29 18:34:43 +02:00
#[bg=##181818] \
2025-06-30 02:58:30 +02:00
#[fg=default]\
#[bg=default] \
#[fg=yellow]\
#[bg=##181818] \
#[bg=##282828]#{host}\
#[bg=##181818] \
'
# 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
2025-06-16 15:25:26 +02:00
# new
bind-key -n S-M-Down new-session
bind-key -n S-M-Right 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
2025-06-16 14:33:48 +02:00
bind-key -n C-F6 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
2025-06-29 10:11:44 +02:00
# kill server
bind-key k kill-server
# reload configuration
bind-key r source-file ${file} \\; display-message 'source-file ${file}'
2025-06-29 10:11:44 +02:00
# toggle mouse
bind-key t set-option -g mouse \\; display-message 'mouse = #{mouse}'
# 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 │
2025-06-16 14:33:48 +02:00
# │ detach-client │ F6 │ │ │ d │
2025-06-29 10:11:44 +02:00
# │ kill-server │ │ k │ │ │
# │ 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 │ │ │
2025-06-16 14:33:48 +02:00
# │ set -g status off │ C-F6 │ │ │ │
# │ 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 │ │ │ │
# ╰───────────────────┴───────────┴─────────┴─────┴───────╯
"
}