4

I want to avoid wasting time doing my startup ritual by having the following done automatically:

  1. Open up a new terminal
  2. Run byobu
  3. Split horizontally, then split the two new panes vertically (or vice versa)
  4. Run specific commands for each pane

I'm guessing it will be something along these lines:

gnome-terminal --full-screen -- byobu -S MainSession

byobu-tmux select-pane -t 0
byobu-tmux split-window -v
byobu-tmux select-pane -t 1
byobu-tmux split-window -h
byobu-tmux select-pane -t 0
byobu-tmux split-window -h

byobu-tmux select-pane -t 1
byobu-tmux send-keys "COMMAND"
byobu-tmux select-pane -t 2
byobu-tmux send-keys "COMMAND"
byobu-tmux select-pane -t 3
byobu-tmux send-keys "COMMAND"
byobu-tmux select-pane -t 0

First line on its own would open a new fullscreen terminal and pass the new byobu session command to it. However, I don't know how to connect the rest of the script together. If I put an opening quote before byobu, separate all the commands with ;, and put a closing quote at the end of the script, I get the terminal opened up without byobu, and an error: "Failed to execute child process (No such file or directory)".

In addition, how can I get the terminal opened on a specific monitor? According to gnome-control-center, the monitor I want this to open on is number 3.

2 Answers 2

8

Took me a while to figure it out, so if anyone needs a startup script to open up multiple byobu sessions, use and modify as you like:

#Create new session. I named this LeftMonitor for obvious reasons
byobu new-session -d -s LeftMonitor

#Select default pane. Probably an unnecessary line of code
byobu select-pane -t 0

#Split pane 0 into two vertically stacked panes
byobu split-window -v

#Select the newly created pane 1. Again, probably unnecessary as the new pane gets selected after a split
byobu select-pane -t 1

#Split pane 1 horizontally to create two side-by-side panes
byobu split-window -h

#Repeat the selection and splitting process with the top half
byobu select-pane -t 0
byobu split-window -h
#At this point, four equally sized panes have been created.

#Select pane to interact with
byobu select-pane -t 1

#Pass a command to the selected pane. I'm using top as the example here.
#Note that you need to type Enter for byobu to simulate pressing the enter key.
byobu send-keys "top" Enter

#Create a new session. Session name is again chosen for obvious reasons
byobu new-session -d -s RightMonitor

#Repeat the same splitting and command issuing processes from the first session.
byobu select-pane -t 0
byobu split-window -h
byobu select-pane -t 1
byobu send-keys "top" Enter
byobu select-pane -t 0
byobu send-keys "top" Enter

#Finally, to be able to actually see anything, you need to launch a terminal for each session
gnome-terminal --full-screen -- byobu attach -t LeftMonitor
gnome-terminal --full-screen -- byobu attach -t RightMonitor

Save this with your preferred text editor, run sudo chmod +x on the file, and add it to whatever startup list you use.

0

I did some modification. It would be useful hopefully.

I created - sudo nano /home/replace_by_your_home_dir/.byobu/setup_on_boot.sh :

#!/bin/bash

# Check if the crypto-work session already exists
if byobu list-sessions | grep -q "crypto-work"; then
    echo "crypto-work session already exists. Skipping setup."
    exit 0
fi

# Create new session
byobu new-session -d -s crypto-work

# Rename first windows
byobu rename-window -t 0 Terminal

###################################
# Binance Spot and Futures        #
###################################
byobu new-window -n Binance
# Split window horisontally
byobu split-window -h
# Select pane 0
byobu select-pane -t 0
# Starting Python script
byobu send-keys "cd /home/*replace_by_your_home_dir*/Binance-Spot" Enter
byobu send-keys "source /home/*replace_by_your_home_dir*/Binance-Spot/venv/bin/activate" Enter
byobu send-keys "python binance_spot.py" Enter
# Select pane 1
byobu select-pane -t 1
# Starting Python script
byobu send-keys "cd /home/*replace_by_your_home_dir*/Binance-Fut" Enter
byobu send-keys "source /home/*replace_by_your_home_dir*/Binance-Fut/venv/bin/activate" Enter
byobu send-keys "python binance_fut.py" Enter

byobu detach

Then edited /home/replace_by_your_home_dir/.profile - sudo nano /home/replace_by_your_home_dir/.profile and added lines in the end of the file:

# Check if the setup script has already been executed
if [ ! -f "$HOME/.byobu/setup_executed" ]; then
    # Run the setup script
    /bin/bash /home/*replace_by_your_home_dir*/.byobu/setup_on_boot.sh
    # Mark the setup script as executed
    touch "$HOME/.byobu/setup_executed"
fi
# Launch the Byobu session with the crypto-work session name
_byobu_sourced=1 . /usr/bin/byobu-launch attach -t crypto-work 2>/dev/null || true

As a result, when I connect via SSH I got a ready layout with all needed windows, panes + python venv activated + py scripts already running. Don't forget to: chmod +x setup_on_boot.sh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .