0

I would like to start a tmux session on a separate window in iTerm2. Now I'm writing my own configuration script to launch the session.

tmux new-session -s dev -n main -d
tmux send-keys -t dev "cd $DL" C-m
tmux split-window -h -t dev
tmux split-window -v -t dev -p 30
tmux resize-pane -x 70 -y 20
tmux attach -t dev

This starts a new session but the window is on the window I execute the script, not the new, separate window in iTerm2.

So I changed the first line (tmux new-session -s dev -n main -d) to tmux -CC new -t dev, but then although the session starts in a new window, it does not have the split and the resize. It seems to only open the new session in a new window and that's all.

How can I make it launched in a new window with all the initial settings including the directory change, split window, etc...?

2 Answers 2

0

You can use applescript to do something like this:

$ cat a.bash
#!/bin/bash
osascript - "$@" <<EOF
on run argv
tell application "iTerm"
    activate
    set new_term to (create window with default profile)
    tell new_term
        tell the current session
            repeat with arg in argv
               write text arg
            end repeat
        end tell
    end tell
end tell
end run
EOF

This provides a script which can then pass arguments passed into it, into another iterm2 terminal.

For example:

$ ./a.bash "echo 'hello iterm2'"

   ss of iterm2 launch

References

2
  • Thanks but how can I take the script to the argument of the a.bash? ./a.bash < my_script does not work (it only launches the window). It works if it is ./a.bash "tmux new -s dev", though.
    – Blaszard
    Commented Jul 5, 2018 at 11:26
  • @Blaszard - can you please update your question, it's not clear what exactly you want/expect to happen here then.If the last part works I'd saw your problem's solved, which I know isn't the case in your mind, but we need more to go on then.
    – slm
    Commented Jul 5, 2018 at 13:55
0

You are almost there. Your command for control mode is mostly correct, but you should replace the last line with it, not the first line. Use this as your last line:

tmux -CC attach -t dev

By the way, your first two lines can be combined into one:

tmux new-session -s dev -n main -d "cd $DL; $SHELL"
1
  • Note that you might want to quote $DL, depending on what you know about its value. Commented Jan 8, 2022 at 2:52

You must log in to answer this question.

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