On Thu, Aug 18, 2011 at 10:36 AM, Kevin Van Workum <
vanw+scr...@sabalcore.com> wrote:

> Hi,
>
> I would like to query the values of environment variable that are set in
> the shells of other window in my screen session. For example, I would like
> to know the value of $HOSTNAME in window 0 while in window 1.
>
> Really, all I want is HOSTNAME, USER, and PWD which are all displayed on my
> hardstatus line. So if I could just get the hardstatus line for each window,
> that would be fine. The idea would be to create a screen-aware scp command
> to copy files from one location to another.
>
> Kevin
>
>
I came up with a reasonably useful solution if you're interested. This
solution allows you to 'stuff' the title of a window into the current
window. If you set your window titles to "$USER@$HOSTNAME:$PWD", then you
can use this 'stuff' technique to scp files from one window to another.
Here's how it works.

First, you need to setup your bash PROMPT_COMMAND to automatically set the
window title. You can do this by adding the following to your bashrc. You
need to add it to all the bashrc files on all your hosts that you use.

if [ "$TERM" == "screen" ]; then
  PROMPT_COMMAND='echo -ne "\033k${USER}@
${HOSTNAME}:${PWD/#$HOME/'~'}\033\\"'
fi

Or anything you want to be in your window title.

Next, you need to create some custom key binds like this in your screenrc:

# This is my title_stuff command
bind -c title_stuff 0 exec .!. screen -p 0 -Q title
bind -c title_stuff 1 exec .!. screen -p 1 -Q title
bind -c title_stuff 2 exec .!. screen -p 2 -Q title
bind -c title_stuff 3 exec .!. screen -p 3 -Q title
bind -c title_stuff 4 exec .!. screen -p 4 -Q title
bind -c title_stuff 5 exec .!. screen -p 5 -Q title
bind -c title_stuff 6 exec .!. screen -p 6 -Q title
bind -c title_stuff 7 exec .!. screen -p 7 -Q title
bind -c title_stuff 8 exec .!. screen -p 8 -Q title
bind -c title_stuff 9 exec .!. screen -p 9 -Q title
bind "C" command -c title_stuff

With these bindings, then doing a 'C-a C n' key sequence would stuff the
title of window 'n' into the current window at the cursor location. Which
can be very handy for scp, cp, ssh, etc.

Hope you find it as useful as I do.

Kevin
_______________________________________________
screen-users mailing list
screen-users@gnu.org
https://lists.gnu.org/mailman/listinfo/screen-users

Reply via email to