LoginSignup
1
1

More than 3 years have passed since last update.

複数タブでコマンドを実行してくれるShell Scriptをかきたい

Last updated at Posted at 2021-02-18

はじめに

フロントエンドとバックエンドで分けて起動したい時、
1. terminalを起動して
2. タブを分割して
3. 各々で起動コマンドを実行する
という流れが面倒だったのでシェルスクリプトにしました。

実行すれば垂直分割されたiTermが起動して、それぞれでコマンドを実行してくれます。(↓の状態のiTermが起動します)
スクリーンショット 2021-02-18 11.41.20.png

実装

今回はiTerm2を使います。

こちらの記事を参考にApple Scriptで書きました。

.init.sh
#!/usr/bin/osascript
tell application "iTerm"
    create window with default profile
    tell current window
        # tabの分割
        tell current session of current tab
            split vertically with default profile
        end tell

        # tab1の処理
        tell current session of current tab
            write text "cd ~/[対象のpath]"
            write text "実行したいコマンド"
        end tell

        # tab2の処理
        tell second session of current tab
            write text "cd ~/[対象のpath]"
            write text "実行したいコマンド"
        end tell
    end tell
end tell
$ ./init.sh

を実行したら垂直分割されたiTermが起動されます。

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1