user2743
user2743

Reputation: 1513

Using a bash script to launch screen, then split and resize a screen

I'm trying to build a bash script to launch a screen session, split the screen and then resize one of the screens. Below is what I run manually from the terminal.

$screen
$ cd /some/directory

Controla then ShiftS //splits the screen in two

Controlatab //navigate to the "new" screen

Controlc //create another terminal

Controla :resize -15 //resize the screen

$cd /another/dictionary

Controlatab //navigate to the first screen

$clear

I've done some bash scripting but nothing with keystrokes. I've been trying to find something to send controla within a bash script but I'm not sure if I can or if after I launch screen if I can interact with screen that way. I haven't been able to find anything in my googling yet. Any help or direction is greatly appreciated.

Upvotes: 3

Views: 1874

Answers (2)

Liviu
Liviu

Reputation: 148

I know this is old but I needed this, too, and could not find an answer. I finally solved it out like this:

  • make a configuration file, say .splitscreenrc:

    chdir /etc
    screen 0
    stuff "ls -1\n"
    split
    focus down
    resize 3
    chdir /tmp
    screen 1
    stuff "ls\n"
    focus up
    
  • run screen -c .splitscreenrc

Hope this helps someone ;)

Upvotes: 4

glenn jackman
glenn jackman

Reputation: 246847

Using expect:

#!/usr/bin/expect -f
set prompt {\$ }   ;# this is a regular expression to match your shell prompt
set dir1 /tmp
set dir2 /var/log

spawn screen
expect -re $prompt
send -- "\001S"
expect -re $prompt
send -- "cd $dir1\r"
expect -re $prompt
send -- "\001\t"
send -- "\001c"
expect -re $prompt
send -- "\001:resize -15\r"
send -- "cd $dir2\r"
expect -re $prompt
send -- "\001\t"
send -- "clear\r"

interact

Upvotes: 0

Related Questions