+2  A: 

The following command does not create a new screen session, but it will create a screen internal variable. Running it on the command line allow you to use the shell expansion:

$ screen -X setenv a "$PWD/debugging_code.php"

Then use the new variable:

C-a :readbuf $a
Chen Levy
+1 for its coolness. A similar in Ubuntu 'screen -X export foo="foo world"' did not work for some reason.
Masi
Note that the setenv in this context is a screen command not a *shudder* csh command.
Chen Levy
Would you clarify how you use it. Dunno why it does not work on my Ubuntu.
Masi
Masi, reading your first comment, I suspect you figured that the "setenv" above is a csh construct, and you replaced it with the equivalent bash "export" constant. However "setenv" here is a GNU screen command. For more information grep "-X" in `screen --help; also grep "setenv" in man screen.
Chen Levy
This is the best possible solution IMHO, since tapping into the current window's shell for environmental variables seems insecure, difficult (how many hops of ssh have you gone through?), and not necessarily optimal (maybe I don't want my screen's environment variables to change every time I change windows). This leaves the shell's work to the shell, and lets screen do what it needs to do.
rampion
+1  A: 

I have made a patch to screen 4.0.3 that supports the following syntax:

^A :readbuf !shell-command

This allows you to exec any arbitrary shell command and pipe the output into the screen buffer. Note that this is implemented by executing a subshell using popen and copying the standard output to the current file specified in the bufferfile setting (and then reading that file), so be careful you don't overwrite something you don't intend to. Also, this patch is probably terribly insecure so please use it at your own risk.

An example might be:

^A :readbuf !cat $HOME/projects/foobar/file.txt

Any shell command is executed literally as typed.

See gnu-screen-readbuf-exec on Github for the Git repository containing the patch.

Greg Hewgill
+1 cool! Have to work on it :D
Masi