[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to include PWD into hardstatus line?

From: Phil!Gregory
Subject: Re: How to include PWD into hardstatus line?
Date: Sat, 12 Feb 2005 17:52:55 -0500
User-agent: Mutt/1.5.6+20040907i

* Rusty Shackleford <address@hidden> [2005-02-11 16:03 +0000]:
> I tried adding $PWD to my hardstatus, but that seemed to store the
> initial directory and not update as I moved around.  I couldn't find a %
> symbol for the current directory.

There's not really a good way to do what you want, though I'll provide
something of a hack in a bit.

The problem with $PWD is that it's an enivronment variable.  screen will
inherit $PWD from the process that ran it (presumably your shell), but it
will not change $PWD, so you will always get the same value from it.

The problem with some % escape is that you're probably not changing
screen's working directory.  If you start screen, screen starts a shell by
default.  When you change directories by 'cd', the shell is changing its
working directory, but the screen process's working directory remains the
same.  (You can change screen's working directory via the 'chdir' sceen
command, but I assume that's not what you're using.)

You can hack this into screen by using the new backtick escapes.  Put
something like this in your .screenrc:

  backtick 1 15 15 cat %{HOME}/.pwd
  hardstatus "%H:%1`"

Then modify your shell to write to ~/.pwd every time you change
directories.  The best approach would be if you use a shell that can run
user-defined stuff right after changing directories (like zsh's chpwd),
but I'll assume you're running bash, which only has $PROMPT_COMMAND.  In
your .bashrc (or .profile; I can never keep the two straight) put
something like:

  PROMPT_COMMAND='echo $PWD > ~/.pwd'

Those will combine to put "<hostname>:<pwd>" in your hardstatus.  The
caveat is that it only really works if you only have one window in your
screen session.  If you've got multiple windows (or even multiple shells
from, say, several xterms), they'll keep overwriting each other's pwds.
(Though you could change the PROMPT_COMMAND to '[ "$TERM" = "screen" ] &&
echo $PWD > ~/.pwd' to filter out all shells not running in screen.)

> Also, sometimes I start a screen on host XXX, then rsh to another host
> YYY, but the screen hardstatus still displays hostname XXX and cpu load
> average info for XXX.

Yes.  Screen displays the name, load, and other characteristics of the
computer it's running on.  Even if you rsh to a different host, that
screen session is still running on the original host; it just has an rsh
session in it.

> Is it possible to update that to YYY's hostname and load average?

Probably, with some careful work and judicious use of backtick commands.
Actual implementation is left as an exercise for the reader.  }:>

-- contrarian of the first order... /
PGP: 026A27F2  print: D200 5BDB FC4B B24A 9248  9F7A 4322 2D22 026A 27F2
--- --
You are standing in an open field west of a white house, with a boarded
front door.
There is a small mailbox here.
---- --- --

reply via email to

[Prev in Thread] Current Thread [Next in Thread]