0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

シェルスクリプトでtmuxの開発環境を立ち上げる

Posted at

はじめに

突然ですが皆さん、開発環境を立ち上げるために毎日同じようなコマンドを打っていませんか?

クライアント、サーバーだけでもディレクトリ移動と起動コマンドを2回ずつ打たなければいけないし、ましてや最近流行りのマイクロサービスとかになってしまうと、5回, 6回とサーバーを起動しなければなりません。

そこで今回は、シェルスクリプト一発でtmuxの開発環境を立ち上げる方法をご紹介します。

tmuxを知らない方や、インストールしていない方は下の記事が参考になります。

環境

  • ubuntu22.04
  • tmux 3.2a

ディレクトリ構成

次のようなディレクトリ構成を想定しています。
今回作成するのはsetup.shです

homedir/
    ├── setup.sh
    ├── ...
    └── project-dir
        ├── app-client/ (react-app)
            ├── node_modules/
            ├── package.json
            ├── ...
            └── src/
        └── app-server/ (go server)
            └── main.go

スクリプトの作成

setup.sh
#!/bin/sh

cd /path/to/project-dir

# セッションの作成
tmux new-session -d -s session_name

# ウィンドウ名の変更
tmux rename-window server
tmux send-keys -t session_name:1 "cd app-server" Enter
tmux send-keys -t session_name:1 "go run main.go" Enter

# 新しいウィンドウの作成
tmux new-window -t session_name
tmux rename-window client
tmux send-keys -t session_name:2 "cd app-client" Enter
tmux send-keys -t session_name:2 "yarn start" Enter

# 最初のウィンドウを選択
tmux select-window -t session_name:1

# セッションをアタッチ
tmux attach-session -t session_name

実行

$ source setup.sh

Screenshot from 2023-05-28 20-05-38.png

Screenshot from 2023-05-28 20-06-07.png

これで、めんどくさいコマンドを毎日打たなくてもよくなりますね!

tmuxのカスタマイズは、こちらの記事を参考にしています。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?