2

When running Screen, I can use Ctrl+ac to create a new window and run vim in each window. Also from Screen, I can run the command screen vim multiple times to open new windows with vim already running. These work as expected. However...

If I put the command multiple times in a script, such as:

#!/bin/bash
screen vim
screen vim
screen vim

...and run that script from within Screen, the first command will run as expected, but the second and following ones will not.

Things I have noticed are:

  1. Window 2 and beyond does not have stty -ixon applied, which I have set in .bashrc
  2. If I don't have colorscheme set explicitly in .vimrc, it will use one scheme in window 1 and another in all following windows
  3. Sometimes a command will be skipped, i.e., sometimes only two new windows will be opened where the script was set to open three
  4. If I do a :windowlist, window 2 and following will not have the login flag set (running screen vim directly will set this flag), e.g.,
Num Name Flags
  0 bash     $
  1 vim      $  <-- running the script from window 0 opened 1..3 (no flag on 2 or 3)
  2 vim
  3 vim
  4 vim      $  <-- manually running `screen vim` from window 0 always sets the flag
  1. Using Ctrl+aL on a window that's not logged in will return the message This window is not logged in and the flag will not be set. Pressing the keys again will then toggle between logged in and out (though stty -ixon etc' will still not be applied)
  2. Running htop will show all instances of vim (including ones that are not logged in) are running under my user.

Why does manually opening multiple windows apply my settings correctly, but using a script doesn't?

I am new to Linux and not sure if I'm doing something silly here.

1 Answer 1

1

I believe I found that the problem is caused by the script running all commands (except the first) in the background. I can force the first command to have the same problem by forking it with &.

After not being able to find a way to have the script run each command in the foreground, one-after-the-other, I have found an alternative solution...

I can put all the commands in a custom screenrc file (e.g., my_screenrc) as such:

# Import default screenrc
source ${HOME}/.screenrc

# Run screen-specific commands (not bash ones)
screen     # Run bash in window 0
screen vim # Run vim in windows 1 through 3 (with correct settings)
screen vim
screen vim

I can then run this from bash with:

screen -c my_screenrc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .