5

.screenrc:

shell -${SHELL}
caption always "%n(%t) %= %{b}@%H[%l] : %{r}%c:%s"
termcapinfo xterm ti@:te@
termcap  xterm 'AF=\E[3%dm:AB=\E[4%dm'
terminfo xterm 'AF=\E[3%p1%dm:AB=\E[4%p1%dm'
startup_message off

screen -t server 0 rails s
screen -t spork 1 bundle exec spork
screen -t dev_log tail -f ./log/test.log

Pressing Ctrl+C in any of the screen windows above destroys it. I would like to have subshell for every so if I press Ctrl+C than I just exit to that subshell.

Right now I'm running screen and creating all windows above manually, renaming them and it works great. I can terminate any program on any window, do something else and run it again. What I want to achieve is to have that set-up to run with just one command.

pawel7318
  • 2,000
  • 3
  • 16
  • 15

2 Answers2

3

I decided to create another related question How to keep Bash running after command execution? to just forget about big picture and focus on the main problem. Worked as intended and finally there were presented 3 ways to achieve the goal:

  1. workaround which was not bad
  2. portable (POSIX)
  3. simple

and I choose to use 3rd one that way:

~/.run_screen:

#!/bin/bash
/bin/bash -i <<<"$*; exec </dev/tty"

~/.screenrc:

screen -t server 1 ${HOME}/.run_screen rails s
screen -t spork 2 ${HOME}/.run_screen bundle exec spork
screen -t dev_log 3 ${HOME}/.run_screen tail -f ./log/development.log
screen -t test_log 4 ${HOME}/.run_screen tail -f ./log/test.log
screen -t bash 0  
pawel7318
  • 2,000
  • 3
  • 16
  • 15
2

How about instead of a subshell, just open a new one when your app finishes?

screen -t htop bash -i -c "htop && bash"