Subject: Spawning commands inside interactive shells in new windows in a scriptable fashion

From: László Monda <[email-masked]>
Date: Wed, 16 Jul 2008 13:50:06 +0200

Hi List,

I've already sent this mail to the list some days ago, but seeing the
archives it seems to me that it hasn't arrived, so I resend it this
time.

I want to open new windows that run specific commands within interactive
shells in a scriptable fashion.

Let's say I want to run `du --max-depth=1 /` in a new screen window
within an interactive shell and I want to do it from a script.

Let's consider the following:

$ screen screen bash -i -c du --max-depth=1 /

I'd expect this to work, but it doesn't.

On the other hand it works:

$ screen screen bash -i -c read

But bash closes right after pressing enter.  I guess bash has trouble
handling -i and -c together and it behaves non-interactively in this
case.

Also, the status line showing the windows doesn't get updated, only
after I explicitly change window.

I'd really appreciate your insights.

Thanks in advance!
-- 
Laci  <http://monda.hu>

_______________________________________________
screen-users mailing list
[email-masked]
http://lists.gnu.org/mailman/listinfo/screen-users

---

From: Mark Eichin <[email-masked]>
Date: Thu, 17 Jul 2008 12:40:14 -0400

looks like you might want to use "stuff" to push the commands at a
normal screen that has a shell open (so that it runs them, and stays
interactive.)

---

From: László Monda <[email-masked]>
Date: Tue, 22 Jul 2008 02:20:35 +0200

> normal screen that has a shell open (so that it runs them, and stays

I don't think that "stuff" is capable of what I want to do.  I basically
want to write a script, like:

new-screen-window ls
new-screen-window du /
new-screen-window my-script

Where the new-screen-window utility opens new screen windows without
jumping to them.  I'd also like to specify the title of the individual
windows.

-- 
Laci  <http://monda.hu>

---

From: Gokdeniz Karadag <[email-masked]>
Date: Tue, 22 Jul 2008 14:33:44 +0300

You can use this in your screenrc, opens 4 windows, sets titles, first one is 
interactive and selected.

screen -t shell
screen -t ls
stuff "ls\015"
screen -t du
stuff "du /\015"
screen -t script
stuff "my-script\015"
select 0

László Monda demis ki::
> ------------------------------------------------------------------------
>

---

From: László Monda <[email-masked]>
Date: Wed, 23 Jul 2008 23:36:29 +0200

Hi David,

(David has allowed me to reply to his email publicly.)

I think this is almost exactly what I need, but "^M" gets literally
quoted for me, just like as "\^M" or "\015".

How can I put new line characters in there?

Thanks!

On Tue, 2008-07-22 at 09:10 +0100, [email-masked] wrote:
> I don't know if this will help you but I have a small script that will
> start up folding at home in a running screen session. Here is the
> basis of it
> 
> $ cat screen.scpt
> screen -S desktop4 -X screen -t t1
> screen -S desktop4 -p t1 -X stuff 'cd /^M'
> screen -S desktop4 -p t1 -X stuff 'ls ^M'
> screen -S desktop4 -X screen -t t2
> screen -S desktop4 -p t2 -X stuff 'cd programming^M'
> screen -S desktop4 -p t2 -X stuff 'file *^M'
> 
> It will open a new screen called 't1', select it, cd to / and ls it,
> then another called 't2' move into my programming folder and do a
> 'file' on the content.
> 
> It seems like this might be the basis for what you need?
> 
> On 22/07/2008, László Monda <[email-masked]> wrote:
-- 
Laci  <http://monda.hu>

---

From: Gokdeniz Karadag <[email-masked]>
Date: Thu, 24 Jul 2008 00:44:09 +0300

In a console based text editor( I use vim) you can press on following three keys;
ctrl v enter

This will embed a literal newline into the file, tested with the given script. 
I'm not sure about embedding newlines with GUI editors.

By the way, David's suggestion was very helpful, I realized I did not know 
about -p

:)

---

From: László Monda <[email-masked]>
Date: Thu, 24 Jul 2008 01:12:04 +0200

Seems like I'm just ready with new-screen-window which I've just
attached.

From now on we can easily do things, like:
new-screen-window new-window-title 'du -h /'

Thanks for David for kicking ass with his way of doing this and for
Gokdeniz for explaining me the newline issue.

Possible improvements that are encouraged by me, since I suck at bash:

* Make specifying the window title optional by using a -t option.
* Jump back to the original window where new-screen-window ran.
* Provide a -j option for jumping to the new window.
* Interpret the rest of the command line as $command without quoting.

-- 
Laci  <http://monda.hu>