조용한 담장

TMUX 세션별로 환경 분리해서 사용하기 본문

tips

TMUX 세션별로 환경 분리해서 사용하기

iosroid 2024. 7. 17. 22:00

 

tmux를 여러 터미널에서 동시에 다른 환경으로 사용해야 할 상황들이 있다.

간단한 예제로 개발할 때는 zsh를, 빌드할 때는 오래된 툴체인 때문에 bash를 사용해야 상황이다. (실제로)

한쪽 터미널에서는 build 를 하면서 다른 쪽 터미널에서는 develop을 계속하는 환경이 필요하다.

build 중에 종종 튕기는 악조건 이기에 어떻게든 tmux에 매달려야 한다...... (현실)

 

tmux.conf 파일에서 아래와 같이 수정하면 default-shell 은 간단히 수정된다.

set-option -g default-shell /bin/zsh

 

가끔 bash 환경을 써야 할때는 conf 파일을 따로 만들어서 사용하면 된다.

tmux -f ~/.tmux_bash.conf

 

zsh 환경을 가끔 쓴다면 반대로 적용하면 되겠다.

 

문제는 각각의 conf 옵션을 동시에 사용하려면 둘의 환경을 분리해줘야 한다.

이는 소켓의 이름을 다르게 설정하여 서버를 분리해 주는 방법으로 해결한다.

 

기본 소켓의 이름은 default 이다.

$ ls /tmp/tmux-1000/
default

 

여기서 conf 파일을 다르게 적용해도 option 들은 분리가 되지 않는다.

-L 옵션을 통해서 각각의 소켓을 만든다.

-L socket-name
tmux stores the server socket in a directory under TMUX_TMPDIR or /tmp if it is unset. The default socket is named default. This option allows a different socket name to be specified, allowing several independent tmux servers to be run. Unlike -S a full path is not necessary: the sockets are all created in a directory tmux-UID under the directory given by TMUX_TMPDIR or in /tmp. The tmux-UID directory is created by tmux and must not be world readable, writable or executable.

 

tmux -L devel
tmux -L build -f ~/.tmux_bash.conf

 

다른 이름으로 생성된 소켓을 통해 conf 환경이 분리되었다.

간단하네...

 

build와 devel 소켓이 생성되었다.

$ ls /tmp/tmux-1000/
build default  devel

 

$ tmux -L devel list-sessions
0: 1 windows (created Wed Jul 17 11:21:23 2024) (attached)
$ tmux -L build list-sessions
0: 2 windows (created Wed Jul 17 11:22:00 2024) (attached)

 

alias로 편하게

alias tmux-dev='tmux -L devel'
alias tmux-build='tmux -L build'

 

 

Comments