On Fri, 24 Jun 2011, Michael Parson wrote:
-- begin chscdir --
#!/bin/sh
screen -X msgwait 0
screen -X at "$1" stuff ""
screen -X at "$1" stuff "pwd > $TMPDIR/buffer ^M"
screen -X readbuf
screen -X stuff "cd "
screen -X paste .
screen -X removebuf
screen -X msgwait 4
-- end chscdir --
<snip>
If only Screen had a "tty" command, it would be possible to know the
current working directory of any process the user owns ( provided there
is an accessible /proc filesystem ). But I guess hell freezes over
before the feature freeze ends.
-- begin screen_get_dir --
#!/bin/sh
WIN=$1
TTY=`screen -p $WIN -Q @tty | cut -c6-`
PID=`pgrep -t $TTY | tail -1`
echo `readlink -f /proc/$PID/cwd`
-- end screen_get_dir --
This applies cleanly against HEAD and adds ":tty" command which prints
the filename of the current terminal:
diff --git a/src/comm.c b/src/comm.c
index 5f4af8a..7a9cd18 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -313,6 +313,7 @@ struct comm comms[RC_LAST + 1] =
{ "terminfo", ARGS_23 },
{ "time", CAN_QUERY|ARGS_01 },
{ "title", CAN_QUERY|NEED_FORE|ARGS_01 },
+ { "tty", CAN_QUERY|ARGS_0 },
{ "umask", ARGS_1|ARGS_ORMORE },
{ "unbindall", ARGS_0 },
{ "unsetenv", ARGS_1 },
diff --git a/src/process.c b/src/process.c
index dfa7c82..ada5383 100644
--- a/src/process.c
+++ b/src/process.c
@@ -2662,6 +2662,19 @@ int key;
MakeTermcap((display == 0));
debug("new termcap made\n");
break;
+ case RC_TTY:
+ if(fore)
+ {
+ if (fore->w_type == W_TYPE_TELNET)
+ OutputMsg(0, "telnet");
+ else if (fore->w_type == W_TYPE_GROUP)
+ OutputMsg(0, "group");
+ else
+ OutputMsg(0, "%s", fore->w_tty);
+ }
+ else
+ OutputMsg(0, "none");
+ break;
case RC_ECHO:
if (!msgok && (!rc_name || strcmp(rc_name, "-X")))
break;
_______________________________________________
screen-users mailing list
screen-users@gnu.org
https://lists.gnu.org/mailman/listinfo/screen-users