tmux 세션 내에서 새 tmux 세션 만들기
tmux 내부에 있고 세션이 존재하는지 여부에 따라 주어진 세션을 생성 / 연결하거나 전환하는 셸 스크립트를 작성하고 있습니다.
tmux 세션 내에서 새 tmux 세션을 만들어야하는 경우를 제외하고는 모든 것이 잘 작동합니다.
내 스크립트가 실행되면 tmux new-session -s name
다음 출력이 표시됩니다.
세션은 신중하게 중첩되어야합니다. $ TMUX를 설정 해제하여
실제로 세션을 중첩하고 싶지는 않습니다. 제 목표는 다른 별도의 세션 을 만들고 tmux 세션 내에서 세션으로 전환하는 것입니다 .
이게 가능해?
가장 빠른 방법 ( ctrl-b
명령 접두사로 사용한다고 가정 )은 다음과 같습니다.
ctrl-b :new
새 세션을 생성하려면
ctrl-b s
대화식으로 선택하고 세션에 연결합니다.
스크립트를 만드는 방법
이 스크립트는 세션이 있는지 확인합니다. 세션이 존재하지 않는 경우 새 세션을 생성하고 연결합니다. 세션이 존재하지 않으면 아무 일도 일어나지 않고 해당 세션에 연결됩니다. `~ / development '를 프로젝트 이름으로 자유롭게 바꾸십시오.
$ touch ~/development && chmod +x ~/development
# ~/development
tmux has-session -t development
if [ $? != 0 ]
then
tmux new-session -s development
fi
tmux attach -t development
터미널의 새 세션
두 개의 분리 된 세션을 만들고 나열하고 하나에 연결 한 다음 tmux 내에서 세션을 순환합니다.
tmux new -s name -d
새로운 분리 된 세션을 생성하기 때문에 tmux 내부에서 작동합니다. 그렇지 않으면 중첩 오류가 발생합니다.
$ tmux new -s development -d
$ tmux new -s foo -d
$ tmux ls
> development: 1 windows (created Wed Jan 13 11:31:38 2016) [204x54]
> foo: 1 windows (created Wed Jan 13 11:31:38 2016) [204x54]
$ tmux attach -t
$ tmux ls
> development: 1 windows (created Wed Jan 13 11:31:38 2016) [204x54] (attached)
> foo: 1 windows (created Wed Jan 13 11:31:38 2016) [204x54]
tmux 내에서 새 세션
우리는 이제 대상 세션에 연결 되어 있거나 더 잘 알려져 있습니다. 연결된 동안 새 세션을 만들려고하면 중첩 오류가 발생합니다.
$ tmux new -s bar
> sessions should be nested with care, unset $TMUX to force
이를 해결하기 위해 새로운 분리 세션을 생성합니다. 예 :
$ tmux new -s bar -d
$ tmux ls
> development: 1 windows (created Wed Jan 13 11:31:38 2016) [204x54] (attached)
> foo: 1 windows (created Wed Jan 13 11:31:38 2016) [204x54]
> bar: 1 windows (created Wed Jan 13 17:19:35 2016) [204x54]
주기 (전환) 세션
Prefix
(
이전 세션Prefix
)
다음 세션
note: Prefix
is Ctrl-b
by default. You can bind Prefix
to Ctrl-a
and in Mac OSX you can change Caps Lock to ctrl system preferences > keyboard > modifier keys
Attach to a session using command mode while inside tmux
Trying to attach to a session without detaching will result in an error.
$ tmux attach -t development
> sessions should be nested with care, unset $TMUX to force
Instead use command mode Prefix
:
then type attach -t session_name
and hit enter.
Using this works for me:
TMUX= tmux new-session -d -s name
tmux switch-client -t name
The TMUX=
on the first line is required so tmux doesn't throw a sessions should be nested with care, unset $TMUX to force
message.
All the commands you can launch within your terminal, like tmux new -s sessionName
can be launched from within tmux
by pressing the trigger key (eg: ctrl-b
) then :
then the command without the starting tmux
part.
As a result, ctrl-b :
followed by new -s sessionName
will do exactly what you want and give a name to your session. It also switches automatically to the new session.
You can try unset TMUX
first, this works for me.
at user2354696's advice I use following key bindings to create a new session or "clone" an existing session
bind-key N run-shell 'TMUX= tmux new-session -d \; switch-client -n' bind-key C run-shell 'TMUX= tmux new-session -t $(tmux display-message -p #S) -s $(tmux display-message -p #S-clone) -d \; switch-client -n \; display-message "session #S cloned"'
참고URL : https://stackoverflow.com/questions/16398850/create-new-tmux-session-from-inside-a-tmux-session
'development' 카테고리의 다른 글
NSURLRequest가 데이터 캐싱을 방지하거나 요청 후 캐시 된 데이터를 제거 할 수 있습니까? (0) | 2020.09.11 |
---|---|
Intellij 제품에서 콘솔 출력 색상 화 (0) | 2020.09.11 |
Windows가 subprocess.call ()에서 파일을 찾을 수 없습니다. (0) | 2020.09.11 |
사전을 Python에서 쿼리 문자열로 변환하는 방법은 무엇입니까? (0) | 2020.09.11 |
Git 태그 목록, 커밋 sha1 해시 표시 (0) | 2020.09.11 |