1 июл. 2025 г.

Autorun Tmux 6 panels layout on startup


 

1. Create /root/.tmux.conf

new-session -d -s MYDESK
set -g status off
set -g set-titles on
set -g set-titles-string ""
set -g pane-border-lines double
set -g pane-border-status top
set -g pane-border-format "#P #{pane_tty} PID=#{pane_pid}  PATH=#{pane_current_path} Command=#{pane_current_command} #{pane_title}"
split-window -h -l 80%
select-pane -t 0
split-window -v
split-window -v
select-pane -t 3
split-window -v
split-window -v
select-pane -t 0
send-keys -t MYDESK "cd /opt/proc1" C-m
send-keys -t MYDESK "proc1.sh" C-m
select-pane -t 1
send-keys -t MYDESK "cd /opt/proc2" C-m
send-keys -t MYDESK "proc2.sh" C-m
select-pane -t 2
send-keys -t MYDESK "cd /opt/proc3" C-m
send-keys -t MYDESK "proc3.sh" C-m
select-pane -t 3
send-keys -t MYDESK "cd /opt/proc4" C-m
send-keys -t MYDESK "proc4.sh" C-m
select-pane -t 4
send-keys -t MYDESK "cd /opt/proc5" C-m
send-keys -t MYDESK "proc5.sh" C-m
select-pane -t 5
send-keys -t MYDESK "mc" C-m


2. Add those line to bash script in the pane, to change pane_title if required

printf '\033]2;%s\033\\' "title goes here"
for example, for command line arguments
printf '\033]2;%s\033\\' "$0 $1 $2 $3"

3. Check manual startup

#tmux start-server
#tmux list-sessions
#tmux a -t MYDESK
Ctrl/B D
#tmux kill-server

4. Create rc.local script

#!/bin/sh -e
tmux start-server
exit 0


5. Make rc.local executable

#chmod +x /etc/rc.local

6.Create service file in /etc/systemd/system/rc-local.service

[Unit]
Description=rc.local
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandartOutput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

7. Enable rc.local

#systemctl enable rc-local

8.Reboot and check

#reboot
#tmux a -t MYDESK