How to write a shell script that starts tmux session, and then runs a ruby script

后端 未结 6 657
暗喜
暗喜 2020-12-08 03:53

I want to write a shell script that does this:

  • First, create a tmux session
  • Second, run a ruby script called \"run.rb\" INSIDE the tmux session
  • <
6条回答
  •  囚心锁ツ
    2020-12-08 04:30

    With some experimenting, I figured out how to control tmux via shell script.

    tmux new-session -d -s htop-session 'htop';  # start new detached tmux session, run htop
    tmux split-window;                             # split the detached tmux session
    tmux send 'htop -t' ENTER;                     # send 2nd command 'htop -t' to 2nd pane. I believe there's a `--target` option to target specific pane.
    tmux a;                                        # open (attach) tmux session.
    

    The above splits the tmux session into two window, and runs htop in both.

    To answer original question, you can run a ruby script and not detached the tmux session with command below:

    tmux new-session -s ruby_session 'ruby run.rb';  # open tmux session and run ruby script.
    

提交回复
热议问题