Program Tip

tmux를 사용하는 Bash 스크립트를 사용하여 4 개의 창으로 구성된 창 실행

programtip 2020. 11. 28. 10:19
반응형

tmux를 사용하는 Bash 스크립트를 사용하여 4 개의 창으로 구성된 창 실행


누구의 도움으로 무슨 일이 일어나고 있는지 설명 할 수 tmux, bash그리고 exec? 4 개의 창으로 tmux 세션을 설정하려고합니다. 이상적으로는 3 개의 창 (예 : Ruby Thin 서버 및 몇 개의 Ruby 데몬)에서 명령을 실행하고 싶습니다. 이것이 내가 지금까지 가지고있는 것입니다.

~/.bin/tmux-foo:

#!/bin/sh

tmux new-session -d -s foo 'exec pfoo "bundle exec thin start"'
tmux rename-window 'Foo'
tmux select-window -t foo:0
tmux split-window -h 'exec pfoo "bundle exec compass watch"'
tmux split-window -v -t 0 'exec pfoo "rake ts:start"'
tmux split-window -v -t 1 'exec pfoo'
tmux -2 attach-session -t foo

~/.bin/pfoo:

#!/bin/bash
cd ~/projects/foo
rvm use ree

# here I want to execute command1 2 3 or 4...

exec $SHELL

모두 작동하지만 ctlr-c씬 서버를 실행하는 첫 번째 창에서 씬 서버를 중지하고 셸로 돌아갑니다. 그러나 명령은 기록에 없습니다. 즉, up 키를 눌렀을 때 bundle exec thin start명령을 얻지 못합니다 . bash 기록에서 다른 명령을 얻습니다. bash 기록에서 명령을 얻을 수 있도록 이러한 스크립트를 정렬하는 방법이 있는지 궁금합니다.

또한 ... 나는 많은 조합을 시도했습니다 exec, exec $SHELL -s ...그리고 exec $SHELL -s ... -I나는 확신에 무슨 일이 아니에요 ...

누구든지 도움이 일반에 무슨 일이 일어나고 있는지의 아이디어를 설명 할 수 tmuxbashexec여기를?


다른 사람들이 언급했듯이 명령 은를 시작하기 전에 쉘 스크립트에 의해 실행됩니다 $SHELL. 의 인스턴스가 $SHELL시작하기 전에 부모가 무엇을 실행했는지 알 수 있는 일반적인 방법은 없습니다 .

쉘 히스토리에 "초기 명령"을 가져 오려면 명령 키 입력을 $SHELL자신 의 인스턴스에 직접 입력해야 합니다 (물론 시작된 후). 다른 컨텍스트에서는 작은 Expect 프로그램을 사용하여의 인스턴스를 생성 $SHELL하고 키 입력을 제공 한 다음 interacttty를 expect -spawned 에 연결하는 데 사용하는 것이 좋습니다 $SHELL.

그러나 tmux 컨텍스트 에서는 send-keys다음을 사용할 수 있습니다 .

#!/bin/sh

tmux new-session -d -s foo 'exec pfoo'
tmux send-keys 'bundle exec thin start' 'C-m'
tmux rename-window 'Foo'
tmux select-window -t foo:0
tmux split-window -h 'exec pfoo'
tmux send-keys 'bundle exec compass watch' 'C-m'
tmux split-window -v -t 0 'exec pfoo'
tmux send-keys 'rake ts:start' 'C-m'
tmux split-window -v -t 1 'exec pfoo'
tmux -2 attach-session -t foo

tmuxinator를 사용하면 멋진 yaml 파일로이를 지정할 수 있습니다. 귀하의 경우 다음을 가질 수 있습니다.

# ~/.tmuxinator/foo.yml
# you can make as many tabs as you wish...

project_name: foo
project_root: ~/projects/foo
rvm: ree
tabs:
  - main:
      layout: tiled
      panes:
        - bundle exec thin start
        - bundle exec compass watch
        - #empty, will just run plain bash
        - rake ts:start

물론 추가 창 등을 가질 수 있습니다.


You are running the command and then entering the interactive shell; the command run from the script, not being in an interactive shell, doesn't get recorded in the history. You really want a way to stuff (that's a technical term :) once upon a time it was TIOCSTI for "terminal ioctl(): stuff input") input for the shell into the window.

With tmux, it looks like you use buffers for this. Something along the lines of (untested)

#! /bin/bash
cd ~/projects/foo
rvm use ree

if [[ $# != 0 ]]; then
  tmux set-buffer "$(printf '%s\n' "$*")" \; paste-buffer -d
fi

exec ${SHELL:-/bin/sh}

참고URL : https://stackoverflow.com/questions/5447278/bash-scripts-with-tmux-to-launch-a-4-paned-window

반응형