[Updated]
The question is related to the questions GNU Screen: Programmers quotes in Readbuf and GNU Screen: files to numbered buffers?. Since they are not solved, the question targets more general concept about environment variables. My belief is that they are the key to make Screen more efficient.
1. How can I use Bash's variables in Screen like:
$ export path=`pwd`
$ ^a :readbuf `echo $path`/debugging_code.php
2. How can I reuse Screen's buffers like:
$ ^a :readreg a `echo $path`
$ ^a :readbuf $a/debugging_code.php
$ ^a ]
3. How can I use Screen's buffers like environment variables?
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
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.